authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-05-28 03:01:32+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-05-27 21:01:32-04:00
logc0aa9292bafa1a10c43297d3d5929049fab84e9a
treeb0efded728c8580f086557b05f83faa6b0505074
parentec10595b65490126e1b7d231f655be6d7d198acf
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

build: allow specifying rpaths explicitly (#8912)

It currently looks like that if the user links in a dylib using `lib_or_exe.linkSystemLibrary`, and the linked lib doesn't have a hardcoded path in its description load command but rather it allows for any runtime path via `@rpath`, then it is not possible to specify the runtime path explicitly using the build system.

1 files changed, 11 insertions(+), 0 deletions(-)

lib/std/build.zig+11
...@@ -1341,6 +1341,7 @@ pub const LibExeObjStep = struct {...@@ -1341,6 +1341,7 @@ pub const LibExeObjStep = struct {
1341 name_only_filename: []const u8,1341 name_only_filename: []const u8,
1342 strip: bool,1342 strip: bool,
1343 lib_paths: ArrayList([]const u8),1343 lib_paths: ArrayList([]const u8),
1344 rpaths: ArrayList([]const u8),
1344 framework_dirs: ArrayList([]const u8),1345 framework_dirs: ArrayList([]const u8),
1345 frameworks: BufSet,1346 frameworks: BufSet,
1346 verbose_link: bool,1347 verbose_link: bool,
...@@ -1536,6 +1537,7 @@ pub const LibExeObjStep = struct {...@@ -1536,6 +1537,7 @@ pub const LibExeObjStep = struct {
1536 .link_objects = ArrayList(LinkObject).init(builder.allocator),1537 .link_objects = ArrayList(LinkObject).init(builder.allocator),
1537 .c_macros = ArrayList([]const u8).init(builder.allocator),1538 .c_macros = ArrayList([]const u8).init(builder.allocator),
1538 .lib_paths = ArrayList([]const u8).init(builder.allocator),1539 .lib_paths = ArrayList([]const u8).init(builder.allocator),
1540 .rpaths = ArrayList([]const u8).init(builder.allocator),
1539 .framework_dirs = ArrayList([]const u8).init(builder.allocator),1541 .framework_dirs = ArrayList([]const u8).init(builder.allocator),
1540 .object_src = undefined,1542 .object_src = undefined,
1541 .build_options_contents = std.ArrayList(u8).init(builder.allocator),1543 .build_options_contents = std.ArrayList(u8).init(builder.allocator),
...@@ -2072,6 +2074,10 @@ pub const LibExeObjStep = struct {...@@ -2072,6 +2074,10 @@ pub const LibExeObjStep = struct {
2072 self.lib_paths.append(self.builder.dupe(path)) catch unreachable;2074 self.lib_paths.append(self.builder.dupe(path)) catch unreachable;
2073 }2075 }
20742076
2077 pub fn addRPath(self: *LibExeObjStep, path: []const u8) void {
2078 self.rpaths.append(self.builder.dupe(path)) catch unreachable;
2079 }
2080
2075 pub fn addFrameworkDir(self: *LibExeObjStep, dir_path: []const u8) void {2081 pub fn addFrameworkDir(self: *LibExeObjStep, dir_path: []const u8) void {
2076 self.framework_dirs.append(self.builder.dupe(dir_path)) catch unreachable;2082 self.framework_dirs.append(self.builder.dupe(dir_path)) catch unreachable;
2077 }2083 }
...@@ -2568,6 +2574,11 @@ pub const LibExeObjStep = struct {...@@ -2568,6 +2574,11 @@ pub const LibExeObjStep = struct {
2568 try zig_args.append(lib_path);2574 try zig_args.append(lib_path);
2569 }2575 }
25702576
2577 for (self.rpaths.items) |rpath| {
2578 try zig_args.append("-rpath");
2579 try zig_args.append(rpath);
2580 }
2581
2571 for (self.c_macros.items) |c_macro| {2582 for (self.c_macros.items) |c_macro| {
2572 try zig_args.append("-D");2583 try zig_args.append("-D");
2573 try zig_args.append(c_macro);2584 try zig_args.append(c_macro);