Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Separate lib into its own build step
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn committed Mar 1, 2024
1 parent ec6f5ba commit 429648b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ resulting in potentially much smaller code size for minimal impact on performanc

## C Library

Running `zig build` will generate a static C library in `zig-out/lib` and a header file in `zig-out/include`.
Running `zig build lib` will generate a static C library in `zig-out/lib` and a header file in `zig-out/include`.
The header file requires `zig.h` which is located in the `lib_dir` output by running `zig env`.

This process should improve as https://github.com/ziglang/zig/issues/13528 is resolved.
Expand Down
12 changes: 7 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.root_source_file = .{ .path = "src/lib.zig" },
});
b.installArtifact(lib);
const lib_install = b.addInstallArtifact(lib, .{});

// Ideally we would use dlib.getEmittedH(), but https://github.com/ziglang/zig/issues/18497
_ = lib.getEmittedH(); // Needed to trigger generation
_ = lib.getEmittedH(); // Needed to trigger header generation
const lib_header = b.addInstallFile(.{ .path = "zig-cache/fastlanez.h" }, "include/fastlanez.h");
lib_header.step.dependOn(&lib.step);
b.getInstallStep().dependOn(&lib_header.step);
lib_header.step.dependOn(&lib_install.step);

// const lib_header_file = .{ .step = &lib.step, .path = "/Users/ngates/git/fastlanez/zig-cache/fastlanez.h" };
const lib_step = b.step("lib", "Build static C library");
lib_step.dependOn(&lib_header.step);
lib_step.dependOn(&lib_install.step);

// Unit Tests
const unit_tests = b.addTest(.{
Expand Down

0 comments on commit 429648b

Please sign in to comment.