mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2025-01-31 06:46:50 +01:00
368c1f4c5e
* gnu/packages/patches/zig-0.12-fix-runpath.patch: New file. * gnu/packages/patches/zig-0.12-use-baseline-cpu-by-default.patch: New file. * gnu/packages/patches/zig-0.12-use-system-paths.patch: New file. * gnu/local.mk (dist_patch_DATA): Regisiter them. * gnu/packages/zig.scm (zig-0.12-glibc-abi-tool,zig-0.12): New variables. Change-Id: I700d0afa2b373bf24a4f3527548e86dbed1aff17
133 lines
5.9 KiB
Diff
133 lines
5.9 KiB
Diff
From ef7d97a722260e0a4fbd110625355b556c7ab8e3 Mon Sep 17 00:00:00 2001
|
|
From: Hilton Chain <hako@ultrarare.space>
|
|
Date: Fri, 29 Nov 2024 14:13:30 +0800
|
|
Subject: [PATCH] Use system paths.
|
|
|
|
Prefer Guix search paths and support Guix cross builds.
|
|
---
|
|
lib/std/zig/system.zig | 25 +++++++++++---
|
|
lib/std/zig/system/NativePaths.zig | 53 ++++++++++++++++++++++++++++++
|
|
src/main.zig | 3 +-
|
|
3 files changed, 76 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig
|
|
index 83c798c342..138d43f2e1 100644
|
|
--- a/lib/std/zig/system.zig
|
|
+++ b/lib/std/zig/system.zig
|
|
@@ -1123,10 +1123,27 @@ fn defaultAbiAndDynamicLinker(cpu: Target.Cpu, os: Target.Os, query: Target.Quer
|
|
.os = os,
|
|
.abi = abi,
|
|
.ofmt = query.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch),
|
|
- .dynamic_linker = if (query.dynamic_linker.get() == null)
|
|
- Target.DynamicLinker.standard(cpu, os.tag, abi)
|
|
- else
|
|
- query.dynamic_linker,
|
|
+ .dynamic_linker = if (query.dynamic_linker.get() == null) blk: {
|
|
+ var standard_linker = Target.DynamicLinker.standard(cpu, os.tag, abi);
|
|
+ if (standard_linker.get()) |standard_linker_path| {
|
|
+ if (builtin.os.tag != .windows and builtin.os.tag != .wasi) {
|
|
+ if (posix.getenv("CROSS_LIBRARY_PATH") orelse posix.getenv("LIBRARY_PATH")) |library_path| {
|
|
+ const linker_basename = fs.path.basename(standard_linker_path);
|
|
+ var buffer: [255]u8 = undefined;
|
|
+ var it = mem.tokenizeScalar(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 query.dynamic_linker,
|
|
};
|
|
}
|
|
|
|
diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig
|
|
index 2a50e27b0c..f4cc0e8b3a 100644
|
|
--- a/lib/std/zig/system/NativePaths.zig
|
|
+++ b/lib/std/zig/system/NativePaths.zig
|
|
@@ -15,6 +15,51 @@ warnings: std.ArrayListUnmanaged([]const u8) = .{},
|
|
|
|
pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths {
|
|
var self: NativePaths = .{ .arena = arena };
|
|
+ if (isGuix(arena)) {
|
|
+ inline for ([_][]const u8{ "CROSS_C_INCLUDE_PATH", "CROSS_CPLUS_INCLUDE_PATH" }) |env_var| {
|
|
+ if (process.getEnvVarOwned(arena, env_var)) |include_path| {
|
|
+ var it = mem.tokenizeScalar(u8, include_path, ':');
|
|
+ while (it.next()) |dir|
|
|
+ try self.addIncludeDir(dir);
|
|
+ } else |err| switch (err) {
|
|
+ error.InvalidWtf8 => unreachable,
|
|
+ error.EnvironmentVariableNotFound => {},
|
|
+ error.OutOfMemory => |e| return e,
|
|
+ }
|
|
+ }
|
|
+ if (process.getEnvVarOwned(arena, "CROSS_LIBRARY_PATH")) |library_path| {
|
|
+ var it = mem.tokenizeScalar(u8, library_path, ':');
|
|
+ while (it.next()) |dir|
|
|
+ try self.addLibDir(dir);
|
|
+ } else |err| switch (err) {
|
|
+ error.InvalidWtf8 => unreachable,
|
|
+ error.EnvironmentVariableNotFound => {},
|
|
+ error.OutOfMemory => |e| return e,
|
|
+ }
|
|
+ if (!isCrossGuix(arena)) {
|
|
+ inline for ([_][]const u8{ "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH" }) |env_var| {
|
|
+ if (process.getEnvVarOwned(arena, env_var)) |include_path| {
|
|
+ var it = mem.tokenizeScalar(u8, include_path, ':');
|
|
+ while (it.next()) |dir|
|
|
+ try self.addIncludeDir(dir);
|
|
+ } else |err| switch (err) {
|
|
+ error.InvalidWtf8 => unreachable,
|
|
+ error.EnvironmentVariableNotFound => {},
|
|
+ error.OutOfMemory => |e| return e,
|
|
+ }
|
|
+ }
|
|
+ if (process.getEnvVarOwned(arena, "LIBRARY_PATH")) |library_path| {
|
|
+ var it = mem.tokenizeScalar(u8, library_path, ':');
|
|
+ while (it.next()) |dir|
|
|
+ try self.addLibDir(dir);
|
|
+ } else |err| switch (err) {
|
|
+ error.InvalidWtf8 => unreachable,
|
|
+ error.EnvironmentVariableNotFound => {},
|
|
+ error.OutOfMemory => |e| return e,
|
|
+ }
|
|
+ }
|
|
+ return self;
|
|
+ }
|
|
var is_nix = false;
|
|
if (process.getEnvVarOwned(arena, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
|
|
is_nix = true;
|
|
@@ -208,3 +253,11 @@ pub fn addWarningFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype
|
|
pub fn addRPath(self: *NativePaths, s: []const u8) !void {
|
|
try self.rpaths.append(self.arena, s);
|
|
}
|
|
+
|
|
+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/src/main.zig b/src/main.zig
|
|
index 5b0e211647..d27b63d5a3 100644
|
|
--- a/src/main.zig
|
|
+++ b/src/main.zig
|
|
@@ -3706,7 +3706,8 @@ fn createModule(
|
|
}
|
|
|
|
// Trigger native system library path detection if necessary.
|
|
- if (create_module.sysroot == null and
|
|
+ if (std.zig.system.NativePaths.isCrossGuix(arena) or
|
|
+ create_module.sysroot == null and
|
|
resolved_target.is_native_os and resolved_target.is_native_abi and
|
|
create_module.want_native_include_dirs)
|
|
{
|
|
--
|
|
2.46.0
|
|
|