authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-03-04 01:38:29+01:00
committergravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-04-07 15:34:47+02:00
log5af4e91e0036a5d83889d20ee1477a366c6c12ac
treee14470c27ad448d1992941f23eac3f918ff5b4d3
parent7b1a6a93a4e94ee859ab2a41c7865b7859d19e62

Oops, forgot to dupe installations in `installLibraryHeaders`

Added test coverage for `installLibraryHeaders`

2 files changed, 26 insertions(+), 8 deletions(-)

lib/std/Build/Step/Compile.zig+7-5
......@@ -309,8 +309,8 @@ pub const HeaderInstallation = union(enum) {
309309
310310 pub fn dupe(self: HeaderInstallation, b: *std.Build) HeaderInstallation {
311311 return switch (self) {
312 .file => |f| f.dupe(b),
313 .directory => |d| d.dupe(b),
312 .file => |f| .{ .file = f.dupe(b) },
313 .directory => |d| .{ .directory = d.dupe(b) },
314314 };
315315 }
316316};
......@@ -480,10 +480,12 @@ pub fn installConfigHeader(cs: *Compile, config_header: *Step.ConfigHeader) void
480480
481481pub fn installLibraryHeaders(cs: *Compile, lib: *Compile) void {
482482 assert(lib.kind == .lib);
483 const b = cs.step.owner;
483484 for (lib.installed_headers.items) |installation| {
484 cs.installed_headers.append(installation) catch @panic("OOM");
485 cs.addHeaderInstallationToIncludeTree(installation);
486 installation.getSource().addStepDependencies(&cs.step);
485 const installation_copy = installation.dupe(b);
486 cs.installed_headers.append(installation_copy) catch @panic("OOM");
487 cs.addHeaderInstallationToIncludeTree(installation_copy);
488 installation_copy.getSource().addStepDependencies(&cs.step);
487489 }
488490}
489491
test/standalone/install_headers/build.zig+19-3
......@@ -4,12 +4,14 @@ pub fn build(b: *std.Build) void {
44 const test_step = b.step("test", "Test");
55 b.default_step = test_step;
66
7 const empty_c = b.addWriteFiles().add("empty.c", "");
8
79 const libfoo = b.addStaticLibrary(.{
810 .name = "foo",
911 .target = b.resolveTargetQuery(.{}),
1012 .optimize = .Debug,
1113 });
12 libfoo.addCSourceFile(.{ .file = b.addWriteFiles().add("empty.c", "") });
14 libfoo.addCSourceFile(.{ .file = empty_c });
1315
1416 const exe = b.addExecutable(.{
1517 .name = "exe",
......@@ -23,8 +25,9 @@ pub fn build(b: *std.Build) void {
2325 \\#include <foo/sub_dir/b.h>
2426 \\#include <foo/d.h>
2527 \\#include <foo/config.h>
28 \\#include <bar.h>
2629 \\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);
2831 \\ return 0;
2932 \\}
3033 ) });
......@@ -51,8 +54,20 @@ pub fn build(b: *std.Build) void {
5154 .FOO_CONFIG_2 = "2",
5255 }));
5356
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
5469 const run_exe = b.addRunArtifact(exe);
55 run_exe.expectStdOutEqual("ABD12");
70 run_exe.expectStdOutEqual("ABD12X");
5671 test_step.dependOn(&run_exe.step);
5772
5873 const install_exe = b.addInstallArtifact(libfoo, .{
......@@ -75,6 +90,7 @@ pub fn build(b: *std.Build) void {
7590 "!custom/include/foo/sub_dir/c.ignore_me.h",
7691 "custom/include/foo/d.h",
7792 "custom/include/foo/config.h",
93 "custom/include/bar.h",
7894 });
7995 run_check_exists.setCwd(.{ .cwd_relative = b.getInstallPath(.prefix, "") });
8096 run_check_exists.expectExitCode(0);