[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
03/72: gnu: zig-0.10: Fix RUNPATH issue.
From: |
guix-commits |
Subject: |
03/72: gnu: zig-0.10: Fix RUNPATH issue. |
Date: |
Thu, 21 Nov 2024 07:19:42 -0500 (EST) |
hako pushed a commit to branch wip-zig-bootstrap
in repository guix.
commit 64ab40662af7c2763444d8f7eea65d91feb57efc
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 | 47 ++++++++
.../patches/zig-0.10-use-system-paths.patch | 131 +++++++++++++++++++++
gnu/packages/zig.scm | 24 ++--
4 files changed, 191 insertions(+), 13 deletions(-)
diff --git a/gnu/local.mk b/gnu/local.mk
index 291ad225cd..118a7a89ac 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2370,6 +2370,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..9ad1e73a90
--- /dev/null
+++ b/gnu/packages/patches/zig-0.10-fix-runpath.patch
@@ -0,0 +1,47 @@
+From cf2f6ca541c8295b5edd5f6836c98f120113c0d4 Mon Sep 17 00:00:00 2001
+From: Hilton Chain <hako@ultrarare.space>
+Date: Thu, 14 Nov 2024 14:13:02 +0800
+Subject: [PATCH 3/5] Fix RUNPATH issue.
+
+Add needed libraries and libc to RUNPATH when CROSS_LIBRARY_PATH or
LIBRARY_PATH
+is set.
+---
+ src/Compilation.zig | 4 +++-
+ src/link/Elf.zig | 6 ++++++
+ 2 files changed, 9 insertions(+), 1 deletion(-)
+
+diff --git a/src/Compilation.zig b/src/Compilation.zig
+index 3ddf936e57..54fcc9efb4 100644
+--- a/src/Compilation.zig
++++ b/src/Compilation.zig
+@@ -1886,7 +1886,9 @@ 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.process.hasEnvVar(gpa,
"CROSS_LIBRARY_PATH") catch false or
++ std.process.hasEnvVar(gpa, "LIBRARY_PATH") catch false 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..20556b70da
--- /dev/null
+++ b/gnu/packages/patches/zig-0.10-use-system-paths.patch
@@ -0,0 +1,131 @@
+From 3ff50f4830b26b48e2b0fc394275d186ab4dbf5b Mon Sep 17 00:00:00 2001
+From: Hilton Chain <hako@ultrarare.space>
+Date: Wed, 13 Nov 2024 12:46:31 +0800
+Subject: [PATCH] Use system paths.
+
+Prefer Guix search paths and support Guix cross builds.
+---
+ lib/std/zig/system/NativePaths.zig | 51 +++++++++++++++++++++++++
+ lib/std/zig/system/NativeTargetInfo.zig | 29 ++++++++++++--
+ src/main.zig | 3 +-
+ 3 files changed, 78 insertions(+), 5 deletions(-)
+
+diff --git a/lib/std/zig/system/NativePaths.zig
b/lib/std/zig/system/NativePaths.zig
+index 2c4db3ec85..6c38376b3d 100644
+--- a/lib/std/zig/system/NativePaths.zig
++++ b/lib/std/zig/system/NativePaths.zig
+@@ -25,6 +25,57 @@ pub fn detect(allocator: Allocator, native_info:
NativeTargetInfo) !NativePaths
+ .warnings = ArrayList([:0]u8).init(allocator),
+ };
+ errdefer self.deinit();
++ const getenv_available = !(builtin.os.tag == .windows or (builtin.os.tag
== .wasi and !builtin.link_libc));
++ var is_guix = false;
++ var is_cross_guix = false;
++ if (getenv_available) {
++ if (std.os.getenv("CROSS_C_INCLUDE_PATH")) |c_include_path| {
++ is_cross_guix = true;
++ var it = mem.tokenize(u8, c_include_path, ":");
++ while (it.next()) |dir| {
++ try self.addIncludeDir(dir);
++ }
++ }
++ if (std.os.getenv("CROSS_CPLUS_INCLUDE_PATH")) |cplus_include_path| {
++ is_cross_guix = true;
++ var it = mem.tokenize(u8, cplus_include_path, ":");
++ while (it.next()) |dir| {
++ try self.addIncludeDir(dir);
++ }
++ }
++ if (std.os.getenv("CROSS_LIBRARY_PATH")) |library_path| {
++ is_cross_guix = true;
++ var it = mem.tokenize(u8, library_path, ":");
++ while (it.next()) |dir| {
++ try self.addLibDir(dir);
++ }
++ }
++ if (!is_cross_guix) {
++ if (std.os.getenv("C_INCLUDE_PATH")) |c_include_path| {
++ is_guix = true;
++ var it = mem.tokenize(u8, c_include_path, ":");
++ while (it.next()) |dir| {
++ try self.addIncludeDir(dir);
++ }
++ }
++ if (std.os.getenv("CPLUS_INCLUDE_PATH")) |cplus_include_path| {
++ is_guix = true;
++ var it = mem.tokenize(u8, cplus_include_path, ":");
++ while (it.next()) |dir| {
++ try self.addIncludeDir(dir);
++ }
++ }
++ if (std.os.getenv("LIBRARY_PATH")) |library_path| {
++ var it = mem.tokenize(u8, library_path, ":");
++ while (it.next()) |dir| {
++ try self.addLibDir(dir);
++ }
++ }
++ }
++ }
++ if (is_guix or is_cross_guix) {
++ return self;
++ }
+
+ var is_nix = false;
+ if (process.getEnvVarOwned(allocator, "NIX_CFLAGS_COMPILE"))
|nix_cflags_compile| {
+diff --git a/lib/std/zig/system/NativeTargetInfo.zig
b/lib/std/zig/system/NativeTargetInfo.zig
+index cae45af64b..b4b210f6b7 100644
+--- a/lib/std/zig/system/NativeTargetInfo.zig
++++ b/lib/std/zig/system/NativeTargetInfo.zig
+@@ -936,10 +936,31 @@ 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 = blk: {
++ if (cross_target.dynamic_linker.get() == null) {
++ var standard_linker = target.standardDynamicLinkerPath();
++ const standard_linker_path = standard_linker.get() orelse "";
++ const getenv_available = !(builtin.os.tag == .windows or
(builtin.os.tag == .wasi and !builtin.link_libc));
++ if (standard_linker_path.len != 0 and getenv_available) {
++ 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}", .{ dir, 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 {
++ break :blk cross_target.dynamic_linker;
++ }
++ },
+ };
+ }
+
+diff --git a/src/main.zig b/src/main.zig
+index b752c89308..be93c9d00f 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.process.hasEnvVar(arena, "CROSS_LIBRARY_PATH") catch false 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 8b7c290500..03962dea95 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.10-fix-runpath.patch"
+ "zig-0.9-use-baseline-cpu-by-default.patch"
+ "zig-0.10-use-system-paths.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?
- 02/72: gnu: zig-0.9: Update patches., (continued)
- 02/72: gnu: zig-0.9: Update patches., guix-commits, 2024/11/21
- 11/72: gnu: Add zig-0.10.0-853., guix-commits, 2024/11/21
- 10/72: gnu: Add zig-0.10.0-851., guix-commits, 2024/11/21
- 06/72: gnu: Add zig-0.10.0-675., guix-commits, 2024/11/21
- 07/72: gnu: Add zig-0.10.0-722., guix-commits, 2024/11/21
- 09/72: gnu: Add zig-0.10.0-748., guix-commits, 2024/11/21
- 16/72: gnu: Add zig-0.10.0-1497., guix-commits, 2024/11/21
- 20/72: gnu: Add zig-0.10.0-1681., guix-commits, 2024/11/21
- 22/72: gnu: Add zig-0.10.0-1713., guix-commits, 2024/11/21
- 26/72: gnu: Add zig-0.10.0-2566., guix-commits, 2024/11/21
- 03/72: gnu: zig-0.10: Fix RUNPATH issue.,
guix-commits <=
- 05/72: gnu: Add zig-0.10.0-610., guix-commits, 2024/11/21
- 15/72: gnu: Add zig-0.10.0-1073., guix-commits, 2024/11/21
- 08/72: gnu: Add zig-0.10.0-747., guix-commits, 2024/11/21
- 27/72: gnu: Add zig-0.10.0-2571., guix-commits, 2024/11/21
- 37/72: gnu: Add zig-0.11., guix-commits, 2024/11/21
- 40/72: gnu: Add zig-0.11.0-494., guix-commits, 2024/11/21
- 46/72: gnu: Add zig-0.11.0-1967., guix-commits, 2024/11/21
- 21/72: gnu: Add zig-0.10.0-1712., guix-commits, 2024/11/21
- 29/72: gnu: Add zig-0.10.0-2838., guix-commits, 2024/11/21
- 33/72: gnu: Add zig-0.10.0-3807., guix-commits, 2024/11/21