feat: expose module for zig build system

This commit is contained in:
Rekai Nyangadzayi Musuka 2023-06-25 16:44:21 -05:00
parent 78cdb10395
commit 9643b520c8
1 changed files with 19 additions and 22 deletions

View File

@ -15,42 +15,39 @@ pub fn build(b: *std.Build) void {
// set a preferred release mode, allowing the user to decide how to optimize. // set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{ const util_dep = b.dependency("zba-util", .{});
.name = "arm32",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .path = "src/lib.zig" },
.target = target,
.optimize = optimize,
});
const zba_util_mod = b.dependency("zba-util", .{}).module("zba-util");
const bitfield_mod = b.createModule(.{ .source_file = .{ .path = "lib/bitfield.zig" }, .dependencies = &.{} }); const bitfield_mod = b.createModule(.{ .source_file = .{ .path = "lib/bitfield.zig" }, .dependencies = &.{} });
lib.addModule("zba-util", zba_util_mod); // https://git.musuka.dev/paoda/zba-util _ = b.addModule("arm32", .{
lib.addModule("bitfield", bitfield_mod); .source_file = .{ .path = "src/lib.zig" },
.dependencies = &.{
// This declares intent for the library to be installed into the standard .{
// location when the user invokes the "install" step (the default step when .name = "zba-util",
// running `zig build`). .module = util_dep.module("zba-util"),
b.installArtifact(lib); },
.{
.name = "bitfield",
.module = bitfield_mod,
},
},
});
// Creates a step for unit testing. This only builds the test executable // Creates a step for unit testing. This only builds the test executable
// but does not run it. // but does not run it.
const main_tests = b.addTest(.{ const lib_tests = b.addTest(.{
.root_source_file = .{ .path = "src/lib.zig" }, .root_source_file = .{ .path = "src/lib.zig" },
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
main_tests.addModule("zba-util", zba_util_mod); // https://git.musuka.dev/paoda/zba-util lib_tests.addModule("zba-util", util_dep.module("zba-util")); // https://git.musuka.dev/paoda/zba-util
main_tests.addModule("bitfield", bitfield_mod); lib_tests.addModule("bitfield", bitfield_mod);
const run_main_tests = b.addRunArtifact(main_tests); const run_lib_tests = b.addRunArtifact(lib_tests);
// This creates a build step. It will be visible in the `zig build --help` menu, // This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build test` // and can be selected like this: `zig build test`
// This will evaluate the `test` step rather than the default, which is "install". // This will evaluate the `test` step rather than the default, which is "install".
const test_step = b.step("test", "Run library tests"); const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step); test_step.dependOn(&run_lib_tests.step);
} }