diff options
| author | Hilton Chain <hako@ultrarare.space> | 2024-11-11 11:10:16 +0800 |
|---|---|---|
| committer | Hilton Chain <hako@ultrarare.space> | 2024-12-31 10:54:15 +0800 |
| commit | ab8979321881e59777da31ad11e77d5e482ff843 (patch) | |
| tree | 34c3d8cda8a51dd023306fa8297220113119db2f /gnu | |
| parent | 654e058538754f35eabf63e729243930140de89b (diff) | |
gnu: Add zig-0.11.
* gnu/packages/patches/zig-0.11-fix-runpath.patch: New file.
* gnu/packages/patches/zig-0.11-use-system-paths.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register them.
* gnu/packages/zig.scm (zig-0.11-glibc-abi-tool,zig-0.11): New variables.
Change-Id: I2507af62918f3989967d55dec942b84655d6d8bd
Diffstat (limited to 'gnu')
| -rw-r--r-- | gnu/local.mk | 2 | ||||
| -rw-r--r-- | gnu/packages/patches/zig-0.11-fix-runpath.patch | 45 | ||||
| -rw-r--r-- | gnu/packages/patches/zig-0.11-use-system-paths.patch | 133 | ||||
| -rw-r--r-- | gnu/packages/zig.scm | 74 |
4 files changed, 254 insertions, 0 deletions
diff --git a/gnu/local.mk b/gnu/local.mk index 3f6d8325a9e..5bf4731f4ea 100644 --- a/gnu/local.mk +++ b/gnu/local.mk | |||
| @@ -2423,6 +2423,8 @@ dist_patch_DATA = \ | |||
| 2423 | %D%/packages/patches/zig-0.10.0-675-TypeOf-hack.patch \ | 2423 | %D%/packages/patches/zig-0.10.0-675-TypeOf-hack.patch \ |
| 2424 | %D%/packages/patches/zig-0.10.0-747-CallOptions.patch \ | 2424 | %D%/packages/patches/zig-0.10.0-747-CallOptions.patch \ |
| 2425 | %D%/packages/patches/zig-0.10.0-1638-re-add-qualCast.patch \ | 2425 | %D%/packages/patches/zig-0.10.0-1638-re-add-qualCast.patch \ |
| 2426 | %D%/packages/patches/zig-0.11-fix-runpath.patch \ | ||
| 2427 | %D%/packages/patches/zig-0.11-use-system-paths.patch \ | ||
| 2426 | %D%/packages/patches/zsh-egrep-failing-test.patch \ | 2428 | %D%/packages/patches/zsh-egrep-failing-test.patch \ |
| 2427 | %D%/packages/patches/zuo-bin-sh.patch | 2429 | %D%/packages/patches/zuo-bin-sh.patch |
| 2428 | 2430 | ||
diff --git a/gnu/packages/patches/zig-0.11-fix-runpath.patch b/gnu/packages/patches/zig-0.11-fix-runpath.patch new file mode 100644 index 00000000000..1c9e8928745 --- /dev/null +++ b/gnu/packages/patches/zig-0.11-fix-runpath.patch | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | From 4a5397b856564d0fbc0b89186e682e6694a909b0 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Hilton Chain <hako@ultrarare.space> | ||
| 3 | Date: Wed, 27 Nov 2024 11:55:44 +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 | src/Compilation.zig | 2 +- | ||
| 10 | src/link/Elf.zig | 6 ++++++ | ||
| 11 | 2 files changed, 7 insertions(+), 1 deletion(-) | ||
| 12 | |||
| 13 | diff --git a/src/Compilation.zig b/src/Compilation.zig | ||
| 14 | index a08c3e09f4..add374d0ba 100644 | ||
| 15 | --- a/src/Compilation.zig | ||
| 16 | +++ b/src/Compilation.zig | ||
| 17 | @@ -1542,7 +1542,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ||
| 18 | .llvm_cpu_features = llvm_cpu_features, | ||
| 19 | .skip_linker_dependencies = options.skip_linker_dependencies, | ||
| 20 | .parent_compilation_link_libc = options.parent_compilation_link_libc, | ||
| 21 | - .each_lib_rpath = options.each_lib_rpath orelse false, | ||
| 22 | + .each_lib_rpath = std.zig.system.NativePaths.isGuix(arena) or options.each_lib_rpath orelse false, | ||
| 23 | .build_id = build_id, | ||
| 24 | .cache_mode = cache_mode, | ||
| 25 | .disable_lld_caching = options.disable_lld_caching or cache_mode == .whole, | ||
| 26 | diff --git a/src/link/Elf.zig b/src/link/Elf.zig | ||
| 27 | index dd88d47fab..b6e3944725 100644 | ||
| 28 | --- a/src/link/Elf.zig | ||
| 29 | +++ b/src/link/Elf.zig | ||
| 30 | @@ -1730,6 +1730,12 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v | ||
| 31 | } | ||
| 32 | } | ||
| 33 | } | ||
| 34 | + if (self.base.options.link_libc and self.base.options.link_mode == .Dynamic) { | ||
| 35 | + if (self.base.options.libc_installation) |libc_installation| { | ||
| 36 | + try argv.append("-rpath"); | ||
| 37 | + try argv.append(libc_installation.crt_dir.?); | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | } | ||
| 41 | |||
| 42 | for (self.base.options.lib_dirs) |lib_dir| { | ||
| 43 | -- | ||
| 44 | 2.46.0 | ||
| 45 | |||
diff --git a/gnu/packages/patches/zig-0.11-use-system-paths.patch b/gnu/packages/patches/zig-0.11-use-system-paths.patch new file mode 100644 index 00000000000..0eeaffe5397 --- /dev/null +++ b/gnu/packages/patches/zig-0.11-use-system-paths.patch | |||
| @@ -0,0 +1,133 @@ | |||
| 1 | From 8b76c88e577fcd6a054ecfee333b2989ec94a3cc Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Hilton Chain <hako@ultrarare.space> | ||
| 3 | Date: Wed, 27 Nov 2024 11:54:51 +0800 | ||
| 4 | Subject: [PATCH] Use system paths. | ||
| 5 | |||
| 6 | Prefer Guix search paths and support Guix cross builds. | ||
| 7 | --- | ||
| 8 | lib/std/zig/system/NativePaths.zig | 53 +++++++++++++++++++++++++ | ||
| 9 | lib/std/zig/system/NativeTargetInfo.zig | 25 ++++++++++-- | ||
| 10 | src/main.zig | 3 +- | ||
| 11 | 3 files changed, 76 insertions(+), 5 deletions(-) | ||
| 12 | |||
| 13 | diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig | ||
| 14 | index 4c8f1286b8..5b4805f6c6 100644 | ||
| 15 | --- a/lib/std/zig/system/NativePaths.zig | ||
| 16 | +++ b/lib/std/zig/system/NativePaths.zig | ||
| 17 | @@ -17,6 +17,51 @@ warnings: std.ArrayListUnmanaged([]const u8) = .{}, | ||
| 18 | pub fn detect(arena: Allocator, native_info: NativeTargetInfo) !NativePaths { | ||
| 19 | const native_target = native_info.target; | ||
| 20 | var self: NativePaths = .{ .arena = arena }; | ||
| 21 | + if (isGuix(arena)) { | ||
| 22 | + inline for ([_][]const u8{ "CROSS_C_INCLUDE_PATH", "CROSS_CPLUS_INCLUDE_PATH" }) |env_var| { | ||
| 23 | + if (process.getEnvVarOwned(arena, env_var)) |include_path| { | ||
| 24 | + var it = mem.tokenizeScalar(u8, include_path, ':'); | ||
| 25 | + while (it.next()) |dir| | ||
| 26 | + try self.addIncludeDir(dir); | ||
| 27 | + } else |err| switch (err) { | ||
| 28 | + error.InvalidUtf8 => {}, | ||
| 29 | + error.EnvironmentVariableNotFound => {}, | ||
| 30 | + error.OutOfMemory => |e| return e, | ||
| 31 | + } | ||
| 32 | + } | ||
| 33 | + if (process.getEnvVarOwned(arena, "CROSS_LIBRARY_PATH")) |library_path| { | ||
| 34 | + var it = mem.tokenizeScalar(u8, library_path, ':'); | ||
| 35 | + while (it.next()) |dir| | ||
| 36 | + try self.addLibDir(dir); | ||
| 37 | + } else |err| switch (err) { | ||
| 38 | + error.InvalidUtf8 => {}, | ||
| 39 | + error.EnvironmentVariableNotFound => {}, | ||
| 40 | + error.OutOfMemory => |e| return e, | ||
| 41 | + } | ||
| 42 | + if (!isCrossGuix(arena)) { | ||
| 43 | + inline for ([_][]const u8{ "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH" }) |env_var| { | ||
| 44 | + if (process.getEnvVarOwned(arena, env_var)) |include_path| { | ||
| 45 | + var it = mem.tokenizeScalar(u8, include_path, ':'); | ||
| 46 | + while (it.next()) |dir| | ||
| 47 | + try self.addIncludeDir(dir); | ||
| 48 | + } else |err| switch (err) { | ||
| 49 | + error.InvalidUtf8 => {}, | ||
| 50 | + error.EnvironmentVariableNotFound => {}, | ||
| 51 | + error.OutOfMemory => |e| return e, | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + if (process.getEnvVarOwned(arena, "LIBRARY_PATH")) |library_path| { | ||
| 55 | + var it = mem.tokenizeScalar(u8, library_path, ':'); | ||
| 56 | + while (it.next()) |dir| | ||
| 57 | + try self.addLibDir(dir); | ||
| 58 | + } else |err| switch (err) { | ||
| 59 | + error.InvalidUtf8 => {}, | ||
| 60 | + error.EnvironmentVariableNotFound => {}, | ||
| 61 | + error.OutOfMemory => |e| return e, | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + return self; | ||
| 65 | + } | ||
| 66 | var is_nix = false; | ||
| 67 | if (process.getEnvVarOwned(arena, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| { | ||
| 68 | is_nix = true; | ||
| 69 | @@ -196,3 +241,11 @@ pub fn addWarningFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype | ||
| 70 | pub fn addRPath(self: *NativePaths, s: []const u8) !void { | ||
| 71 | try self.rpaths.append(self.arena, s); | ||
| 72 | } | ||
| 73 | + | ||
| 74 | +pub fn isCrossGuix(arena: Allocator) bool { | ||
| 75 | + return process.hasEnvVar(arena, "CROSS_LIBRARY_PATH") catch false; | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +pub fn isGuix(arena: Allocator) bool { | ||
| 79 | + return isCrossGuix(arena) or process.hasEnvVar(arena, "LIBRARY_PATH") catch false; | ||
| 80 | +} | ||
| 81 | diff --git a/lib/std/zig/system/NativeTargetInfo.zig b/lib/std/zig/system/NativeTargetInfo.zig | ||
| 82 | index 99a1a8f2ef..50d0d9949c 100644 | ||
| 83 | --- a/lib/std/zig/system/NativeTargetInfo.zig | ||
| 84 | +++ b/lib/std/zig/system/NativeTargetInfo.zig | ||
| 85 | @@ -923,10 +923,27 @@ fn defaultAbiAndDynamicLinker(cpu: Target.Cpu, os: Target.Os, cross_target: Cros | ||
| 86 | }; | ||
| 87 | return NativeTargetInfo{ | ||
| 88 | .target = target, | ||
| 89 | - .dynamic_linker = if (cross_target.dynamic_linker.get() == null) | ||
| 90 | - target.standardDynamicLinkerPath() | ||
| 91 | - else | ||
| 92 | - cross_target.dynamic_linker, | ||
| 93 | + .dynamic_linker = if (cross_target.dynamic_linker.get() == null) blk: { | ||
| 94 | + var standard_linker = target.standardDynamicLinkerPath(); | ||
| 95 | + if (standard_linker.get()) |standard_linker_path| { | ||
| 96 | + if (builtin.os.tag != .windows and builtin.os.tag != .wasi) { | ||
| 97 | + if (std.os.getenv("CROSS_LIBRARY_PATH") orelse std.os.getenv("LIBRARY_PATH")) |library_path| { | ||
| 98 | + const linker_basename = fs.path.basename(standard_linker_path); | ||
| 99 | + var buffer: [255]u8 = undefined; | ||
| 100 | + var it = mem.tokenizeScalar(u8, library_path, ':'); | ||
| 101 | + while (it.next()) |dir| { | ||
| 102 | + const linker_fullpath = std.fmt.bufPrint(&buffer, "{s}{s}{s}", .{ dir, fs.path.sep_str, linker_basename }) catch ""; | ||
| 103 | + const guix_linker_path = fs.cwd().realpath(linker_fullpath, &buffer) catch ""; | ||
| 104 | + if (guix_linker_path.len != 0) { | ||
| 105 | + standard_linker.set(guix_linker_path); | ||
| 106 | + break; | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + break :blk standard_linker; | ||
| 113 | + } else cross_target.dynamic_linker, | ||
| 114 | }; | ||
| 115 | } | ||
| 116 | |||
| 117 | diff --git a/src/main.zig b/src/main.zig | ||
| 118 | index 456886c915..e2a97bf244 100644 | ||
| 119 | --- a/src/main.zig | ||
| 120 | +++ b/src/main.zig | ||
| 121 | @@ -2674,7 +2674,8 @@ fn buildOutputType( | ||
| 122 | // After this point, external_system_libs is used instead of system_libs. | ||
| 123 | |||
| 124 | // Trigger native system library path detection if necessary. | ||
| 125 | - if (sysroot == null and cross_target.isNativeOs() and cross_target.isNativeAbi() and | ||
| 126 | + if (std.zig.system.NativePaths.isCrossGuix(arena) or | ||
| 127 | + sysroot == null and cross_target.isNativeOs() and cross_target.isNativeAbi() and | ||
| 128 | (external_system_libs.len != 0 or want_native_include_dirs)) | ||
| 129 | { | ||
| 130 | const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| { | ||
| 131 | -- | ||
| 132 | 2.46.0 | ||
| 133 | |||
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm index ac1ed3876da..8d087a7b8f4 100644 --- a/gnu/packages/zig.scm +++ b/gnu/packages/zig.scm | |||
| @@ -1084,4 +1084,78 @@ toolchain. Among other features it provides | |||
| 1084 | (modify-inputs (package-native-inputs base) | 1084 | (modify-inputs (package-native-inputs base) |
| 1085 | (replace "zig" `(,base "out"))))))) | 1085 | (replace "zig" `(,base "out"))))))) |
| 1086 | 1086 | ||
| 1087 | (define zig-0.11-glibc-abi-tool | ||
| 1088 | (origin | ||
| 1089 | (method git-fetch) | ||
| 1090 | (uri (git-reference | ||
| 1091 | (url "https://github.com/ziglang/glibc-abi-tool") | ||
| 1092 | (commit "13576b1ea957882be7ff2c99f4cdc27454930219"))) | ||
| 1093 | (file-name "glibc-abi-tool") | ||
| 1094 | (sha256 | ||
| 1095 | (base32 "09m0ipixxw0dnal0zsgk6kvcz29y9s256b9y00s4hkhj95n630il")) | ||
| 1096 | (modules '((guix build utils))) | ||
| 1097 | (snippet | ||
| 1098 | #~(begin | ||
| 1099 | (substitute* "consolidate.zig" | ||
| 1100 | ((".*minor = 3[5678].*") "") | ||
| 1101 | (("(w\\.writeIntLittle.u16, )(@intCast.*);" _ prefix suffix) | ||
| 1102 | (string-append prefix "@as(u16, " suffix ");"))) | ||
| 1103 | (with-directory-excursion "glibc" | ||
| 1104 | (for-each delete-file-recursively | ||
| 1105 | '("2.35" "2.36" "2.37" "2.38"))))))) | ||
| 1106 | |||
| 1107 | (define-public zig-0.11 | ||
| 1108 | (package | ||
| 1109 | (inherit zig-0.10) | ||
| 1110 | (name "zig") | ||
| 1111 | (version "0.11.0") | ||
| 1112 | (source | ||
| 1113 | (origin | ||
| 1114 | (inherit (zig-source | ||
| 1115 | version version | ||
| 1116 | "0qh7c27cd4wcdjj0mbpkarvwypfk1js8hkyxs0z149qv75zkbrca")) | ||
| 1117 | (patches | ||
| 1118 | (search-patches | ||
| 1119 | "zig-0.9-use-baseline-cpu-by-default.patch" | ||
| 1120 | "zig-0.11-use-system-paths.patch" | ||
| 1121 | "zig-0.11-fix-runpath.patch")))) | ||
| 1122 | (arguments | ||
| 1123 | (substitute-keyword-arguments (package-arguments zig-0.10) | ||
| 1124 | ((#:phases phases '%standard-phases) | ||
| 1125 | #~(modify-phases #$phases | ||
| 1126 | (add-after 'unpack 'prepare-source | ||
| 1127 | (lambda* (#:key native-inputs inputs #:allow-other-keys) | ||
| 1128 | (install-file (search-input-file | ||
| 1129 | (or native-inputs inputs) "bin/zig1.wasm") | ||
| 1130 | "stage1") | ||
| 1131 | (make-file-writable "stage1/zig1.wasm"))) | ||
| 1132 | (add-after 'install 'build-zig1 | ||
| 1133 | (lambda _ | ||
| 1134 | (invoke (string-append #$output "/bin/zig") | ||
| 1135 | "build" "update-zig1" "--verbose"))) | ||
| 1136 | (add-after 'build-zig1 'install-zig1 | ||
| 1137 | (lambda _ | ||
| 1138 | (install-file "stage1/zig1.wasm" | ||
| 1139 | (string-append #$output:zig1 "/bin")))) | ||
| 1140 | ;; TODO: Disable tests for macOS target and run full test. | ||
| 1141 | ;; Issue with glibc in CPLUS_INCLUDE_PATH: | ||
| 1142 | ;; <https://github.com/ziglang/zig/issues/18063>. | ||
| 1143 | (replace 'check | ||
| 1144 | (lambda* (#:key tests? #:allow-other-keys) | ||
| 1145 | (when tests? | ||
| 1146 | (invoke (string-append #$output "/bin/zig") | ||
| 1147 | "test" "-I" "test" "test/behavior.zig")))))))) | ||
| 1148 | (inputs | ||
| 1149 | (modify-inputs (package-inputs zig-0.10) | ||
| 1150 | (replace "clang" clang-16) | ||
| 1151 | (replace "lld" lld-16))) | ||
| 1152 | (native-inputs | ||
| 1153 | (modify-inputs (package-native-inputs zig-0.10) | ||
| 1154 | (prepend binaryen `(,zig-0.10.0-3985 "zig1")) | ||
| 1155 | (replace "glibc-abi-tool" zig-0.11-glibc-abi-tool) | ||
| 1156 | (replace "llvm" llvm-16))) | ||
| 1157 | (outputs '("out" "zig1")) | ||
| 1158 | (properties `((max-silent-time . 9600) | ||
| 1159 | ,@(clang-compiler-cpu-architectures "16"))))) | ||
| 1160 | |||
| 1087 | (define-public zig zig-0.10) | 1161 | (define-public zig zig-0.10) |
