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