authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-10 22:23:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-11 15:39:49-08:00
logfe8951cc941a55b23387b8d8bc09c62ea71409dd
treead3afe225ac43e95bc8f3195617f1b666824b396
parent416717d04e182841d87783960e12068100b5b1fb

zig build: add Artifact.installHeadersDirectory

This one is useful for when the C library has a "include" directory but it needs to get renamed to, e.g. "lame" when being installed.

1 files changed, 20 insertions(+), 6 deletions(-)

lib/std/build/LibExeObjStep.zig+20-6
...@@ -108,7 +108,7 @@ object_src: []const u8,...@@ -108,7 +108,7 @@ object_src: []const u8,
108link_objects: ArrayList(LinkObject),108link_objects: ArrayList(LinkObject),
109include_dirs: ArrayList(IncludeDir),109include_dirs: ArrayList(IncludeDir),
110c_macros: ArrayList([]const u8),110c_macros: ArrayList([]const u8),
111installed_headers: ArrayList(*std.build.InstallFileStep),111installed_headers: ArrayList(*std.build.Step),
112output_dir: ?[]const u8,112output_dir: ?[]const u8,
113is_linking_libc: bool = false,113is_linking_libc: bool = false,
114is_linking_libcpp: bool = false,114is_linking_libcpp: bool = false,
...@@ -371,7 +371,7 @@ fn initExtraArgs(...@@ -371,7 +371,7 @@ fn initExtraArgs(
371 .lib_paths = ArrayList([]const u8).init(builder.allocator),371 .lib_paths = ArrayList([]const u8).init(builder.allocator),
372 .rpaths = ArrayList([]const u8).init(builder.allocator),372 .rpaths = ArrayList([]const u8).init(builder.allocator),
373 .framework_dirs = ArrayList([]const u8).init(builder.allocator),373 .framework_dirs = ArrayList([]const u8).init(builder.allocator),
374 .installed_headers = ArrayList(*std.build.InstallFileStep).init(builder.allocator),374 .installed_headers = ArrayList(*std.build.Step).init(builder.allocator),
375 .object_src = undefined,375 .object_src = undefined,
376 .c_std = Builder.CStd.C99,376 .c_std = Builder.CStd.C99,
377 .override_lib_dir = null,377 .override_lib_dir = null,
...@@ -478,7 +478,21 @@ pub fn installHeader(a: *LibExeObjStep, src_path: []const u8) void {...@@ -478,7 +478,21 @@ pub fn installHeader(a: *LibExeObjStep, src_path: []const u8) void {
478 const basename = fs.path.basename(src_path);478 const basename = fs.path.basename(src_path);
479 const install_file = a.builder.addInstallHeaderFile(src_path, basename);479 const install_file = a.builder.addInstallHeaderFile(src_path, basename);
480 a.builder.getInstallStep().dependOn(&install_file.step);480 a.builder.getInstallStep().dependOn(&install_file.step);
481 a.installed_headers.append(install_file) catch unreachable;481 a.installed_headers.append(&install_file.step) catch unreachable;
482}
483
484pub fn installHeadersDirectory(
485 a: *LibExeObjStep,
486 src_dir_path: []const u8,
487 dest_rel_path: []const u8,
488) void {
489 const install_dir = a.builder.addInstallDirectory(.{
490 .source_dir = src_dir_path,
491 .install_dir = .header,
492 .install_subdir = dest_rel_path,
493 });
494 a.builder.getInstallStep().dependOn(&install_dir.step);
495 a.installed_headers.append(&install_dir.step) catch unreachable;
482}496}
483497
484/// Creates a `RunStep` with an executable built with `addExecutable`.498/// Creates a `RunStep` with an executable built with `addExecutable`.
...@@ -1701,9 +1715,9 @@ fn make(step: *Step) !void {...@@ -1701,9 +1715,9 @@ fn make(step: *Step) !void {
1701 try zig_args.append("-isystem");1715 try zig_args.append("-isystem");
1702 try zig_args.append(fs.path.dirname(h_path).?);1716 try zig_args.append(fs.path.dirname(h_path).?);
1703 }1717 }
1704 if (other.installed_headers.items.len != 0) {1718 if (other.installed_headers.items.len > 0) {
1705 for (other.installed_headers.items) |install_file| {1719 for (other.installed_headers.items) |install_step| {
1706 try install_file.step.make();1720 try install_step.make();
1707 }1721 }
1708 try zig_args.append("-I");1722 try zig_args.append("-I");
1709 try zig_args.append(builder.pathJoin(&.{1723 try zig_args.append(builder.pathJoin(&.{