mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2025-01-18 21:46:35 +01:00
3927e61481
* gnu/packages/patches/zig-0.10-fix-runpath.patch: New file. * gnu/packages/patches/zig-0.10-use-system-paths.patch: New file. * gnu/local.mk (dist_patch_DATA): Regisiter them. * gnu/packages/zig.scm (zig-0.10)[source]: Add patches. Use zig-source. [arguments]<#:validate-runpath?>: Unset. <#:phases>: Adjust 'patch-more-shebangs to use a file in inputs instead. Change-Id: Ic4fd22d8bba664e3d42f433875f9d099969b9df9
136 lines
6 KiB
Diff
136 lines
6 KiB
Diff
From 95a42ae38fed8ef0b0dd07b2568b649c1d7a9aeb Mon Sep 17 00:00:00 2001
|
|
From: Hilton Chain <hako@ultrarare.space>
|
|
Date: Wed, 27 Nov 2024 11:54:51 +0800
|
|
Subject: [PATCH] Use system paths.
|
|
|
|
Prefer Guix search paths and support Guix cross builds.
|
|
---
|
|
lib/std/zig/system/NativePaths.zig | 56 ++++++++++++++++++++++++-
|
|
lib/std/zig/system/NativeTargetInfo.zig | 25 +++++++++--
|
|
src/main.zig | 3 +-
|
|
3 files changed, 78 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig
|
|
index 2c4db3ec85..6366e37cd9 100644
|
|
--- a/lib/std/zig/system/NativePaths.zig
|
|
+++ b/lib/std/zig/system/NativePaths.zig
|
|
@@ -25,7 +25,53 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths
|
|
.warnings = ArrayList([:0]u8).init(allocator),
|
|
};
|
|
errdefer self.deinit();
|
|
-
|
|
+ if (isGuix(allocator)) {
|
|
+ const guix_cross_include_paths = [_][]const u8{ "CROSS_C_INCLUDE_PATH", "CROSS_CPLUS_INCLUDE_PATH" };
|
|
+ for (guix_cross_include_paths) |env_var| {
|
|
+ if (process.getEnvVarOwned(allocator, env_var)) |include_path| {
|
|
+ var it = mem.tokenize(u8, include_path, ":");
|
|
+ while (it.next()) |dir|
|
|
+ try self.addIncludeDir(dir);
|
|
+ } else |err| switch (err) {
|
|
+ error.InvalidUtf8 => {},
|
|
+ error.EnvironmentVariableNotFound => {},
|
|
+ error.OutOfMemory => |e| return e,
|
|
+ }
|
|
+ }
|
|
+ if (process.getEnvVarOwned(allocator, "CROSS_LIBRARY_PATH")) |library_path| {
|
|
+ var it = mem.tokenize(u8, library_path, ":");
|
|
+ while (it.next()) |dir|
|
|
+ try self.addLibDir(dir);
|
|
+ } else |err| switch (err) {
|
|
+ error.InvalidUtf8 => {},
|
|
+ error.EnvironmentVariableNotFound => {},
|
|
+ error.OutOfMemory => |e| return e,
|
|
+ }
|
|
+ if (!isCrossGuix(allocator)) {
|
|
+ const guix_include_paths = [_][]const u8{ "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH" };
|
|
+ for (guix_include_paths) |env_var| {
|
|
+ if (process.getEnvVarOwned(allocator, env_var)) |include_path| {
|
|
+ var it = mem.tokenize(u8, include_path, ":");
|
|
+ while (it.next()) |dir|
|
|
+ try self.addIncludeDir(dir);
|
|
+ } else |err| switch (err) {
|
|
+ error.InvalidUtf8 => {},
|
|
+ error.EnvironmentVariableNotFound => {},
|
|
+ error.OutOfMemory => |e| return e,
|
|
+ }
|
|
+ }
|
|
+ if (process.getEnvVarOwned(allocator, "LIBRARY_PATH")) |library_path| {
|
|
+ var it = mem.tokenize(u8, library_path, ":");
|
|
+ while (it.next()) |dir|
|
|
+ try self.addLibDir(dir);
|
|
+ } else |err| switch (err) {
|
|
+ error.InvalidUtf8 => {},
|
|
+ error.EnvironmentVariableNotFound => {},
|
|
+ error.OutOfMemory => |e| return e,
|
|
+ }
|
|
+ }
|
|
+ return self;
|
|
+ }
|
|
var is_nix = false;
|
|
if (process.getEnvVarOwned(allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
|
|
defer allocator.free(nix_cflags_compile);
|
|
@@ -231,3 +277,11 @@ fn appendArray(self: *NativePaths, array: *ArrayList([:0]u8), s: []const u8) !vo
|
|
errdefer array.allocator.free(item);
|
|
try array.append(item);
|
|
}
|
|
+
|
|
+pub fn isCrossGuix(arena: Allocator) bool {
|
|
+ return process.hasEnvVar(arena, "CROSS_LIBRARY_PATH") catch false;
|
|
+}
|
|
+
|
|
+pub fn isGuix(arena: Allocator) bool {
|
|
+ return isCrossGuix(arena) or process.hasEnvVar(arena, "LIBRARY_PATH") catch false;
|
|
+}
|
|
diff --git a/lib/std/zig/system/NativeTargetInfo.zig b/lib/std/zig/system/NativeTargetInfo.zig
|
|
index cae45af64b..0c87d49816 100644
|
|
--- a/lib/std/zig/system/NativeTargetInfo.zig
|
|
+++ b/lib/std/zig/system/NativeTargetInfo.zig
|
|
@@ -936,10 +936,27 @@ fn defaultAbiAndDynamicLinker(cpu: Target.Cpu, os: Target.Os, cross_target: Cros
|
|
};
|
|
return NativeTargetInfo{
|
|
.target = target,
|
|
- .dynamic_linker = if (cross_target.dynamic_linker.get() == null)
|
|
- target.standardDynamicLinkerPath()
|
|
- else
|
|
- cross_target.dynamic_linker,
|
|
+ .dynamic_linker = if (cross_target.dynamic_linker.get() == null) blk: {
|
|
+ var standard_linker = target.standardDynamicLinkerPath();
|
|
+ if (standard_linker.get()) |standard_linker_path| {
|
|
+ if (builtin.os.tag != .windows and builtin.os.tag != .wasi) {
|
|
+ if (std.os.getenv("CROSS_LIBRARY_PATH") orelse std.os.getenv("LIBRARY_PATH")) |library_path| {
|
|
+ const linker_basename = fs.path.basename(standard_linker_path);
|
|
+ var buffer: [255]u8 = undefined;
|
|
+ var it = mem.tokenize(u8, library_path, ":");
|
|
+ while (it.next()) |dir| {
|
|
+ const linker_fullpath = std.fmt.bufPrint(&buffer, "{s}{s}{s}", .{ dir, fs.path.sep_str, linker_basename }) catch "";
|
|
+ const guix_linker_path = fs.cwd().realpath(linker_fullpath, &buffer) catch "";
|
|
+ if (guix_linker_path.len != 0) {
|
|
+ standard_linker.set(guix_linker_path);
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ break :blk standard_linker;
|
|
+ } else cross_target.dynamic_linker,
|
|
};
|
|
}
|
|
|
|
diff --git a/src/main.zig b/src/main.zig
|
|
index b752c89308..4fb7310a4f 100644
|
|
--- a/src/main.zig
|
|
+++ b/src/main.zig
|
|
@@ -2375,7 +2375,8 @@ fn buildOutputType(
|
|
want_native_include_dirs = true;
|
|
}
|
|
|
|
- if (sysroot == null and cross_target.isNativeOs() and
|
|
+ if (std.zig.system.NativePaths.isCrossGuix(arena) or
|
|
+ sysroot == null and cross_target.isNativeOs() and
|
|
(system_libs.count() != 0 or want_native_include_dirs))
|
|
{
|
|
const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| {
|
|
--
|
|
2.46.0
|
|
|