Skip to content

Commit a2fa15e

Browse files
committed
std: allow overriding install path of artifacts
This is necessary when, for example, writing a PAM module which should be installed to lib/security/module_name.so. Currently the zig build system forces shared libraries to be prefixed with "lib" and versions the so files as well as creating symlinks. Furthermore, artifacts can currently only be installed to the bin or lib directories, not sub-directories thereof. Allowing the user to manually specify the install path allows maximum flexibility, solving this use case and more.
1 parent ea9b38c commit a2fa15e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/std/build.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ pub const LibExeObjStep = struct {
12121212
is_linking_libc: bool = false,
12131213
vcpkg_bin_path: ?[]const u8 = null,
12141214

1215+
install_rel_path_override: ?[]const u8,
12151216
installed_path: ?[]const u8,
12161217
install_step: ?*InstallArtifactStep,
12171218

@@ -1348,6 +1349,7 @@ pub const LibExeObjStep = struct {
13481349
.rdynamic = false,
13491350
.output_dir = null,
13501351
.single_threaded = false,
1352+
.install_rel_path_override = null,
13511353
.installed_path = null,
13521354
.install_step = null,
13531355
};
@@ -1417,6 +1419,11 @@ pub const LibExeObjStep = struct {
14171419
self.output_dir = self.builder.dupePath(dir);
14181420
}
14191421

1422+
// Override the install path, relative to the install prefix
1423+
pub fn overrideInstallPath(self: *LibExeObjStep, rel_path: []const u8) void {
1424+
self.install_rel_path_override = rel_path;
1425+
}
1426+
14201427
pub fn install(self: *LibExeObjStep) void {
14211428
self.builder.installArtifact(self);
14221429
}
@@ -2327,6 +2334,11 @@ pub const InstallArtifactStep = struct {
23272334
self.step.dependOn(&artifact.step);
23282335
artifact.install_step = self;
23292336

2337+
if (artifact.install_rel_path_override) |rel_path| {
2338+
builder.pushInstalledFile(.Prefix, rel_path);
2339+
return self;
2340+
}
2341+
23302342
builder.pushInstalledFile(self.dest_dir, artifact.out_filename);
23312343
if (self.artifact.isDynamicLibrary()) {
23322344
builder.pushInstalledFile(.Lib, artifact.major_only_filename);
@@ -2348,6 +2360,13 @@ pub const InstallArtifactStep = struct {
23482360
const self = @fieldParentPtr(Self, "step", step);
23492361
const builder = self.builder;
23502362

2363+
if (self.artifact.install_rel_path_override) |rel_path| {
2364+
const full_dest_path = builder.getInstallPath(.Prefix, rel_path);
2365+
try builder.updateFile(self.artifact.getOutputPath(), full_dest_path);
2366+
self.artifact.installed_path = full_dest_path;
2367+
return;
2368+
}
2369+
23512370
const full_dest_path = builder.getInstallPath(self.dest_dir, self.artifact.out_filename);
23522371
try builder.updateFile(self.artifact.getOutputPath(), full_dest_path);
23532372
if (self.artifact.isDynamicLibrary() and self.artifact.target.wantSharedLibSymLinks()) {

0 commit comments

Comments
 (0)