diff options
author | Hilton Chain <hako@ultrarare.space> | 2024-11-11 11:10:16 +0800 |
---|---|---|
committer | Hilton Chain <hako@ultrarare.space> | 2024-12-31 10:54:15 +0800 |
commit | ab8979321881e59777da31ad11e77d5e482ff843 (patch) | |
tree | 34c3d8cda8a51dd023306fa8297220113119db2f /gnu/packages/patches | |
parent | 654e058538754f35eabf63e729243930140de89b (diff) |
gnu: Add zig-0.11.
* gnu/packages/patches/zig-0.11-fix-runpath.patch: New file.
* gnu/packages/patches/zig-0.11-use-system-paths.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register them.
* gnu/packages/zig.scm (zig-0.11-glibc-abi-tool,zig-0.11): New variables.
Change-Id: I2507af62918f3989967d55dec942b84655d6d8bd
Diffstat (limited to 'gnu/packages/patches')
-rw-r--r-- | gnu/packages/patches/zig-0.11-fix-runpath.patch | 45 | ||||
-rw-r--r-- | gnu/packages/patches/zig-0.11-use-system-paths.patch | 133 |
2 files changed, 178 insertions, 0 deletions
diff --git a/gnu/packages/patches/zig-0.11-fix-runpath.patch b/gnu/packages/patches/zig-0.11-fix-runpath.patch new file mode 100644 index 0000000000..1c9e892874 --- /dev/null +++ b/gnu/packages/patches/zig-0.11-fix-runpath.patch @@ -0,0 +1,45 @@ +From 4a5397b856564d0fbc0b89186e682e6694a909b0 Mon Sep 17 00:00:00 2001 +From: Hilton Chain <hako@ultrarare.space> +Date: Wed, 27 Nov 2024 11:55:44 +0800 +Subject: [PATCH] Fix RUNPATH issue. + +Add needed libraries and libc to RUNPATH when CROSS_LIBRARY_PATH or LIBRARY_PATH +is set. +--- + src/Compilation.zig | 2 +- + src/link/Elf.zig | 6 ++++++ + 2 files changed, 7 insertions(+), 1 deletion(-) + +diff --git a/src/Compilation.zig b/src/Compilation.zig +index a08c3e09f4..add374d0ba 100644 +--- a/src/Compilation.zig ++++ b/src/Compilation.zig +@@ -1542,7 +1542,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { + .llvm_cpu_features = llvm_cpu_features, + .skip_linker_dependencies = options.skip_linker_dependencies, + .parent_compilation_link_libc = options.parent_compilation_link_libc, +- .each_lib_rpath = options.each_lib_rpath orelse false, ++ .each_lib_rpath = std.zig.system.NativePaths.isGuix(arena) or options.each_lib_rpath orelse false, + .build_id = build_id, + .cache_mode = cache_mode, + .disable_lld_caching = options.disable_lld_caching or cache_mode == .whole, +diff --git a/src/link/Elf.zig b/src/link/Elf.zig +index dd88d47fab..b6e3944725 100644 +--- a/src/link/Elf.zig ++++ b/src/link/Elf.zig +@@ -1730,6 +1730,12 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v + } + } + } ++ if (self.base.options.link_libc and self.base.options.link_mode == .Dynamic) { ++ if (self.base.options.libc_installation) |libc_installation| { ++ try argv.append("-rpath"); ++ try argv.append(libc_installation.crt_dir.?); ++ } ++ } + } + + for (self.base.options.lib_dirs) |lib_dir| { +-- +2.46.0 + diff --git a/gnu/packages/patches/zig-0.11-use-system-paths.patch b/gnu/packages/patches/zig-0.11-use-system-paths.patch new file mode 100644 index 0000000000..0eeaffe539 --- /dev/null +++ b/gnu/packages/patches/zig-0.11-use-system-paths.patch @@ -0,0 +1,133 @@ +From 8b76c88e577fcd6a054ecfee333b2989ec94a3cc 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 | 53 +++++++++++++++++++++++++ + lib/std/zig/system/NativeTargetInfo.zig | 25 ++++++++++-- + src/main.zig | 3 +- + 3 files changed, 76 insertions(+), 5 deletions(-) + +diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig +index 4c8f1286b8..5b4805f6c6 100644 +--- a/lib/std/zig/system/NativePaths.zig ++++ b/lib/std/zig/system/NativePaths.zig +@@ -17,6 +17,51 @@ warnings: std.ArrayListUnmanaged([]const u8) = .{}, + pub fn detect(arena: Allocator, native_info: NativeTargetInfo) !NativePaths { + const native_target = native_info.target; + 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.InvalidUtf8 => {}, ++ 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.InvalidUtf8 => {}, ++ 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.InvalidUtf8 => {}, ++ 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.InvalidUtf8 => {}, ++ 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; +@@ -196,3 +241,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/lib/std/zig/system/NativeTargetInfo.zig b/lib/std/zig/system/NativeTargetInfo.zig +index 99a1a8f2ef..50d0d9949c 100644 +--- a/lib/std/zig/system/NativeTargetInfo.zig ++++ b/lib/std/zig/system/NativeTargetInfo.zig +@@ -923,10 +923,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.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 cross_target.dynamic_linker, + }; + } + +diff --git a/src/main.zig b/src/main.zig +index 456886c915..e2a97bf244 100644 +--- a/src/main.zig ++++ b/src/main.zig +@@ -2674,7 +2674,8 @@ fn buildOutputType( + // After this point, external_system_libs is used instead of system_libs. + + // Trigger native system library path detection if necessary. +- if (sysroot == null and cross_target.isNativeOs() and cross_target.isNativeAbi() and ++ if (std.zig.system.NativePaths.isCrossGuix(arena) or ++ sysroot == null and cross_target.isNativeOs() and cross_target.isNativeAbi() and + (external_system_libs.len != 0 or want_native_include_dirs)) + { + const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| { +-- +2.46.0 + |