[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
03/73: gnu: zig-0.10: Fix RUNPATH issue.
From: |
guix-commits |
Subject: |
03/73: gnu: zig-0.10: Fix RUNPATH issue. |
Date: |
Thu, 28 Nov 2024 05:50:04 -0500 (EST) |
hako pushed a commit to branch wip-zig-bootstrap
in repository guix.
commit 8ddf525650a4d3baf17006f5a9553157fa07c6fe
Author: Hilton Chain <hako@ultrarare.space>
AuthorDate: Tue Nov 12 17:37:33 2024 +0800
gnu: zig-0.10: Fix RUNPATH issue.
* 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
---
gnu/local.mk | 2 +
gnu/packages/patches/zig-0.10-fix-runpath.patch | 45 +++++++
.../patches/zig-0.10-use-system-paths.patch | 140 +++++++++++++++++++++
gnu/packages/zig.scm | 24 ++--
4 files changed, 198 insertions(+), 13 deletions(-)
diff --git a/gnu/local.mk b/gnu/local.mk
index 116e9c8b48..1193447348 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2367,6 +2367,8 @@ dist_patch_DATA =
\
%D%/packages/patches/zig-0.9-riscv-support.patch \
%D%/packages/patches/zig-0.9-use-baseline-cpu-by-default.patch \
%D%/packages/patches/zig-0.9-use-system-paths.patch \
+ %D%/packages/patches/zig-0.10-fix-runpath.patch \
+ %D%/packages/patches/zig-0.10-use-system-paths.patch \
%D%/packages/patches/zsh-egrep-failing-test.patch \
%D%/packages/patches/zuo-bin-sh.patch
diff --git a/gnu/packages/patches/zig-0.10-fix-runpath.patch
b/gnu/packages/patches/zig-0.10-fix-runpath.patch
new file mode 100644
index 0000000000..59b7975717
--- /dev/null
+++ b/gnu/packages/patches/zig-0.10-fix-runpath.patch
@@ -0,0 +1,45 @@
+From b8678a24d96c4a94d7309ea56bd35bae41fbbeae 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 3ddf936e57..138df1f913 100644
+--- a/src/Compilation.zig
++++ b/src/Compilation.zig
+@@ -1886,7 +1886,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
options.is_native_os,
++ .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 2663f90aee..8813aea827 100644
+--- a/src/link/Elf.zig
++++ b/src/link/Elf.zig
+@@ -1620,6 +1620,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.10-use-system-paths.patch
b/gnu/packages/patches/zig-0.10-use-system-paths.patch
new file mode 100644
index 0000000000..49084819fb
--- /dev/null
+++ b/gnu/packages/patches/zig-0.10-use-system-paths.patch
@@ -0,0 +1,140 @@
+From dd729fc8d566617e3e342401480dcb4418885c5a 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 | 61 +++++++++++++++++++++++++
+ lib/std/zig/system/NativeTargetInfo.zig | 25 ++++++++--
+ src/main.zig | 2 +-
+ 3 files changed, 83 insertions(+), 5 deletions(-)
+
+diff --git a/lib/std/zig/system/NativePaths.zig
b/lib/std/zig/system/NativePaths.zig
+index 2c4db3ec85..83a6a20829 100644
+--- a/lib/std/zig/system/NativePaths.zig
++++ b/lib/std/zig/system/NativePaths.zig
+@@ -26,6 +26,10 @@ pub fn detect(allocator: Allocator, native_info:
NativeTargetInfo) !NativePaths
+ };
+ errdefer self.deinit();
+
++ if (isGuix(allocator)) {
++ try self.addGuixPaths(allocator);
++ return self;
++ }
+ var is_nix = false;
+ if (process.getEnvVarOwned(allocator, "NIX_CFLAGS_COMPILE"))
|nix_cflags_compile| {
+ defer allocator.free(nix_cflags_compile);
+@@ -231,3 +235,60 @@ 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;
++}
++
++const guix_paths = [_][]const u8{ "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH",
"LIBRARY_PATH" };
++const guix_cross_paths = [_][]const u8{ "CROSS_C_INCLUDE_PATH",
"CROSS_CPLUS_INCLUDE_PATH", "CROSS_LIBRARY_PATH" };
++
++fn addGuixPaths(self: *NativePaths, arena: Allocator) !void {
++ for (guix_cross_paths[0..2]) |env_var| {
++ if (process.getEnvVarOwned(arena, env_var)) |dirs| {
++ var it = mem.tokenize(u8, dirs, ":");
++ 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, guix_cross_paths[2])) |dirs| {
++ var it = mem.tokenize(u8, dirs, ":");
++ while (it.next()) |dir|
++ try self.addLibDir(dir);
++ } else |err| switch (err) {
++ error.InvalidUtf8 => {},
++ error.EnvironmentVariableNotFound => {},
++ error.OutOfMemory => |e| return e,
++ }
++
++ if (!isCrossGuix(arena)) {
++ for (guix_paths[0..2]) |env_var| {
++ if (process.getEnvVarOwned(arena, env_var)) |dirs| {
++ var it = mem.tokenize(u8, dirs, ":");
++ 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, guix_paths[2])) |dirs| {
++ var it = mem.tokenize(u8, dirs, ":");
++ while (it.next()) |dir|
++ try self.addLibDir(dir);
++ } else |err| switch (err) {
++ error.InvalidUtf8 => {},
++ error.EnvironmentVariableNotFound => {},
++ error.OutOfMemory => |e| return e,
++ }
++ }
++}
+diff --git a/lib/std/zig/system/NativeTargetInfo.zig
b/lib/std/zig/system/NativeTargetInfo.zig
+index cae45af64b..e5afa5329f 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 or (builtin.os.tag == .wasi
and !builtin.link_libc))) {
++ 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..32249eb687 100644
+--- a/src/main.zig
++++ b/src/main.zig
+@@ -2375,7 +2375,7 @@ 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
+
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
index 1036d60f0c..6c7cf75fd4 100644
--- a/gnu/packages/zig.scm
+++ b/gnu/packages/zig.scm
@@ -160,14 +160,14 @@ toolchain. Among other features it provides
(version "0.10.1")
(source
(origin
- (method git-fetch)
- (uri (git-reference
- (url "https://github.com/ziglang/zig.git")
- (commit version)))
- (file-name (git-file-name name version))
- (sha256
- (base32 "1sh5xjsksl52i4cfv1qj36sz5h0ln7cq4pdhgs3960mk8a90im7b"))
- (patches (search-patches "zig-0.9-use-baseline-cpu-by-default.patch"))))
+ (inherit (zig-source
+ version version
+ "1sh5xjsksl52i4cfv1qj36sz5h0ln7cq4pdhgs3960mk8a90im7b"))
+ (patches
+ (search-patches
+ "zig-0.9-use-baseline-cpu-by-default.patch"
+ "zig-0.10-use-system-paths.patch"
+ "zig-0.10-fix-runpath.patch"))))
(arguments
(substitute-keyword-arguments (package-arguments zig-0.9)
((#:configure-flags flags ''())
@@ -175,8 +175,6 @@ toolchain. Among other features it provides
"-DZIG_SHARED_LLVM=ON"
(string-append "-DZIG_LIB_DIR=" #$output "/lib/zig")
#$flags))
- ;; TODO: zig binary can't find ld-linux.
- ((#:validate-runpath? _ #t) #f)
((#:tests? _ #t) #t)
((#:phases phases '%standard-phases)
#~(modify-phases #$phases
@@ -190,10 +188,10 @@ toolchain. Among other features it provides
(setenv "CC" #$(cc-for-target))))
(add-after 'patch-source-shebangs 'patch-more-shebangs
(lambda* (#:key inputs #:allow-other-keys)
- ;; Zig uses information about /usr/bin/env to determine the
- ;; version of glibc and other data.
+ ;; Zig uses information about an ELF file to determine the
+ ;; version of glibc and other data for native builds.
(substitute* "lib/std/zig/system/NativeTargetInfo.zig"
- (("/usr/bin/env") (search-input-file inputs "/bin/env")))))
+ (("/usr/bin/env") (search-input-file inputs
"bin/clang++")))))
(replace 'check
(lambda* (#:key tests? #:allow-other-keys)
(when tests?
- branch wip-zig-bootstrap created (now aa3960c15e), guix-commits, 2024/11/28
- 28/73: gnu: Add zig-0.10.0-2797., guix-commits, 2024/11/28
- 27/73: gnu: Add zig-0.10.0-2571., guix-commits, 2024/11/28
- 03/73: gnu: zig-0.10: Fix RUNPATH issue.,
guix-commits <=
- 01/73: gnu: zig: Add 'zig-source' procedure., guix-commits, 2024/11/28
- 26/73: gnu: Add zig-0.10.0-2566., guix-commits, 2024/11/28
- 09/73: gnu: Add zig-0.10.0-748., guix-commits, 2024/11/28
- 40/73: gnu: Add zig-0.11.0-494., guix-commits, 2024/11/28
- 38/73: gnu: Add zig-0.11.0-149., guix-commits, 2024/11/28
- 58/73: build/zig: Adjust the build triplets for some systems., guix-commits, 2024/11/28
- 21/73: gnu: Add zig-0.10.0-1712., guix-commits, 2024/11/28
- 63/73: gnu: Add zig-pixman., guix-commits, 2024/11/28
- 50/73: gnu: Add zig-0.11.0-3503., guix-commits, 2024/11/28
- 14/73: gnu: Add zig-0.10.0-1027., guix-commits, 2024/11/28