diff options
| author | Hilton Chain <hako@ultrarare.space> | 2024-11-11 21:20:00 +0800 |
|---|---|---|
| committer | Hilton Chain <hako@ultrarare.space> | 2024-12-31 10:54:17 +0800 |
| commit | 8808ea98ae1429232a1b7df35e1b75f4c9bac42b (patch) | |
| tree | 84012489b4cad3db96591a38153812f1ab75954f /gnu/packages | |
| parent | a39aa559ae42007937a5521ea972f0bbf0089223 (diff) | |
gnu: Add zig-0.13.
* gnu/packages/patches/zig-0.13-fix-runpath.patch: New file.
* gnu/local.mk (dist_patch_DATA): Regisiter it.
* gnu/packages/zig.scm (zig-0.13-glibc-abi-tool,zig-0.13): New variables.
Change-Id: I217a1d444acb600d8cc38abcaa3950156b11cbae
Diffstat (limited to 'gnu/packages')
| -rw-r--r-- | gnu/packages/patches/zig-0.13-fix-runpath.patch | 121 | ||||
| -rw-r--r-- | gnu/packages/zig.scm | 37 |
2 files changed, 158 insertions, 0 deletions
diff --git a/gnu/packages/patches/zig-0.13-fix-runpath.patch b/gnu/packages/patches/zig-0.13-fix-runpath.patch new file mode 100644 index 00000000000..b77686a0b90 --- /dev/null +++ b/gnu/packages/patches/zig-0.13-fix-runpath.patch | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | From 68a437ab4ab3aeac0f7a7932f3e5b78d9dfb25b7 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Hilton Chain <hako@ultrarare.space> | ||
| 3 | Date: Fri, 29 Nov 2024 14:13:46 +0800 | ||
| 4 | Subject: [PATCH] Fix RUNPATH issue. | ||
| 5 | |||
| 6 | Add needed libraries and libc to RUNPATH when CROSS_LIBRARY_PATH or LIBRARY_PATH | ||
| 7 | is set. | ||
| 8 | --- | ||
| 9 | lib/std/Build/Step/Compile.zig | 3 +++ | ||
| 10 | src/link/Elf.zig | 14 +++++++++++++ | ||
| 11 | src/main.zig | 37 +++++++++++++++++++++++++++++++++- | ||
| 12 | 3 files changed, 53 insertions(+), 1 deletion(-) | ||
| 13 | |||
| 14 | diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig | ||
| 15 | index d18d8de413..5bb442e4a1 100644 | ||
| 16 | --- a/lib/std/Build/Step/Compile.zig | ||
| 17 | +++ b/lib/std/Build/Step/Compile.zig | ||
| 18 | @@ -741,6 +741,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 | } | ||
| 28 | diff --git a/src/link/Elf.zig b/src/link/Elf.zig | ||
| 29 | index 770d483e98..38660d5d80 100644 | ||
| 30 | --- a/src/link/Elf.zig | ||
| 31 | +++ b/src/link/Elf.zig | ||
| 32 | @@ -1504,6 +1504,13 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { | ||
| 33 | try argv.append(rpath); | ||
| 34 | } | ||
| 35 | |||
| 36 | + if (comp.config.link_libc and link_mode == .dynamic and std.zig.system.NativePaths.isGuix(arena)) { | ||
| 37 | + if (self.base.comp.libc_installation) |libc_installation| { | ||
| 38 | + try argv.append("-rpath"); | ||
| 39 | + try argv.append(libc_installation.crt_dir.?); | ||
| 40 | + } | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | try argv.appendSlice(&.{ | ||
| 44 | "-z", | ||
| 45 | try std.fmt.allocPrint(arena, "stack-size={d}", .{self.base.stack_size}), | ||
| 46 | @@ -2533,6 +2540,13 @@ fn linkWithLLD(self: *Elf, arena: Allocator, prog_node: std.Progress.Node) !void | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | + if (comp.config.link_libc and link_mode == .dynamic and std.zig.system.NativePaths.isGuix(arena)) { | ||
| 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 | } | ||
| 60 | diff --git a/src/main.zig b/src/main.zig | ||
| 61 | index 90f78d51d4..9306b7be44 100644 | ||
| 62 | --- a/src/main.zig | ||
| 63 | +++ b/src/main.zig | ||
| 64 | @@ -3719,7 +3719,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.appendSlice(arena, create_module.lib_dirs.items); | ||
| 71 | } | ||
| 72 | |||
| 73 | @@ -3939,6 +3939,24 @@ fn createModule( | ||
| 74 | if (create_module.resolved_system_libs.len != 0) | ||
| 75 | create_module.opts.any_dyn_libs = true; | ||
| 76 | |||
| 77 | + if (std.zig.system.NativePaths.isGuix(arena)) { | ||
| 78 | + for (create_module.resolved_system_libs.items(.name)) |lib_name| { | ||
| 79 | + for (create_module.lib_dirs.items) |lib_dir_path| { | ||
| 80 | + if (try libPathExists(arena, lib_dir_path, lib_name, target)) { | ||
| 81 | + try create_module.rpath_list.append(arena, lib_dir_path); | ||
| 82 | + break; | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + for (create_module.link_objects.items) |obj| { | ||
| 87 | + if (Compilation.classifyFileExt(obj.path) == .shared_library) { | ||
| 88 | + const lib_dir_path = fs.path.dirname(obj.path) orelse continue; | ||
| 89 | + if (obj.loption) continue; | ||
| 90 | + try create_module.rpath_list.append(arena, lib_dir_path); | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | create_module.resolved_options = Compilation.Config.resolve(create_module.opts) catch |err| switch (err) { | ||
| 96 | error.WasiExecModelRequiresWasi => fatal("only WASI OS targets support execution model", .{}), | ||
| 97 | error.SharedMemoryIsWasmOnly => fatal("only WebAssembly CPU targets support shared memory", .{}), | ||
| 98 | @@ -7448,3 +7466,20 @@ fn handleModArg( | ||
| 99 | c_source_files_owner_index.* = create_module.c_source_files.items.len; | ||
| 100 | rc_source_files_owner_index.* = create_module.rc_source_files.items.len; | ||
| 101 | } | ||
| 102 | + | ||
| 103 | +fn libPathExists( | ||
| 104 | + arena: Allocator, | ||
| 105 | + lib_dir_path: []const u8, | ||
| 106 | + lib_name: []const u8, | ||
| 107 | + target: std.Target, | ||
| 108 | +) !bool { | ||
| 109 | + const sep = fs.path.sep_str; | ||
| 110 | + const lib_path = try std.fmt.allocPrint(arena, "{s}" ++ sep ++ "{s}{s}{s}", .{ | ||
| 111 | + lib_dir_path, | ||
| 112 | + target.libPrefix(), | ||
| 113 | + lib_name, | ||
| 114 | + target.dynamicLibSuffix(), | ||
| 115 | + }); | ||
| 116 | + fs.cwd().access(lib_path, .{}) catch return false; | ||
| 117 | + return true; | ||
| 118 | +} | ||
| 119 | -- | ||
| 120 | 2.46.0 | ||
| 121 | |||
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm index a06b6de5302..cbdff2c2ff2 100644 --- a/gnu/packages/zig.scm +++ b/gnu/packages/zig.scm | |||
| @@ -1526,4 +1526,41 @@ toolchain. Among other features it provides | |||
| 1526 | (modify-inputs (package-native-inputs base) | 1526 | (modify-inputs (package-native-inputs base) |
| 1527 | (replace "zig" `(,base "out"))))))) | 1527 | (replace "zig" `(,base "out"))))))) |
| 1528 | 1528 | ||
| 1529 | (define zig-0.13-glibc-abi-tool | ||
| 1530 | (origin | ||
| 1531 | (method git-fetch) | ||
| 1532 | (uri (git-reference | ||
| 1533 | (url "https://github.com/ziglang/glibc-abi-tool") | ||
| 1534 | (commit "fc5d0a7046b76795e4219f8f168e118ec29fbc53"))) | ||
| 1535 | (file-name "glibc-abi-tool") | ||
| 1536 | (sha256 | ||
| 1537 | (base32 "1q9plbqkkk3jzrvsgcjmj5jjdncz4ym9p0snglz4kkjwwm65gqs1")))) | ||
| 1538 | |||
| 1539 | (define-public zig-0.13 | ||
| 1540 | (package | ||
| 1541 | (inherit zig-0.12) | ||
| 1542 | (name "zig") | ||
| 1543 | (version "0.13.0") | ||
| 1544 | (source | ||
| 1545 | (origin | ||
| 1546 | (inherit (zig-source | ||
| 1547 | version version | ||
| 1548 | "0ly8042lbsa8019g0d1jg4l06rxpq2530n9mijq66n4lmx7a5976")) | ||
| 1549 | (patches | ||
| 1550 | (search-patches | ||
| 1551 | "zig-0.12-use-baseline-cpu-by-default.patch" | ||
| 1552 | "zig-0.12-use-system-paths.patch" | ||
| 1553 | "zig-0.13-fix-runpath.patch")))) | ||
| 1554 | (inputs | ||
| 1555 | (modify-inputs (package-inputs zig-0.12) | ||
| 1556 | (replace "clang" clang-18) | ||
| 1557 | (replace "lld" lld-18))) | ||
| 1558 | (native-inputs | ||
| 1559 | (modify-inputs (package-native-inputs zig-0.12) | ||
| 1560 | (replace "glibc-abi-tool" zig-0.13-glibc-abi-tool) | ||
| 1561 | (replace "llvm" llvm-18) | ||
| 1562 | (replace "zig" `(,zig-0.12.0-109 "zig1")))) | ||
| 1563 | (properties `((max-silent-time . 9600) | ||
| 1564 | ,@(clang-compiler-cpu-architectures "18"))))) | ||
| 1565 | |||
| 1529 | (define-public zig zig-0.10) | 1566 | (define-public zig zig-0.10) |
