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) {...@@ -309,8 +309,8 @@ pub const HeaderInstallation = union(enum) {
309309
310 pub fn dupe(self: HeaderInstallation, b: *std.Build) HeaderInstallation {310 pub fn dupe(self: HeaderInstallation, b: *std.Build) HeaderInstallation {
311 return switch (self) {311 return switch (self) {
312 .file => |f| f.dupe(b),312 .file => |f| .{ .file = f.dupe(b) },
313 .directory => |d| d.dupe(b),313 .directory => |d| .{ .directory = d.dupe(b) },
314 };314 };
315 }315 }
316};316};
...@@ -480,10 +480,12 @@ pub fn installConfigHeader(cs: *Compile, config_header: *Step.ConfigHeader) void...@@ -480,10 +480,12 @@ pub fn installConfigHeader(cs: *Compile, config_header: *Step.ConfigHeader) void
480480
481pub fn installLibraryHeaders(cs: *Compile, lib: *Compile) void {481pub fn installLibraryHeaders(cs: *Compile, lib: *Compile) void {
482 assert(lib.kind == .lib);482 assert(lib.kind == .lib);
483 const b = cs.step.owner;
483 for (lib.installed_headers.items) |installation| {484 for (lib.installed_headers.items) |installation| {
484 cs.installed_headers.append(installation) catch @panic("OOM");485 const installation_copy = installation.dupe(b);
485 cs.addHeaderInstallationToIncludeTree(installation);486 cs.installed_headers.append(installation_copy) catch @panic("OOM");
486 installation.getSource().addStepDependencies(&cs.step);487 cs.addHeaderInstallationToIncludeTree(installation_copy);
488 installation_copy.getSource().addStepDependencies(&cs.step);
487 }489 }
488}490}
489491
test/standalone/install_headers/build.zig+19-3
...@@ -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;
66
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 });
1315
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 }));
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
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);
5772
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);