diff options
author | Hilton Chain <hako@ultrarare.space> | 2024-11-13 23:44:33 +0800 |
---|---|---|
committer | Hilton Chain <hako@ultrarare.space> | 2024-12-31 10:54:17 +0800 |
commit | 368c1f4c5e207c21d88f490101d0859b0a036259 (patch) | |
tree | 1178492284843c68933fb405a64df8587c8f0058 /gnu/packages/patches/zig-0.12-use-system-paths.patch | |
parent | a0d5fc28b83f573ee63d48fc6460c53447a8eb2b (diff) |
gnu: Add zig-0.12.
* 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
Diffstat (limited to 'gnu/packages/patches/zig-0.12-use-system-paths.patch')
-rw-r--r-- | gnu/packages/patches/zig-0.12-use-system-paths.patch | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/gnu/packages/patches/zig-0.12-use-system-paths.patch b/gnu/packages/patches/zig-0.12-use-system-paths.patch new file mode 100644 index 0000000000..bcf0fd5ab1 --- /dev/null +++ b/gnu/packages/patches/zig-0.12-use-system-paths.patch @@ -0,0 +1,133 @@ +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 + |