mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2025-01-18 13:36:36 +01:00
DRAFT gnu: Add zig-0.14 (fake).
* 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
This commit is contained in:
parent
81b2609aed
commit
34da9020e0
5 changed files with 334 additions and 0 deletions
|
@ -2434,6 +2434,9 @@ dist_patch_DATA = \
|
|||
%D%/packages/patches/zig-0.12-use-system-paths.patch \
|
||||
%D%/packages/patches/zig-0.13-build-respect-PKG_CONFIG-env-var.patch \
|
||||
%D%/packages/patches/zig-0.13-fix-runpath.patch \
|
||||
%D%/packages/patches/zig-0.14-fix-runpath.patch \
|
||||
%D%/packages/patches/zig-0.14-use-baseline-cpu-by-default.patch \
|
||||
%D%/packages/patches/zig-0.14-use-system-paths.patch \
|
||||
%D%/packages/patches/zsh-egrep-failing-test.patch \
|
||||
%D%/packages/patches/zuo-bin-sh.patch
|
||||
|
||||
|
|
118
gnu/packages/patches/zig-0.14-fix-runpath.patch
Normal file
118
gnu/packages/patches/zig-0.14-fix-runpath.patch
Normal file
|
@ -0,0 +1,118 @@
|
|||
From d5c31f6d99a3d02c8b0efba13e1a1e82e0e36f96 Mon Sep 17 00:00:00 2001
|
||||
From: Hilton Chain <hako@ultrarare.space>
|
||||
Date: Fri, 29 Nov 2024 14:13:46 +0800
|
||||
Subject: [PATCH] Fix RUNPATH issue.
|
||||
|
||||
Add needed libraries and libc to RUNPATH when CROSS_LIBRARY_PATH or LIBRARY_PATH
|
||||
is set.
|
||||
---
|
||||
lib/std/Build/Step/Compile.zig | 3 +++
|
||||
src/link/Elf.zig | 14 ++++++++++++++
|
||||
src/main.zig | 34 +++++++++++++++++++++++++++++++++-
|
||||
3 files changed, 50 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig
|
||||
index 1dd444abf2..df7f4a56db 100644
|
||||
--- a/lib/std/Build/Step/Compile.zig
|
||||
+++ b/lib/std/Build/Step/Compile.zig
|
||||
@@ -778,6 +778,9 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
|
||||
try zig_cflags.appendSlice(&[_][]const u8{ "-D", macro });
|
||||
} else if (mem.startsWith(u8, arg, "-D")) {
|
||||
try zig_cflags.append(arg);
|
||||
+ } else if (mem.startsWith(u8, arg, "-Wl,-rpath=")) {
|
||||
+ const dir = arg["-Wl,-rpath=".len..];
|
||||
+ try zig_libs.appendSlice(&[_][]const u8{ "-L", dir });
|
||||
} else if (b.debug_pkg_config) {
|
||||
return compile.step.fail("unknown pkg-config flag '{s}'", .{arg});
|
||||
}
|
||||
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
|
||||
index 608ff2fe3a..2b9fe803fd 100644
|
||||
--- a/src/link/Elf.zig
|
||||
+++ b/src/link/Elf.zig
|
||||
@@ -1037,6 +1037,13 @@ fn dumpArgvInit(self: *Elf, arena: Allocator) !void {
|
||||
try argv.appendSlice(gpa, &.{ "-rpath", rpath });
|
||||
}
|
||||
|
||||
+ if (std.zig.system.NativePaths.isGuix(arena) and comp.config.link_libc and comp.config.link_mode == .dynamic) {
|
||||
+ if (self.base.comp.libc_installation) |libc_installation| {
|
||||
+ try argv.append(gpa, "-rpath");
|
||||
+ try argv.append(gpa, libc_installation.crt_dir.?);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
try argv.appendSlice(gpa, &.{
|
||||
"-z",
|
||||
try std.fmt.allocPrint(arena, "stack-size={d}", .{self.base.stack_size}),
|
||||
@@ -1857,6 +1864,13 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
|
||||
try argv.appendSlice(&.{ "-rpath", rpath });
|
||||
}
|
||||
|
||||
+ if (std.zig.system.NativePaths.isGuix(arena) and comp.config.link_libc and link_mode == .dynamic) {
|
||||
+ if (self.base.comp.libc_installation) |libc_installation| {
|
||||
+ try argv.append("-rpath");
|
||||
+ try argv.append(libc_installation.crt_dir.?);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
for (self.symbol_wrap_set.keys()) |symbol_name| {
|
||||
try argv.appendSlice(&.{ "-wrap", symbol_name });
|
||||
}
|
||||
diff --git a/src/main.zig b/src/main.zig
|
||||
index 79493aa624..505bb7570a 100644
|
||||
--- a/src/main.zig
|
||||
+++ b/src/main.zig
|
||||
@@ -3901,7 +3901,7 @@ fn createModule(
|
||||
create_module.want_native_include_dirs = true;
|
||||
}
|
||||
|
||||
- if (create_module.each_lib_rpath orelse resolved_target.is_native_os) {
|
||||
+ if (create_module.each_lib_rpath orelse false) {
|
||||
try create_module.rpath_list.ensureUnusedCapacity(arena, create_module.lib_directories.items.len);
|
||||
for (create_module.lib_directories.items) |lib_directory| {
|
||||
create_module.rpath_list.appendAssumeCapacity(lib_directory.path.?);
|
||||
@@ -3976,6 +3976,28 @@ fn createModule(
|
||||
else => {},
|
||||
};
|
||||
|
||||
+ if (std.zig.system.NativePaths.isGuix(arena)) {
|
||||
+ for (create_module.link_inputs.items) |link_input| {
|
||||
+ if (link_input.path()) |lib| {
|
||||
+ const lib_name = lib.sub_path;
|
||||
+ if (Compilation.classifyFileExt(lib_name) == .shared_library) {
|
||||
+ if (fs.path.isAbsolute(lib_name)) {
|
||||
+ const lib_dir_path = fs.path.dirname(lib_name).?;
|
||||
+ try create_module.rpath_list.append(arena, lib_dir_path);
|
||||
+ continue;
|
||||
+ }
|
||||
+ for (create_module.lib_directories.items) |lib_dir| {
|
||||
+ const lib_dir_path = lib_dir.path.?;
|
||||
+ if (try libPathExists(arena, lib_dir_path, lib_name)) {
|
||||
+ try create_module.rpath_list.append(arena, lib_dir_path);
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
create_module.resolved_options = Compilation.Config.resolve(create_module.opts) catch |err| switch (err) {
|
||||
error.WasiExecModelRequiresWasi => fatal("only WASI OS targets support execution model", .{}),
|
||||
error.SharedMemoryIsWasmOnly => fatal("only WebAssembly CPU targets support shared memory", .{}),
|
||||
@@ -7495,3 +7517,13 @@ fn addLibDirectoryWarn2(
|
||||
.path = path,
|
||||
});
|
||||
}
|
||||
+
|
||||
+fn libPathExists(arena: Allocator, lib_dir_path: []const u8, lib_name: []const u8) !bool {
|
||||
+ const lib_path = try std.fmt.allocPrint(arena, "{s}{s}{s}", .{
|
||||
+ lib_dir_path,
|
||||
+ fs.path.sep_str,
|
||||
+ lib_name,
|
||||
+ });
|
||||
+ fs.cwd().access(lib_path, .{}) catch return false;
|
||||
+ return true;
|
||||
+}
|
||||
--
|
||||
2.46.0
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
From 7da6d5e31e3f99fef7e669e2dbe4104ae0f12073 Mon Sep 17 00:00:00 2001
|
||||
From: Ekaitz Zarraga <ekaitz@elenq.tech>
|
||||
Date: Sat, 18 Nov 2023 15:04:16 +0100
|
||||
Subject: [PATCH] Use `baseline` cpu by default.
|
||||
|
||||
This helps Guix tune the package later. Tunning will only add
|
||||
`-Dcpu=whatever` which should override the standard behaviour.
|
||||
|
||||
Zig by default uses `native`, which interferes with our build process.
|
||||
In our previous zig-build-system we chose to add `-Dcpu=baseline` flag
|
||||
in each `zig build` execution, but that doesn't allow us to tune the
|
||||
package later. Tunning is only designed to add extra flags in the
|
||||
command line call, and we already had one set for the baseline case.
|
||||
With this patch we set the standard behavior to `baseline` so we don't
|
||||
need to add the `-Dcpu=baseline` flag in the zig-build-system and we can
|
||||
tune with no issues.
|
||||
---
|
||||
lib/std/Target/Query.zig | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/std/Target/Query.zig b/lib/std/Target/Query.zig
|
||||
index 144b2d60af..5a496b531d 100644
|
||||
--- a/lib/std/Target/Query.zig
|
||||
+++ b/lib/std/Target/Query.zig
|
||||
@@ -6,7 +6,7 @@
|
||||
/// `null` means native.
|
||||
cpu_arch: ?Target.Cpu.Arch = null,
|
||||
|
||||
-cpu_model: CpuModel = CpuModel.determined_by_arch_os,
|
||||
+cpu_model: CpuModel = CpuModel.baseline,
|
||||
|
||||
/// Sparse set of CPU features to add to the set from `cpu_model`.
|
||||
cpu_features_add: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty,
|
||||
--
|
||||
2.46.0
|
||||
|
133
gnu/packages/patches/zig-0.14-use-system-paths.patch
Normal file
133
gnu/packages/patches/zig-0.14-use-system-paths.patch
Normal file
|
@ -0,0 +1,133 @@
|
|||
From 813993ef425ba24e7a18d3cdf700c0589a333943 Mon Sep 17 00:00:00 2001
|
||||
From: Hilton Chain <hako@ultrarare.space>
|
||||
Date: Fri, 29 Nov 2024 14:13:30 +0800
|
||||
Subject: [PATCH] Use system paths.
|
||||
|
||||
Prefer Guix search paths and support Guix cross builds.
|
||||
---
|
||||
lib/std/zig/system.zig | 25 +++++++++++---
|
||||
lib/std/zig/system/NativePaths.zig | 53 ++++++++++++++++++++++++++++++
|
||||
src/main.zig | 3 +-
|
||||
3 files changed, 76 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig
|
||||
index 48b195dc3e..b636c46656 100644
|
||||
--- a/lib/std/zig/system.zig
|
||||
+++ b/lib/std/zig/system.zig
|
||||
@@ -1176,10 +1176,27 @@ fn defaultAbiAndDynamicLinker(cpu: Target.Cpu, os: Target.Os, query: Target.Quer
|
||||
.os = os,
|
||||
.abi = abi,
|
||||
.ofmt = query.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch),
|
||||
- .dynamic_linker = if (query.dynamic_linker.get() == null)
|
||||
- Target.DynamicLinker.standard(cpu, os, abi)
|
||||
- else
|
||||
- query.dynamic_linker,
|
||||
+ .dynamic_linker = if (query.dynamic_linker.get() == null) blk: {
|
||||
+ var standard_linker = Target.DynamicLinker.standard(cpu, os, abi);
|
||||
+ if (standard_linker.get()) |standard_linker_path| {
|
||||
+ if (builtin.os.tag != .windows and builtin.os.tag != .wasi) {
|
||||
+ if (posix.getenv("CROSS_LIBRARY_PATH") orelse posix.getenv("LIBRARY_PATH")) |library_path| {
|
||||
+ const linker_basename = fs.path.basename(standard_linker_path);
|
||||
+ var buffer: [255]u8 = undefined;
|
||||
+ var it = mem.tokenizeScalar(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 query.dynamic_linker,
|
||||
};
|
||||
}
|
||||
|
||||
diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig
|
||||
index 3c96134556..90f31b17c1 100644
|
||||
--- a/lib/std/zig/system/NativePaths.zig
|
||||
+++ b/lib/std/zig/system/NativePaths.zig
|
||||
@@ -15,6 +15,51 @@ warnings: std.ArrayListUnmanaged([]const u8) = .empty,
|
||||
|
||||
pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths {
|
||||
var self: NativePaths = .{ .arena = arena };
|
||||
+ if (isGuix(arena)) {
|
||||
+ inline for ([_][]const u8{ "CROSS_C_INCLUDE_PATH", "CROSS_CPLUS_INCLUDE_PATH" }) |env_var| {
|
||||
+ if (process.getEnvVarOwned(arena, env_var)) |include_path| {
|
||||
+ var it = mem.tokenizeScalar(u8, include_path, ':');
|
||||
+ while (it.next()) |dir|
|
||||
+ try self.addIncludeDir(dir);
|
||||
+ } else |err| switch (err) {
|
||||
+ error.InvalidWtf8 => unreachable,
|
||||
+ error.EnvironmentVariableNotFound => {},
|
||||
+ error.OutOfMemory => |e| return e,
|
||||
+ }
|
||||
+ }
|
||||
+ if (process.getEnvVarOwned(arena, "CROSS_LIBRARY_PATH")) |library_path| {
|
||||
+ var it = mem.tokenizeScalar(u8, library_path, ':');
|
||||
+ while (it.next()) |dir|
|
||||
+ try self.addLibDir(dir);
|
||||
+ } else |err| switch (err) {
|
||||
+ error.InvalidWtf8 => unreachable,
|
||||
+ error.EnvironmentVariableNotFound => {},
|
||||
+ error.OutOfMemory => |e| return e,
|
||||
+ }
|
||||
+ if (!isCrossGuix(arena)) {
|
||||
+ inline for ([_][]const u8{ "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH" }) |env_var| {
|
||||
+ if (process.getEnvVarOwned(arena, env_var)) |include_path| {
|
||||
+ var it = mem.tokenizeScalar(u8, include_path, ':');
|
||||
+ while (it.next()) |dir|
|
||||
+ try self.addIncludeDir(dir);
|
||||
+ } else |err| switch (err) {
|
||||
+ error.InvalidWtf8 => unreachable,
|
||||
+ error.EnvironmentVariableNotFound => {},
|
||||
+ error.OutOfMemory => |e| return e,
|
||||
+ }
|
||||
+ }
|
||||
+ if (process.getEnvVarOwned(arena, "LIBRARY_PATH")) |library_path| {
|
||||
+ var it = mem.tokenizeScalar(u8, library_path, ':');
|
||||
+ while (it.next()) |dir|
|
||||
+ try self.addLibDir(dir);
|
||||
+ } else |err| switch (err) {
|
||||
+ error.InvalidWtf8 => unreachable,
|
||||
+ error.EnvironmentVariableNotFound => {},
|
||||
+ error.OutOfMemory => |e| return e,
|
||||
+ }
|
||||
+ }
|
||||
+ return self;
|
||||
+ }
|
||||
var is_nix = false;
|
||||
if (process.getEnvVarOwned(arena, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
|
||||
is_nix = true;
|
||||
@@ -208,3 +253,11 @@ pub fn addWarningFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype
|
||||
pub fn addRPath(self: *NativePaths, s: []const u8) !void {
|
||||
try self.rpaths.append(self.arena, s);
|
||||
}
|
||||
+
|
||||
+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/src/main.zig b/src/main.zig
|
||||
index 0d239f1f99..79493aa624 100644
|
||||
--- a/src/main.zig
|
||||
+++ b/src/main.zig
|
||||
@@ -3909,7 +3909,8 @@ fn createModule(
|
||||
}
|
||||
|
||||
// Trigger native system library path detection if necessary.
|
||||
- if (create_module.sysroot == null and
|
||||
+ if (std.zig.system.NativePaths.isCrossGuix(arena) or
|
||||
+ create_module.sysroot == null and
|
||||
resolved_target.is_native_os and resolved_target.is_native_abi and
|
||||
create_module.want_native_include_dirs)
|
||||
{
|
||||
--
|
||||
2.46.0
|
||||
|
|
@ -1762,4 +1762,48 @@ (define zig-0.13.0-1952
|
|||
(modify-inputs (package-native-inputs base)
|
||||
(replace "zig" `(,base "out")))))))
|
||||
|
||||
(define zig-0.14-glibc-abi-tool
|
||||
(origin
|
||||
(method git-fetch)
|
||||
(uri (git-reference
|
||||
(url "https://github.com/ziglang/glibc-abi-tool")
|
||||
(commit "23fa2936e21ef8573d0a7c244523284fc3a17567")))
|
||||
(file-name "glibc-abi-tool")
|
||||
(sha256
|
||||
(base32 "18s08rqv457fs9jaiqf3smlkqbmpsan2rl0w6p3d59j0v1jf9cvq"))
|
||||
(modules '((guix build utils)))
|
||||
(snippet
|
||||
#~(substitute* "consolidate.zig"
|
||||
(("(const new_inc = ).*" _ prefix)
|
||||
(string-append prefix "Inclusion {"))))))
|
||||
|
||||
(define-public zig-0.14
|
||||
(let ((commit "6d67658965bc298a697dc756a4e06bda144427de")
|
||||
(revision "2580"))
|
||||
(package
|
||||
(inherit zig-0.13)
|
||||
(name "zig")
|
||||
(version (git-version "0.13.0" revision commit))
|
||||
(source
|
||||
(origin
|
||||
(inherit (zig-source
|
||||
version commit
|
||||
"0cyligjfiy465rx67hk9r2j10fyay46ql5s85d87npm633nx92n8"))
|
||||
(patches
|
||||
(search-patches
|
||||
"zig-0.14-use-baseline-cpu-by-default.patch"
|
||||
"zig-0.14-use-system-paths.patch"
|
||||
"zig-0.14-fix-runpath.patch"))))
|
||||
(inputs
|
||||
(modify-inputs (package-inputs zig-0.13)
|
||||
(replace "clang" clang-19)
|
||||
(replace "lld" lld-19)))
|
||||
(native-inputs
|
||||
(modify-inputs (package-native-inputs zig-0.13)
|
||||
(replace "glibc-abi-tool" zig-0.14-glibc-abi-tool)
|
||||
(replace "llvm" llvm-19)
|
||||
(replace "zig" `(,zig-0.13.0-1952 "zig1"))))
|
||||
(properties `((max-silent-time . 9600)
|
||||
,@(clang-compiler-cpu-architectures "19"))))))
|
||||
|
||||
(define-public zig zig-0.13)
|
||||
|
|
Loading…
Reference in a new issue