summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorHilton Chain <hako@ultrarare.space>2024-12-31 21:15:46 +0800
committerHilton Chain <hako@ultrarare.space>2025-03-05 16:58:41 +0800
commita69a33645183fa3d55d54fe1534a9bb2a33a24a4 (patch)
tree295830d6bac213e9e931cbf1d44d5b214e170f3e /gnu
parent37cb2814bbf64c727a2454e1a55102ba490c312b (diff)
gnu: Add zig-0.14.
* gnu/packages/patches/zig-0.14-fix-runpath.patch: New file. * gnu/packages/patches/zig-0.14-use-baseline-cpu-by-default.patch: New file. * gnu/packages/patches/zig-0.14-use-system-paths.patch: New file. * gnu/local.mk (dist_patch_DATA): Regisiter them. * gnu/packages/zig.scm (zig-0.14-glibc-abi-tool,zig-0.14): New variables. Change-Id: Ibb9e49ee451ca3bac58bd33a50a9f53e0aa31402
Diffstat (limited to 'gnu')
-rw-r--r--gnu/local.mk3
-rw-r--r--gnu/packages/patches/zig-0.14-fix-runpath.patch118
-rw-r--r--gnu/packages/patches/zig-0.14-use-baseline-cpu-by-default.patch36
-rw-r--r--gnu/packages/patches/zig-0.14-use-system-paths.patch133
-rw-r--r--gnu/packages/zig.scm37
5 files changed, 327 insertions, 0 deletions
diff --git a/gnu/local.mk b/gnu/local.mk
index a4ba6dd65a2..ac95c99cad0 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2460,6 +2460,9 @@ dist_patch_DATA = \
2460 %D%/packages/patches/zig-0.12-use-system-paths.patch \ 2460 %D%/packages/patches/zig-0.12-use-system-paths.patch \
2461 %D%/packages/patches/zig-0.13-build-respect-PKG_CONFIG-env-var.patch \ 2461 %D%/packages/patches/zig-0.13-build-respect-PKG_CONFIG-env-var.patch \
2462 %D%/packages/patches/zig-0.13-fix-runpath.patch \ 2462 %D%/packages/patches/zig-0.13-fix-runpath.patch \
2463 %D%/packages/patches/zig-0.14-fix-runpath.patch \
2464 %D%/packages/patches/zig-0.14-use-baseline-cpu-by-default.patch \
2465 %D%/packages/patches/zig-0.14-use-system-paths.patch \
2463 %D%/packages/patches/zsh-egrep-failing-test.patch \ 2466 %D%/packages/patches/zsh-egrep-failing-test.patch \
2464 %D%/packages/patches/zuo-bin-sh.patch 2467 %D%/packages/patches/zuo-bin-sh.patch
2465 2468
diff --git a/gnu/packages/patches/zig-0.14-fix-runpath.patch b/gnu/packages/patches/zig-0.14-fix-runpath.patch
new file mode 100644
index 00000000000..324544165e3
--- /dev/null
+++ b/gnu/packages/patches/zig-0.14-fix-runpath.patch
@@ -0,0 +1,118 @@
1From d5c31f6d99a3d02c8b0efba13e1a1e82e0e36f96 Mon Sep 17 00:00:00 2001
2From: Hilton Chain <hako@ultrarare.space>
3Date: Fri, 29 Nov 2024 14:13:46 +0800
4Subject: [PATCH] Fix RUNPATH issue.
5
6Add needed libraries and libc to RUNPATH when CROSS_LIBRARY_PATH or LIBRARY_PATH
7is set.
8---
9 lib/std/Build/Step/Compile.zig | 3 +++
10 src/link/Elf.zig | 14 ++++++++++++++
11 src/main.zig | 34 +++++++++++++++++++++++++++++++++-
12 3 files changed, 50 insertions(+), 1 deletion(-)
13
14diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig
15index 1dd444abf2..df7f4a56db 100644
16--- a/lib/std/Build/Step/Compile.zig
17+++ b/lib/std/Build/Step/Compile.zig
18@@ -778,6 +778,9 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
19 try zig_cflags.appendSlice(&[_][]const u8{ "-D", macro });
20 } else if (mem.startsWith(u8, arg, "-D")) {
21 try zig_cflags.append(arg);
22+ } else if (mem.startsWith(u8, arg, "-Wl,-rpath=")) {
23+ const dir = arg["-Wl,-rpath=".len..];
24+ try zig_libs.appendSlice(&[_][]const u8{ "-L", dir });
25 } else if (b.debug_pkg_config) {
26 return compile.step.fail("unknown pkg-config flag '{s}'", .{arg});
27 }
28diff --git a/src/link/Elf.zig b/src/link/Elf.zig
29index 608ff2fe3a..2b9fe803fd 100644
30--- a/src/link/Elf.zig
31+++ b/src/link/Elf.zig
32@@ -1037,6 +1037,13 @@ fn dumpArgvInit(self: *Elf, arena: Allocator) !void {
33 try argv.appendSlice(gpa, &.{ "-rpath", rpath });
34 }
35
36+ if (std.zig.system.NativePaths.isGuix(arena) and comp.config.link_libc and comp.config.link_mode == .dynamic) {
37+ if (self.base.comp.libc_installation) |libc_installation| {
38+ try argv.append(gpa, "-rpath");
39+ try argv.append(gpa, libc_installation.crt_dir.?);
40+ }
41+ }
42+
43 try argv.appendSlice(gpa, &.{
44 "-z",
45 try std.fmt.allocPrint(arena, "stack-size={d}", .{self.base.stack_size}),
46@@ -1857,6 +1864,13 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
47 try argv.appendSlice(&.{ "-rpath", rpath });
48 }
49
50+ if (std.zig.system.NativePaths.isGuix(arena) and comp.config.link_libc and link_mode == .dynamic) {
51+ if (self.base.comp.libc_installation) |libc_installation| {
52+ try argv.append("-rpath");
53+ try argv.append(libc_installation.crt_dir.?);
54+ }
55+ }
56+
57 for (self.symbol_wrap_set.keys()) |symbol_name| {
58 try argv.appendSlice(&.{ "-wrap", symbol_name });
59 }
60diff --git a/src/main.zig b/src/main.zig
61index 79493aa624..505bb7570a 100644
62--- a/src/main.zig
63+++ b/src/main.zig
64@@ -3901,7 +3901,7 @@ fn createModule(
65 create_module.want_native_include_dirs = true;
66 }
67
68- if (create_module.each_lib_rpath orelse resolved_target.is_native_os) {
69+ if (create_module.each_lib_rpath orelse false) {
70 try create_module.rpath_list.ensureUnusedCapacity(arena, create_module.lib_directories.items.len);
71 for (create_module.lib_directories.items) |lib_directory| {
72 create_module.rpath_list.appendAssumeCapacity(lib_directory.path.?);
73@@ -3976,6 +3976,28 @@ fn createModule(
74 else => {},
75 };
76
77+ if (std.zig.system.NativePaths.isGuix(arena)) {
78+ for (create_module.link_inputs.items) |link_input| {
79+ if (link_input.path()) |lib| {
80+ const lib_name = lib.sub_path;
81+ if (Compilation.classifyFileExt(lib_name) == .shared_library) {
82+ if (fs.path.isAbsolute(lib_name)) {
83+ const lib_dir_path = fs.path.dirname(lib_name).?;
84+ try create_module.rpath_list.append(arena, lib_dir_path);
85+ continue;
86+ }
87+ for (create_module.lib_directories.items) |lib_dir| {
88+ const lib_dir_path = lib_dir.path.?;
89+ if (try libPathExists(arena, lib_dir_path, lib_name)) {
90+ try create_module.rpath_list.append(arena, lib_dir_path);
91+ break;
92+ }
93+ }
94+ }
95+ }
96+ }
97+ }
98+
99 create_module.resolved_options = Compilation.Config.resolve(create_module.opts) catch |err| switch (err) {
100 error.WasiExecModelRequiresWasi => fatal("only WASI OS targets support execution model", .{}),
101 error.SharedMemoryIsWasmOnly => fatal("only WebAssembly CPU targets support shared memory", .{}),
102@@ -7495,3 +7517,13 @@ fn addLibDirectoryWarn2(
103 .path = path,
104 });
105 }
106+
107+fn libPathExists(arena: Allocator, lib_dir_path: []const u8, lib_name: []const u8) !bool {
108+ const lib_path = try std.fmt.allocPrint(arena, "{s}{s}{s}", .{
109+ lib_dir_path,
110+ fs.path.sep_str,
111+ lib_name,
112+ });
113+ fs.cwd().access(lib_path, .{}) catch return false;
114+ return true;
115+}
116--
1172.46.0
118
diff --git a/gnu/packages/patches/zig-0.14-use-baseline-cpu-by-default.patch b/gnu/packages/patches/zig-0.14-use-baseline-cpu-by-default.patch
new file mode 100644
index 00000000000..c4a6f64540b
--- /dev/null
+++ b/gnu/packages/patches/zig-0.14-use-baseline-cpu-by-default.patch
@@ -0,0 +1,36 @@
1From cd20f7d3088d2befb80d7940b587be0197bdc07b Mon Sep 17 00:00:00 2001
2From: Ekaitz Zarraga <ekaitz@elenq.tech>
3Date: Sat, 18 Nov 2023 15:04:16 +0100
4Subject: [PATCH] Use `baseline` cpu by default.
5
6This helps Guix tune the package later. Tunning will only add
7`-Dcpu=whatever` which should override the standard behaviour.
8
9Zig by default uses `native`, which interferes with our build process.
10In our previous zig-build-system we chose to add `-Dcpu=baseline` flag
11in each `zig build` execution, but that doesn't allow us to tune the
12package later. Tunning is only designed to add extra flags in the
13command line call, and we already had one set for the baseline case.
14With this patch we set the standard behavior to `baseline` so we don't
15need to add the `-Dcpu=baseline` flag in the zig-build-system and we can
16tune with no issues.
17---
18 lib/std/Target/Query.zig | 2 +-
19 1 file changed, 1 insertion(+), 1 deletion(-)
20
21diff --git a/lib/std/Target/Query.zig b/lib/std/Target/Query.zig
22index 56387c27b3..1c0f18f93d 100644
23--- a/lib/std/Target/Query.zig
24+++ b/lib/std/Target/Query.zig
25@@ -6,7 +6,7 @@
26 /// `null` means native.
27 cpu_arch: ?Target.Cpu.Arch = null,
28
29-cpu_model: CpuModel = .determined_by_arch_os,
30+cpu_model: CpuModel = .baseline,
31
32 /// Sparse set of CPU features to add to the set from `cpu_model`.
33 cpu_features_add: Target.Cpu.Feature.Set = .empty,
34--
352.47.1
36
diff --git a/gnu/packages/patches/zig-0.14-use-system-paths.patch b/gnu/packages/patches/zig-0.14-use-system-paths.patch
new file mode 100644
index 00000000000..5ece0c0cdd2
--- /dev/null
+++ b/gnu/packages/patches/zig-0.14-use-system-paths.patch
@@ -0,0 +1,133 @@
1From 813993ef425ba24e7a18d3cdf700c0589a333943 Mon Sep 17 00:00:00 2001
2From: Hilton Chain <hako@ultrarare.space>
3Date: Fri, 29 Nov 2024 14:13:30 +0800
4Subject: [PATCH] Use system paths.
5
6Prefer Guix search paths and support Guix cross builds.
7---
8 lib/std/zig/system.zig | 25 +++++++++++---
9 lib/std/zig/system/NativePaths.zig | 53 ++++++++++++++++++++++++++++++
10 src/main.zig | 3 +-
11 3 files changed, 76 insertions(+), 5 deletions(-)
12
13diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig
14index 48b195dc3e..b636c46656 100644
15--- a/lib/std/zig/system.zig
16+++ b/lib/std/zig/system.zig
17@@ -1176,10 +1176,27 @@ fn defaultAbiAndDynamicLinker(cpu: Target.Cpu, os: Target.Os, query: Target.Quer
18 .os = os,
19 .abi = abi,
20 .ofmt = query.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch),
21- .dynamic_linker = if (query.dynamic_linker.get() == null)
22- Target.DynamicLinker.standard(cpu, os, abi)
23- else
24- query.dynamic_linker,
25+ .dynamic_linker = if (query.dynamic_linker.get() == null) blk: {
26+ var standard_linker = Target.DynamicLinker.standard(cpu, os, abi);
27+ if (standard_linker.get()) |standard_linker_path| {
28+ if (builtin.os.tag != .windows and builtin.os.tag != .wasi) {
29+ if (posix.getenv("CROSS_LIBRARY_PATH") orelse posix.getenv("LIBRARY_PATH")) |library_path| {
30+ const linker_basename = fs.path.basename(standard_linker_path);
31+ var buffer: [255]u8 = undefined;
32+ var it = mem.tokenizeScalar(u8, library_path, ':');
33+ while (it.next()) |dir| {
34+ const linker_fullpath = std.fmt.bufPrint(&buffer, "{s}{s}{s}", .{ dir, fs.path.sep_str, linker_basename }) catch "";
35+ const guix_linker_path = fs.cwd().realpath(linker_fullpath, &buffer) catch "";
36+ if (guix_linker_path.len != 0) {
37+ standard_linker.set(guix_linker_path);
38+ break;
39+ }
40+ }
41+ }
42+ }
43+ }
44+ break :blk standard_linker;
45+ } else query.dynamic_linker,
46 };
47 }
48
49diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig
50index 3c96134556..90f31b17c1 100644
51--- a/lib/std/zig/system/NativePaths.zig
52+++ b/lib/std/zig/system/NativePaths.zig
53@@ -15,6 +15,51 @@ warnings: std.ArrayListUnmanaged([]const u8) = .empty,
54
55 pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths {
56 var self: NativePaths = .{ .arena = arena };
57+ if (isGuix(arena)) {
58+ inline for ([_][]const u8{ "CROSS_C_INCLUDE_PATH", "CROSS_CPLUS_INCLUDE_PATH" }) |env_var| {
59+ if (process.getEnvVarOwned(arena, env_var)) |include_path| {
60+ var it = mem.tokenizeScalar(u8, include_path, ':');
61+ while (it.next()) |dir|
62+ try self.addIncludeDir(dir);
63+ } else |err| switch (err) {
64+ error.InvalidWtf8 => unreachable,
65+ error.EnvironmentVariableNotFound => {},
66+ error.OutOfMemory => |e| return e,
67+ }
68+ }
69+ if (process.getEnvVarOwned(arena, "CROSS_LIBRARY_PATH")) |library_path| {
70+ var it = mem.tokenizeScalar(u8, library_path, ':');
71+ while (it.next()) |dir|
72+ try self.addLibDir(dir);
73+ } else |err| switch (err) {
74+ error.InvalidWtf8 => unreachable,
75+ error.EnvironmentVariableNotFound => {},
76+ error.OutOfMemory => |e| return e,
77+ }
78+ if (!isCrossGuix(arena)) {
79+ inline for ([_][]const u8{ "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH" }) |env_var| {
80+ if (process.getEnvVarOwned(arena, env_var)) |include_path| {
81+ var it = mem.tokenizeScalar(u8, include_path, ':');
82+ while (it.next()) |dir|
83+ try self.addIncludeDir(dir);
84+ } else |err| switch (err) {
85+ error.InvalidWtf8 => unreachable,
86+ error.EnvironmentVariableNotFound => {},
87+ error.OutOfMemory => |e| return e,
88+ }
89+ }
90+ if (process.getEnvVarOwned(arena, "LIBRARY_PATH")) |library_path| {
91+ var it = mem.tokenizeScalar(u8, library_path, ':');
92+ while (it.next()) |dir|
93+ try self.addLibDir(dir);
94+ } else |err| switch (err) {
95+ error.InvalidWtf8 => unreachable,
96+ error.EnvironmentVariableNotFound => {},
97+ error.OutOfMemory => |e| return e,
98+ }
99+ }
100+ return self;
101+ }
102 var is_nix = false;
103 if (process.getEnvVarOwned(arena, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
104 is_nix = true;
105@@ -208,3 +253,11 @@ pub fn addWarningFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype
106 pub fn addRPath(self: *NativePaths, s: []const u8) !void {
107 try self.rpaths.append(self.arena, s);
108 }
109+
110+pub fn isCrossGuix(arena: Allocator) bool {
111+ return process.hasEnvVar(arena, "CROSS_LIBRARY_PATH") catch false;
112+}
113+
114+pub fn isGuix(arena: Allocator) bool {
115+ return isCrossGuix(arena) or process.hasEnvVar(arena, "LIBRARY_PATH") catch false;
116+}
117diff --git a/src/main.zig b/src/main.zig
118index 0d239f1f99..79493aa624 100644
119--- a/src/main.zig
120+++ b/src/main.zig
121@@ -3909,7 +3909,8 @@ fn createModule(
122 }
123
124 // Trigger native system library path detection if necessary.
125- if (create_module.sysroot == null and
126+ if (std.zig.system.NativePaths.isCrossGuix(arena) or
127+ create_module.sysroot == null and
128 resolved_target.is_native_os and resolved_target.is_native_abi and
129 create_module.want_native_include_dirs)
130 {
131--
1322.46.0
133
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
index 476fe0e298b..733251242e4 100644
--- a/gnu/packages/zig.scm
+++ b/gnu/packages/zig.scm
@@ -1847,4 +1847,41 @@ toolchain. Among other features it provides
1847 (modify-inputs (package-native-inputs base) 1847 (modify-inputs (package-native-inputs base)
1848 (replace "zig" `(,base "zig1"))))))) 1848 (replace "zig" `(,base "zig1")))))))
1849 1849
1850(define zig-0.14-glibc-abi-tool
1851 (origin
1852 (method git-fetch)
1853 (uri (git-reference
1854 (url "https://github.com/ziglang/glibc-abi-tool")
1855 (commit "ed9d3bb356413e73b836955e75f399dfb3ec255e")))
1856 (file-name "glibc-abi-tool")
1857 (sha256
1858 (base32 "0ckhwlszm0vkiqsyp2rzp1zcfljh1ng24c7pdvpyfj51x4s612z1"))))
1859
1860(define-public zig-0.14
1861 (package
1862 (inherit zig-0.13)
1863 (name "zig")
1864 (version "0.14.0")
1865 (source
1866 (origin
1867 (inherit (zig-source
1868 version version
1869 "0ndrwir81zhkwviwnzwqc4vszc1klv1fnlf66nmdwijrkqi5wasp"))
1870 (patches
1871 (search-patches
1872 "zig-0.14-use-baseline-cpu-by-default.patch"
1873 "zig-0.14-use-system-paths.patch"
1874 "zig-0.14-fix-runpath.patch"))))
1875 (inputs
1876 (modify-inputs (package-inputs zig-0.13)
1877 (replace "clang" clang-19)
1878 (replace "lld" lld-19)))
1879 (native-inputs
1880 (modify-inputs (package-native-inputs zig-0.13)
1881 (replace "glibc-abi-tool" zig-0.14-glibc-abi-tool)
1882 (replace "llvm" llvm-19)
1883 (replace "zig" `(,zig-0.13.0-3252 "zig1"))))
1884 (properties `((max-silent-time . 9600)
1885 ,@(clang-compiler-cpu-architectures "19")))))
1886
1850(define-public zig zig-0.13) 1887(define-public zig zig-0.13)