Skip to content

Commit f78e4b1

Browse files
committed
std: allow overriding install dir of artifacts
This is necessary when, for example, writing a PAM module which should be installed to lib/security/module_name.so.
1 parent 800c5de commit f78e4b1

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

lib/std/build.zig

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,7 @@ pub const Builder = struct {
10481048
.Bin => self.exe_dir,
10491049
.Lib => self.lib_dir,
10501050
.Header => self.h_dir,
1051+
.Custom => |path| fs.path.join(self.allocator, &[_][]const u8{ self.install_path, path }) catch unreachable,
10511052
};
10521053
return fs.path.resolve(
10531054
self.allocator,
@@ -1212,6 +1213,8 @@ pub const LibExeObjStep = struct {
12121213
is_linking_libc: bool = false,
12131214
vcpkg_bin_path: ?[]const u8 = null,
12141215

1216+
/// This may be set in order to override the default install directory
1217+
override_dest_dir: ?InstallDir,
12151218
installed_path: ?[]const u8,
12161219
install_step: ?*InstallArtifactStep,
12171220

@@ -1348,6 +1351,7 @@ pub const LibExeObjStep = struct {
13481351
.rdynamic = false,
13491352
.output_dir = null,
13501353
.single_threaded = false,
1354+
.override_dest_dir = null,
13511355
.installed_path = null,
13521356
.install_step = null,
13531357
};
@@ -2309,17 +2313,17 @@ pub const InstallArtifactStep = struct {
23092313
.builder = builder,
23102314
.step = Step.init(.InstallArtifact, builder.fmt("install {}", .{artifact.step.name}), builder.allocator, make),
23112315
.artifact = artifact,
2312-
.dest_dir = switch (artifact.kind) {
2316+
.dest_dir = artifact.override_dest_dir orelse switch (artifact.kind) {
23132317
.Obj => unreachable,
23142318
.Test => unreachable,
2315-
.Exe => .Bin,
2316-
.Lib => .Lib,
2319+
.Exe => InstallDir{ .Bin = {} },
2320+
.Lib => InstallDir{ .Lib = {} },
23172321
},
23182322
.pdb_dir = if (artifact.producesPdbFile()) blk: {
23192323
if (artifact.kind == .Exe) {
2320-
break :blk InstallDir.Bin;
2324+
break :blk InstallDir{ .Bin = {} };
23212325
} else {
2322-
break :blk InstallDir.Lib;
2326+
break :blk InstallDir{ .Lib = {} };
23232327
}
23242328
} else null,
23252329
.h_dir = if (artifact.kind == .Lib and artifact.emit_h) .Header else null,
@@ -2615,11 +2619,13 @@ const VcpkgRootStatus = enum {
26152619

26162620
pub const VcpkgLinkage = std.builtin.LinkMode;
26172621

2618-
pub const InstallDir = enum {
2619-
Prefix,
2620-
Lib,
2621-
Bin,
2622-
Header,
2622+
pub const InstallDir = union(enum) {
2623+
Prefix: void,
2624+
Lib: void,
2625+
Bin: void,
2626+
Header: void,
2627+
/// A path relative to the prefix
2628+
Custom: []const u8,
26232629
};
26242630

26252631
pub const InstalledFile = struct {

0 commit comments

Comments
 (0)