aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHilton Chain <hako@ultrarare.space>2024-11-13 21:29:54 +0800
committerHilton Chain <hako@ultrarare.space>2024-12-31 10:54:05 +0800
commitcf74ecc94782bf3dc5588dc8988f39d34d3fa238 (patch)
tree8c5dfee4c2ce483b1e823d8249bda7c2396c84d3
parentfa0e38cbaec13d84d34505f9e01d14345e653a08 (diff)
downloadguix-cf74ecc94782bf3dc5588dc8988f39d34d3fa238.tar.gz
guix-cf74ecc94782bf3dc5588dc8988f39d34d3fa238.zip
gnu: zig-0.9: Update patches.
* gnu/packages/patches/zig-0.9-fix-runpath.patch: New file. * gnu/packages/patches/zig-use-baseline-cpu-by-default.patch: Rename to... * gnu/packages/patches/zig-0.9-use-baseline-cpu-by-default.patch: ...this. * gnu/packages/patches/zig-use-system-paths.patch: Rename to... * gnu/packages/patches/zig-0.9-use-system-paths.patch: ...this and update. * gnu/local.mk (dist_patch_DATA): Adjust accordingly. * gnu/packages/zig.scm (zig-0.9-glibc-abi-tool,zig-0.10-glibc-abi-tool): New variables. (zig-0.9)[source]: Use zig-source. Add patches. [arguments]<#:phases>: Generate and install abilists. [native-inputs]: Add zig-0.9-glibc-abi-tool. (zig-0.10)[source]<patches>: Adjust patch name. [native-inputs]: Replace zig-0.9-glibc-abi-tool with zig-0.10-glibc-abi-tool.
-rw-r--r--gnu/local.mk5
-rw-r--r--gnu/packages/patches/zig-0.9-fix-runpath.patch27
-rw-r--r--gnu/packages/patches/zig-0.9-use-baseline-cpu-by-default.patch (renamed from gnu/packages/patches/zig-use-baseline-cpu-by-default.patch)0
-rw-r--r--gnu/packages/patches/zig-0.9-use-system-paths.patch136
-rw-r--r--gnu/packages/patches/zig-use-system-paths.patch148
-rw-r--r--gnu/packages/zig.scm66
6 files changed, 220 insertions, 162 deletions
diff --git a/gnu/local.mk b/gnu/local.mk
index 838c2a06b3..8ee7218d9d 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2413,9 +2413,10 @@ dist_patch_DATA = \
%D%/packages/patches/xygrib-fix-finding-data.patch \
%D%/packages/patches/xygrib-newer-proj.patch \
%D%/packages/patches/yggdrasil-extra-config.patch \
+ %D%/packages/patches/zig-0.9-fix-runpath.patch \
%D%/packages/patches/zig-0.9-riscv-support.patch \
- %D%/packages/patches/zig-use-baseline-cpu-by-default.patch \
- %D%/packages/patches/zig-use-system-paths.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/zsh-egrep-failing-test.patch \
%D%/packages/patches/zuo-bin-sh.patch
diff --git a/gnu/packages/patches/zig-0.9-fix-runpath.patch b/gnu/packages/patches/zig-0.9-fix-runpath.patch
new file mode 100644
index 0000000000..65677f6b06
--- /dev/null
+++ b/gnu/packages/patches/zig-0.9-fix-runpath.patch
@@ -0,0 +1,27 @@
+From 97d6b38ee78941b96bfd30dc2c814fd9c38561e3 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 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/Compilation.zig b/src/Compilation.zig
+index b44c7da78d..be28538e6a 100644
+--- a/src/Compilation.zig
++++ b/src/Compilation.zig
+@@ -1515,7 +1515,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,
+ .disable_lld_caching = options.disable_lld_caching,
+ .subsystem = options.subsystem,
+ .is_test = options.is_test,
+--
+2.46.0
+
diff --git a/gnu/packages/patches/zig-use-baseline-cpu-by-default.patch b/gnu/packages/patches/zig-0.9-use-baseline-cpu-by-default.patch
index be78d9c6c7..be78d9c6c7 100644
--- a/gnu/packages/patches/zig-use-baseline-cpu-by-default.patch
+++ b/gnu/packages/patches/zig-0.9-use-baseline-cpu-by-default.patch
diff --git a/gnu/packages/patches/zig-0.9-use-system-paths.patch b/gnu/packages/patches/zig-0.9-use-system-paths.patch
new file mode 100644
index 0000000000..81799aa5ee
--- /dev/null
+++ b/gnu/packages/patches/zig-0.9-use-system-paths.patch
@@ -0,0 +1,136 @@
+From 751da768de9b58126fef8f69c70eea5c4180f739 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 | 56 ++++++++++++++++++++++++-
+ lib/std/zig/system/NativeTargetInfo.zig | 25 +++++++++--
+ src/main.zig | 3 +-
+ 3 files changed, 78 insertions(+), 6 deletions(-)
+
+diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig
+index 8e3e46e481..bb6ac32da6 100644
+--- a/lib/std/zig/system/NativePaths.zig
++++ b/lib/std/zig/system/NativePaths.zig
+@@ -25,7 +25,53 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths
+ .warnings = ArrayList([:0]u8).init(allocator),
+ };
+ errdefer self.deinit();
+-
++ if (isGuix(allocator)) {
++ const guix_cross_include_paths = [_][]const u8{ "CROSS_C_INCLUDE_PATH", "CROSS_CPLUS_INCLUDE_PATH" };
++ for (guix_cross_include_paths) |env_var| {
++ if (process.getEnvVarOwned(allocator, env_var)) |include_path| {
++ var it = mem.tokenize(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(allocator, "CROSS_LIBRARY_PATH")) |library_path| {
++ var it = mem.tokenize(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(allocator)) {
++ const guix_include_paths = [_][]const u8{ "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH" };
++ for (guix_include_paths) |env_var| {
++ if (process.getEnvVarOwned(allocator, env_var)) |include_path| {
++ var it = mem.tokenize(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(allocator, "LIBRARY_PATH")) |library_path| {
++ var it = mem.tokenize(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(allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
+ defer allocator.free(nix_cflags_compile);
+@@ -203,3 +249,11 @@ 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;
++}
+diff --git a/lib/std/zig/system/NativeTargetInfo.zig b/lib/std/zig/system/NativeTargetInfo.zig
+index af41fc7905..4ee5ee0b6e 100644
+--- a/lib/std/zig/system/NativeTargetInfo.zig
++++ b/lib/std/zig/system/NativeTargetInfo.zig
+@@ -784,10 +784,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.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 42daa95d3a..1ab9d0f7aa 100644
+--- a/src/main.zig
++++ b/src/main.zig
+@@ -2039,7 +2039,8 @@ fn buildOutputType(
+ want_native_include_dirs = true;
+ }
+
+- if (sysroot == null and cross_target.isNativeOs() and (system_libs.count() != 0 or want_native_include_dirs)) {
++ 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| {
+ fatal("unable to detect native system paths: {s}", .{@errorName(err)});
+ };
+--
+2.46.0
+
diff --git a/gnu/packages/patches/zig-use-system-paths.patch b/gnu/packages/patches/zig-use-system-paths.patch
deleted file mode 100644
index a008beafc2..0000000000
--- a/gnu/packages/patches/zig-use-system-paths.patch
+++ /dev/null
@@ -1,148 +0,0 @@
-This patch replaces the OS-specific detection mechanism by one that solely
-relies on environment variables. This has the benefit that said environment
-variables can be used as search paths in Guix.
-
-diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig
-index 8e3e46e48..1ed9d3206 100644
---- a/lib/std/zig/system/NativePaths.zig
-+++ b/lib/std/zig/system/NativePaths.zig
-@@ -26,73 +26,42 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths
- };
- errdefer self.deinit();
-
-- var is_nix = false;
-- if (process.getEnvVarOwned(allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
-- defer allocator.free(nix_cflags_compile);
--
-- is_nix = true;
-- var it = mem.tokenize(u8, nix_cflags_compile, " ");
-+ // TODO: Support cross-compile paths?
-+ if (process.getEnvVarOwned(allocator, "C_INCLUDE_PATH")) |c_include_path| {
-+ defer allocator.free(c_include_path);
-+ var it = mem.tokenize(u8, c_include_path, ":");
- while (true) {
-- const word = it.next() orelse break;
-- if (mem.eql(u8, word, "-isystem")) {
-- const include_path = it.next() orelse {
-- try self.addWarning("Expected argument after -isystem in NIX_CFLAGS_COMPILE");
-- break;
-- };
-- try self.addIncludeDir(include_path);
-- } else {
-- if (mem.startsWith(u8, word, "-frandom-seed=")) {
-- continue;
-- }
-- try self.addWarningFmt("Unrecognized C flag from NIX_CFLAGS_COMPILE: {s}", .{word});
-- }
-+ const dir = it.next() orelse break;
-+ try self.addIncludeDir(dir);
- }
- } else |err| switch (err) {
- error.InvalidUtf8 => {},
- error.EnvironmentVariableNotFound => {},
- error.OutOfMemory => |e| return e,
- }
-- if (process.getEnvVarOwned(allocator, "NIX_LDFLAGS")) |nix_ldflags| {
-- defer allocator.free(nix_ldflags);
--
-- is_nix = true;
-- var it = mem.tokenize(u8, nix_ldflags, " ");
-+ if (process.getEnvVarOwned(allocator, "CPLUS_INCLUDE_PATH")) |cplus_include_path| {
-+ defer allocator.free(cplus_include_path);
-+ var it = mem.tokenize(u8, cplus_include_path, ":");
- while (true) {
-- const word = it.next() orelse break;
-- if (mem.eql(u8, word, "-rpath")) {
-- const rpath = it.next() orelse {
-- try self.addWarning("Expected argument after -rpath in NIX_LDFLAGS");
-- break;
-- };
-- try self.addRPath(rpath);
-- } else if (word.len > 2 and word[0] == '-' and word[1] == 'L') {
-- const lib_path = word[2..];
-- try self.addLibDir(lib_path);
-- } else {
-- try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word});
-- break;
-- }
-+ const dir = it.next() orelse break;
-+ try self.addIncludeDir(dir);
- }
- } else |err| switch (err) {
- error.InvalidUtf8 => {},
- error.EnvironmentVariableNotFound => {},
- error.OutOfMemory => |e| return e,
- }
-- if (is_nix) {
-- return self;
-- }
--
-- if (comptime builtin.target.isDarwin()) {
-- try self.addIncludeDir("/usr/include");
-- try self.addIncludeDir("/usr/local/include");
--
-- try self.addLibDir("/usr/lib");
-- try self.addLibDir("/usr/local/lib");
--
-- try self.addFrameworkDir("/Library/Frameworks");
-- try self.addFrameworkDir("/System/Library/Frameworks");
--
-- return self;
-+ if (process.getEnvVarOwned(allocator, "LIBRARY_PATH")) |library_path| {
-+ defer allocator.free(library_path);
-+ var it = mem.tokenize(u8, library_path, ":");
-+ while (true) {
-+ const dir = it.next() orelse break;
-+ try self.addLibDir(dir);
-+ }
-+ } else |err| switch (err) {
-+ error.InvalidUtf8 => {},
-+ error.EnvironmentVariableNotFound => {},
-+ error.OutOfMemory => |e| return e,
- }
-
- if (comptime native_target.os.tag == .solaris) {
-@@ -106,32 +75,17 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths
- return self;
- }
-
-- if (native_target.os.tag != .windows) {
-- const triple = try native_target.linuxTriple(allocator);
-- const qual = native_target.cpu.arch.ptrBitWidth();
--
-- // TODO: $ ld --verbose | grep SEARCH_DIR
-- // the output contains some paths that end with lib64, maybe include them too?
-- // TODO: what is the best possible order of things?
-- // TODO: some of these are suspect and should only be added on some systems. audit needed.
--
-- try self.addIncludeDir("/usr/local/include");
-- try self.addLibDirFmt("/usr/local/lib{d}", .{qual});
-- try self.addLibDir("/usr/local/lib");
--
-- try self.addIncludeDirFmt("/usr/include/{s}", .{triple});
-- try self.addLibDirFmt("/usr/lib/{s}", .{triple});
--
-- try self.addIncludeDir("/usr/include");
-- try self.addLibDirFmt("/lib{d}", .{qual});
-- try self.addLibDir("/lib");
-- try self.addLibDirFmt("/usr/lib{d}", .{qual});
-- try self.addLibDir("/usr/lib");
--
-- // example: on a 64-bit debian-based linux distro, with zlib installed from apt:
-- // zlib.h is in /usr/include (added above)
-- // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
-- try self.addLibDirFmt("/lib/{s}", .{triple});
-+ if (process.getEnvVarOwned(allocator, "DYLD_FRAMEWORK_PATH")) |dyld_framework_path| {
-+ defer allocator.free(dyld_framework_path);
-+ var it = mem.tokenize(u8, dyld_framework_path, ":");
-+ while (true) {
-+ const dir = it.next() orelse break;
-+ try self.addFrameworkDir(dir);
-+ }
-+ } else |err| switch (err) {
-+ error.InvalidUtf8 => {},
-+ error.EnvironmentVariableNotFound => {},
-+ error.OutOfMemory => |e| return e,
- }
-
- return self;
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
index ea06bd7c69..3942938fc2 100644
--- a/gnu/packages/zig.scm
+++ b/gnu/packages/zig.scm
@@ -3,6 +3,7 @@
;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
;;; Copyright © 2021 Calum Irwin <calumirwin1@gmail.com>
;;; Copyright © 2022, 2023 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2023, 2024 Hilton Chain <hako@ultrarare.space>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -55,21 +56,31 @@
;; IETF RFC documents have nonfree license.
(find-files "." "^rfc[0-9]+\\.txt"))))))
+(define zig-0.9-glibc-abi-tool
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/ziglang/glibc-abi-tool")
+ (commit "6f992064f821c612f68806422b2780c9260cbc4c")))
+ (file-name "glibc-abi-tool")
+ (sha256
+ (base32 "0lsi3f2lkixcdidljby73by2sypywb813yqdapy9md4bi2h8hhgp"))))
+
(define-public zig-0.9
(package
(name "zig")
(version "0.9.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 "0nfvgg23sw50ksy0z0ml6lkdsvmd0278mq29m23dbb2jsirkhry7"))
- (patches (search-patches "zig-0.9-riscv-support.patch"
- "zig-use-system-paths.patch"))))
+ (inherit (zig-source
+ version version
+ "0nfvgg23sw50ksy0z0ml6lkdsvmd0278mq29m23dbb2jsirkhry7"))
+ (patches
+ (search-patches
+ "zig-0.9-riscv-support.patch"
+ "zig-0.9-use-baseline-cpu-by-default.patch"
+ "zig-0.9-use-system-paths.patch"
+ "zig-0.9-fix-runpath.patch"))))
(build-system cmake-build-system)
(arguments
(list
@@ -119,13 +130,28 @@
"-Dskip-stage2-tests"
;; Non-native tests try to link and execute non-native
;; binaries.
- "-Dskip-non-native")))))))
+ "-Dskip-non-native"))))
+ (add-before 'check 'install-glibc-abilists
+ (lambda* (#:key inputs native-inputs #:allow-other-keys)
+ (mkdir-p "/tmp/glibc-abi-tool")
+ (with-directory-excursion "/tmp/glibc-abi-tool"
+ (copy-recursively
+ (dirname (search-input-file
+ (or native-inputs inputs) "consolidate.zig"))
+ ".")
+ (for-each make-file-writable (find-files "."))
+ (invoke (string-append #$output "/bin/zig")
+ "run" "consolidate.zig")
+ (install-file
+ "abilists"
+ (string-append #$output "/lib/zig/libc/glibc"))))))))
(inputs
(list clang-13 ;Clang propagates llvm.
lld-13))
;; Zig compiles fine with GCC, but also needs native LLVM libraries.
(native-inputs
- (list llvm-13))
+ (list llvm-13
+ zig-0.9-glibc-abi-tool))
(native-search-paths
(list
(search-path-specification
@@ -157,6 +183,21 @@ toolchain. Among other features it provides
,@(clang-compiler-cpu-architectures "13")))
(license license:expat)))
+(define zig-0.10-glibc-abi-tool
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/ziglang/glibc-abi-tool")
+ (commit "b07bf67ab3c15881f13b9c3c03bcec04535760bb")))
+ (file-name "glibc-abi-tool")
+ (sha256
+ (base32 "0csn3c9pj8wchwy5sk5lfnhjn8a3c8cp45fv7mkpi5bqxzdzf1na"))
+ (modules '((guix build utils)))
+ (snippet
+ #~(substitute* "consolidate.zig"
+ (("(@ctz.)u.., " _ prefix) prefix)
+ (("(@popCount.)u.., " _ prefix) prefix)))))
+
(define-public zig-0.10
(package
(inherit zig-0.9)
@@ -171,7 +212,7 @@ toolchain. Among other features it provides
(file-name (git-file-name name version))
(sha256
(base32 "1sh5xjsksl52i4cfv1qj36sz5h0ln7cq4pdhgs3960mk8a90im7b"))
- (patches (search-patches "zig-use-baseline-cpu-by-default.patch"))))
+ (patches (search-patches "zig-0.9-use-baseline-cpu-by-default.patch"))))
(arguments
(substitute-keyword-arguments (package-arguments zig-0.9)
((#:configure-flags flags ''())
@@ -216,6 +257,7 @@ toolchain. Among other features it provides
(replace "lld" lld-15)))
(native-inputs
(modify-inputs (package-native-inputs zig-0.9)
+ (replace "glibc-abi-tool" zig-0.10-glibc-abi-tool)
(replace "llvm" llvm-15)))
(properties `((max-silent-time . 9600)
,@(clang-compiler-cpu-architectures "15")))))