projects/guix·blob python-team · refs

168 lines · 7.7 KiB

1From 0db495c7db59bf61239f09de5dd77c0669238941 Mon Sep 17 00:00:00 2001
2From: Theodor Thornhill <[email protected]>
3Date: Thu, 18 Jun 2026 21:42:13 +0200
4Subject: [PATCH] Zig 0.16 fix runpath
5
6---
7 lib/std/Build/Step/Compile.zig | 2 ++
8 lib/std/zig.zig | 3 +++
9 lib/std/zig/system/NativePaths.zig | 36 ++++++++++++++++----------
10 src/main.zig | 41 +++++++++++++++++++++++++++---
11 4 files changed, 65 insertions(+), 17 deletions(-)
12
13diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig
14index 529b58a0dd..fc3ffe09e3 100644
15--- a/lib/std/Build/Step/Compile.zig
16+++ b/lib/std/Build/Step/Compile.zig
17@@ -807,6 +807,8 @@ pub fn runPkgConfig(step: *Step, lib_name: []const u8) !PkgConfigResult {
18 try zig_cflags.append(arg);
19 } else if (mem.startsWith(u8, arg, wl_rpath_prefix)) {
20 try zig_cflags.appendSlice(&[_][]const u8{ "-rpath", arg[wl_rpath_prefix.len..] });
21+ } else if (mem.startsWith(u8, arg, "-Wl,-rpath=")) {
22+ try zig_libs.appendSlice(&[_][]const u8{ "-L", arg["-Wl,-rpath=".len..] });
23 } else if (b.debug_pkg_config) {
24 return step.fail("unknown pkg-config flag '{s}'", .{arg});
25 }
26diff --git a/lib/std/zig.zig b/lib/std/zig.zig
27index 0dcd947046..4c9e4ac6dc 100644
28--- a/lib/std/zig.zig
29+++ b/lib/std/zig.zig
30@@ -762,6 +762,9 @@ pub const EnvVar = enum {
31 C_INCLUDE_PATH,
32 CPLUS_INCLUDE_PATH,
33 LIBRARY_PATH,
34+ CROSS_C_INCLUDE_PATH,
35+ CROSS_CPLUS_INCLUDE_PATH,
36+ CROSS_LIBRARY_PATH,
37 CC,
38
39 // Terminal integration
40diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig
41index ead8eb2f70..ed8faa0309 100644
42--- a/lib/std/zig/system/NativePaths.zig
43+++ b/lib/std/zig/system/NativePaths.zig
44@@ -178,24 +178,34 @@ pub fn detect(
45
46 // Distros like guix don't use FHS, so they rely on environment
47 // variables to search for headers and libraries.
48- if (std.zig.EnvVar.C_INCLUDE_PATH.get(environ_map)) |c_include_path| {
49- var it = mem.tokenizeScalar(u8, c_include_path, ':');
50+ const cross_library_path = std.zig.EnvVar.CROSS_LIBRARY_PATH.get(environ_map);
51+ const library_path = std.zig.EnvVar.LIBRARY_PATH.get(environ_map);
52+ const guix_path = cross_library_path orelse library_path;
53+ if (guix_path) |paths| {
54+ var it = mem.tokenizeScalar(u8, paths, ':');
55 while (it.next()) |dir| {
56- try self.addIncludeDir(dir);
57+ try self.addLibDir(dir);
58+ try self.addRPath(dir);
59 }
60 }
61-
62- if (std.zig.EnvVar.CPLUS_INCLUDE_PATH.get(environ_map)) |cplus_include_path| {
63- var it = mem.tokenizeScalar(u8, cplus_include_path, ':');
64- while (it.next()) |dir| {
65- try self.addIncludeDir(dir);
66+ if (cross_library_path != null) {
67+ if (std.zig.EnvVar.CROSS_C_INCLUDE_PATH.get(environ_map)) |cross_c_include_path| {
68+ var include_it = mem.tokenizeScalar(u8, cross_c_include_path, ':');
69+ while (include_it.next()) |dir| try self.addIncludeDir(dir);
70+ }
71+ if (std.zig.EnvVar.CROSS_CPLUS_INCLUDE_PATH.get(environ_map)) |cross_cplus_include_path| {
72+ var include_it = mem.tokenizeScalar(u8, cross_cplus_include_path, ':');
73+ while (include_it.next()) |dir| try self.addIncludeDir(dir);
74 }
75 }
76-
77- if (std.zig.EnvVar.LIBRARY_PATH.get(environ_map)) |library_path| {
78- var it = mem.tokenizeScalar(u8, library_path, ':');
79- while (it.next()) |dir| {
80- try self.addLibDir(dir);
81+ if (library_path != null) {
82+ if (std.zig.EnvVar.C_INCLUDE_PATH.get(environ_map)) |c_include_path| {
83+ var include_it = mem.tokenizeScalar(u8, c_include_path, ':');
84+ while (include_it.next()) |dir| try self.addIncludeDir(dir);
85+ }
86+ if (std.zig.EnvVar.CPLUS_INCLUDE_PATH.get(environ_map)) |cplus_include_path| {
87+ var include_it = mem.tokenizeScalar(u8, cplus_include_path, ':');
88+ while (include_it.next()) |dir| try self.addIncludeDir(dir);
89 }
90 }
91 }
92diff --git a/src/main.zig b/src/main.zig
93index 0395a21a5f..71eaeb993e 100644
94--- a/src/main.zig
95+++ b/src/main.zig
96@@ -3979,7 +3979,26 @@ fn createModule(
97 }
98
99 const target_query = std.zig.parseTargetQueryOrReportFatalError(arena, target_parse_options);
100- const target = std.zig.resolveTargetQueryOrFatal(io, target_query);
101+ var target = std.zig.resolveTargetQueryOrFatal(io, target_query);
102+
103+ if (target_query.dynamic_linker == null) {
104+ const guix_lib_path =
105+ std.zig.EnvVar.CROSS_LIBRARY_PATH.get(environ_map) orelse std.zig.EnvVar.LIBRARY_PATH.get(environ_map) orelse null;
106+ if (guix_lib_path) |lib_path| {
107+ if (target.dynamic_linker.get()) |standard_path| {
108+ const linker_basename = fs.path.basename(standard_path);
109+ var it = mem.tokenizeScalar(u8, lib_path, ':');
110+ while (it.next()) |dir| {
111+ const candidate = try std.fmt.allocPrint(arena, "{s}/{s}", .{ dir, linker_basename });
112+ if (Io.Dir.accessAbsolute(io, candidate, .{})) |_| {
113+ target.dynamic_linker.set(candidate);
114+ break;
115+ } else |_| {}
116+ }
117+ }
118+ }
119+ }
120+
121 break :t .{
122 .result = target,
123 .is_native_os = target_query.isNativeOs(),
124@@ -4077,7 +4096,7 @@ fn createModule(
125 create_module.want_native_include_dirs = true;
126 }
127
128- if (create_module.each_lib_rpath orelse resolved_target.is_native_os) {
129+ if (create_module.each_lib_rpath orelse false) {
130 try create_module.rpath_list.ensureUnusedCapacity(arena, create_module.lib_directories.items.len);
131 for (create_module.lib_directories.items) |lib_directory| {
132 create_module.rpath_list.appendAssumeCapacity(lib_directory.path.?);
133@@ -4085,9 +4104,11 @@ fn createModule(
134 }
135
136 // Trigger native system library path detection if necessary.
137+ const is_guix = std.zig.EnvVar.CROSS_LIBRARY_PATH.isSet(environ_map) or std.zig.EnvVar.LIBRARY_PATH.isSet(environ_map);
138 if (create_module.sysroot == null and
139- resolved_target.is_native_os and resolved_target.is_native_abi and
140- create_module.want_native_include_dirs)
141+ (is_guix or
142+ (resolved_target.is_native_os and resolved_target.is_native_abi and
143+ create_module.want_native_include_dirs)))
144 {
145 var paths = std.zig.system.NativePaths.detect(arena, io, target, environ_map) catch |err|
146 fatal("unable to detect native system paths: {t}", .{err});
147@@ -4138,6 +4159,18 @@ fn createModule(
148 color,
149 ) catch |err| fatal("failed to resolve link inputs: {s}", .{@errorName(err)});
150
151+ if (is_guix) {
152+ for (create_module.link_inputs.items) |link_input| {
153+ const p = switch (link_input) {
154+ .dso => |dso| dso.path,
155+ else => continue,
156+ };
157+ if (fs.path.dirname(p.sub_path) orelse p.root_dir.path) |ld| {
158+ try create_module.rpath_list.append(arena, ld);
159+ }
160+ }
161+ }
162+
163 if (!create_module.opts.any_dyn_libs) for (create_module.link_inputs.items) |item| switch (item) {
164 .dso, .dso_exact => {
165 create_module.opts.any_dyn_libs = true;
166--
1672.54.0
168