feat: expose module for zig build system

This commit is contained in:
Rekai Nyangadzayi Musuka 2023-06-25 16:44:21 -05:00
parent 3f5c9b5bc4
commit b9d1972c17
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.
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.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 util_dep = b.dependency("zba-util", .{});
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
lib.addModule("bitfield", bitfield_mod);
// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
b.installArtifact(lib);
_ = b.addModule("arm32", .{
.source_file = .{ .path = "src/lib.zig" },
.dependencies = &.{
.{
.name = "zba-util",
.module = util_dep.module("zba-util"),
},
.{
.name = "bitfield",
.module = bitfield_mod,
},
},
});
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const main_tests = b.addTest(.{
const lib_tests = b.addTest(.{
.root_source_file = .{ .path = "src/lib.zig" },
.target = target,
.optimize = optimize,
});
main_tests.addModule("zba-util", zba_util_mod); // https://git.musuka.dev/paoda/zba-util
main_tests.addModule("bitfield", bitfield_mod);
lib_tests.addModule("zba-util", util_dep.module("zba-util")); // https://git.musuka.dev/paoda/zba-util
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,
// and can be selected like this: `zig build test`
// This will evaluate the `test` step rather than the default, which is "install".
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step);
test_step.dependOn(&run_lib_tests.step);
}