| ... | ... | @@ -4,12 +4,14 @@ pub fn build(b: *std.Build) void { |
| 4 | 4 | const test_step = b.step("test", "Test"); |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | const empty_c = b.addWriteFiles().add("empty.c", ""); |
| 8 | |
| 7 | 9 | const libfoo = b.addStaticLibrary(.{ |
| 8 | 10 | .name = "foo", |
| 9 | 11 | .target = b.resolveTargetQuery(.{}), |
| 10 | 12 | .optimize = .Debug, |
| 11 | 13 | }); |
| 12 | | libfoo.addCSourceFile(.{ .file = b.addWriteFiles().add("empty.c", "") }); |
| 14 | libfoo.addCSourceFile(.{ .file = empty_c }); |
| 13 | 15 | |
| 14 | 16 | const exe = b.addExecutable(.{ |
| 15 | 17 | .name = "exe", |
| ... | ... | @@ -23,8 +25,9 @@ pub fn build(b: *std.Build) void { |
| 23 | 25 | \\#include <foo/sub_dir/b.h> |
| 24 | 26 | \\#include <foo/d.h> |
| 25 | 27 | \\#include <foo/config.h> |
| 28 | \\#include <bar.h> |
| 26 | 29 | \\int main(void) { |
| 27 | | \\ printf(FOO_A FOO_B FOO_D FOO_CONFIG_1 FOO_CONFIG_2); |
| 30 | \\ printf(FOO_A FOO_B FOO_D FOO_CONFIG_1 FOO_CONFIG_2 BAR_X); |
| 28 | 31 | \\ return 0; |
| 29 | 32 | \\} |
| 30 | 33 | ) }); |
| ... | ... | @@ -51,8 +54,20 @@ pub fn build(b: *std.Build) void { |
| 51 | 54 | .FOO_CONFIG_2 = "2", |
| 52 | 55 | })); |
| 53 | 56 | |
| 57 | const libbar = b.addStaticLibrary(.{ |
| 58 | .name = "bar", |
| 59 | .target = b.resolveTargetQuery(.{}), |
| 60 | .optimize = .Debug, |
| 61 | }); |
| 62 | libbar.addCSourceFile(.{ .file = empty_c }); |
| 63 | libbar.installHeader(b.addWriteFiles().add("bar.h", |
| 64 | \\#define BAR_X "X" |
| 65 | \\ |
| 66 | ), "bar.h"); |
| 67 | libfoo.installLibraryHeaders(libbar); |
| 68 | |
| 54 | 69 | const run_exe = b.addRunArtifact(exe); |
| 55 | | run_exe.expectStdOutEqual("ABD12"); |
| 70 | run_exe.expectStdOutEqual("ABD12X"); |
| 56 | 71 | test_step.dependOn(&run_exe.step); |
| 57 | 72 | |
| 58 | 73 | const install_exe = b.addInstallArtifact(libfoo, .{ |
| ... | ... | @@ -75,6 +90,7 @@ pub fn build(b: *std.Build) void { |
| 75 | 90 | "!custom/include/foo/sub_dir/c.ignore_me.h", |
| 76 | 91 | "custom/include/foo/d.h", |
| 77 | 92 | "custom/include/foo/config.h", |
| 93 | "custom/include/bar.h", |
| 78 | 94 | }); |
| 79 | 95 | run_check_exists.setCwd(.{ .cwd_relative = b.getInstallPath(.prefix, "") }); |
| 80 | 96 | run_check_exists.expectExitCode(0); |