guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

37/73: gnu: Add zig-0.11.


From: guix-commits
Subject: 37/73: gnu: Add zig-0.11.
Date: Thu, 28 Nov 2024 05:50:09 -0500 (EST)

hako pushed a commit to branch wip-zig-bootstrap
in repository guix.

commit 3f84b410a4758d94e860caba744885258c6a9329
Author: Hilton Chain <hako@ultrarare.space>
AuthorDate: Mon Nov 11 11:10:16 2024 +0800

    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): New variable.
    
    Change-Id: I2507af62918f3989967d55dec942b84655d6d8bd
---
 gnu/local.mk                                       |   2 +
 gnu/packages/patches/zig-0.11-fix-runpath.patch    |  45 +++++++
 .../patches/zig-0.11-use-system-paths.patch        | 140 +++++++++++++++++++++
 gnu/packages/zig.scm                               |  54 ++++++++
 4 files changed, 241 insertions(+)

diff --git a/gnu/local.mk b/gnu/local.mk
index 80bd220938..244022af8a 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2373,6 +2373,8 @@ dist_patch_DATA =                                         
\
   %D%/packages/patches/zig-0.10.0-675-TypeOf-hack.patch                \
   %D%/packages/patches/zig-0.10.0-747-CallOptions.patch                \
   %D%/packages/patches/zig-0.10.0-1638-re-add-qualCast.patch   \
+  %D%/packages/patches/zig-0.11-fix-runpath.patch              \
+  %D%/packages/patches/zig-0.11-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.11-fix-runpath.patch 
b/gnu/packages/patches/zig-0.11-fix-runpath.patch
new file mode 100644
index 0000000000..ee905680c3
--- /dev/null
+++ b/gnu/packages/patches/zig-0.11-fix-runpath.patch
@@ -0,0 +1,45 @@
+From aee890054e4d463665be8a7df11b1ab0ee36c080 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 +-
+ src/link/Elf.zig    | 6 ++++++
+ 2 files changed, 7 insertions(+), 1 deletion(-)
+
+diff --git a/src/Compilation.zig b/src/Compilation.zig
+index a08c3e09f4..add374d0ba 100644
+--- a/src/Compilation.zig
++++ b/src/Compilation.zig
+@@ -1542,7 +1542,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 false,
++            .each_lib_rpath = std.zig.system.NativePaths.isGuix(arena) or 
options.each_lib_rpath orelse false,
+             .build_id = build_id,
+             .cache_mode = cache_mode,
+             .disable_lld_caching = options.disable_lld_caching or cache_mode 
== .whole,
+diff --git a/src/link/Elf.zig b/src/link/Elf.zig
+index dd88d47fab..b6e3944725 100644
+--- a/src/link/Elf.zig
++++ b/src/link/Elf.zig
+@@ -1730,6 +1730,12 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, 
prog_node: *std.Progress.Node) !v
+                     }
+                 }
+             }
++            if (self.base.options.link_libc and self.base.options.link_mode 
== .Dynamic) {
++                if (self.base.options.libc_installation) |libc_installation| {
++                    try argv.append("-rpath");
++                    try argv.append(libc_installation.crt_dir.?);
++                }
++            }
+         }
+ 
+         for (self.base.options.lib_dirs) |lib_dir| {
+-- 
+2.46.0
+
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 0000000000..170e2e41a3
--- /dev/null
+++ b/gnu/packages/patches/zig-0.11-use-system-paths.patch
@@ -0,0 +1,140 @@
+From bee48c5a95aef75405a52ceffe0d96c544926e64 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      | 61 +++++++++++++++++++++++++
+ lib/std/zig/system/NativeTargetInfo.zig | 25 ++++++++--
+ src/main.zig                            |  2 +-
+ 3 files changed, 83 insertions(+), 5 deletions(-)
+
+diff --git a/lib/std/zig/system/NativePaths.zig 
b/lib/std/zig/system/NativePaths.zig
+index 4c8f1286b8..57b67e3f67 100644
+--- a/lib/std/zig/system/NativePaths.zig
++++ b/lib/std/zig/system/NativePaths.zig
+@@ -17,6 +17,10 @@ warnings: std.ArrayListUnmanaged([]const u8) = .{},
+ pub fn detect(arena: Allocator, native_info: NativeTargetInfo) !NativePaths {
+     const native_target = native_info.target;
+     var self: NativePaths = .{ .arena = arena };
++    if (isGuix(arena)) {
++        try self.addGuixPaths(arena);
++        return self;
++    }
+     var is_nix = false;
+     if (process.getEnvVarOwned(arena, "NIX_CFLAGS_COMPILE")) 
|nix_cflags_compile| {
+         is_nix = true;
+@@ -196,3 +200,60 @@ 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;
++}
++
++const guix_paths = [_][]const u8{ "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH", 
"LIBRARY_PATH" };
++const guix_cross_paths = [_][]const u8{ "CROSS_C_INCLUDE_PATH", 
"CROSS_CPLUS_INCLUDE_PATH", "CROSS_LIBRARY_PATH" };
++
++fn addGuixPaths(self: *NativePaths, arena: Allocator) !void {
++    for (guix_cross_paths[0..2]) |env_var| {
++        if (process.getEnvVarOwned(arena, env_var)) |dirs| {
++            var it = mem.tokenizeScalar(u8, dirs, ':');
++            while (it.next()) |dir|
++                try self.addIncludeDir(dir);
++        } else |err| switch (err) {
++            error.InvalidUtf8 => {},
++            error.EnvironmentVariableNotFound => {},
++            error.OutOfMemory => |e| return e,
++        }
++    }
++    if (process.getEnvVarOwned(arena, guix_cross_paths[2])) |dirs| {
++        var it = mem.tokenizeScalar(u8, dirs, ':');
++        while (it.next()) |dir|
++            try self.addLibDir(dir);
++    } else |err| switch (err) {
++        error.InvalidUtf8 => {},
++        error.EnvironmentVariableNotFound => {},
++        error.OutOfMemory => |e| return e,
++    }
++
++    if (!isCrossGuix(arena)) {
++        for (guix_paths[0..2]) |env_var| {
++            if (process.getEnvVarOwned(arena, env_var)) |dirs| {
++                var it = mem.tokenizeScalar(u8, dirs, ':');
++                while (it.next()) |dir|
++                    try self.addIncludeDir(dir);
++            } else |err| switch (err) {
++                error.InvalidUtf8 => {},
++                error.EnvironmentVariableNotFound => {},
++                error.OutOfMemory => |e| return e,
++            }
++        }
++        if (process.getEnvVarOwned(arena, guix_paths[2])) |dirs| {
++            var it = mem.tokenizeScalar(u8, dirs, ':');
++            while (it.next()) |dir|
++                try self.addLibDir(dir);
++        } else |err| switch (err) {
++            error.InvalidUtf8 => {},
++            error.EnvironmentVariableNotFound => {},
++            error.OutOfMemory => |e| return e,
++        }
++    }
++}
+diff --git a/lib/std/zig/system/NativeTargetInfo.zig 
b/lib/std/zig/system/NativeTargetInfo.zig
+index 99a1a8f2ef..6464237e49 100644
+--- a/lib/std/zig/system/NativeTargetInfo.zig
++++ b/lib/std/zig/system/NativeTargetInfo.zig
+@@ -923,10 +923,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 or (builtin.os.tag == .wasi 
and !builtin.link_libc))) {
++                    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.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 cross_target.dynamic_linker,
+     };
+ }
+ 
+diff --git a/src/main.zig b/src/main.zig
+index 456886c915..cd6634b4c9 100644
+--- a/src/main.zig
++++ b/src/main.zig
+@@ -2674,7 +2674,7 @@ fn buildOutputType(
+     // After this point, external_system_libs is used instead of system_libs.
+ 
+     // Trigger native system library path detection if necessary.
+-    if (sysroot == null and cross_target.isNativeOs() and 
cross_target.isNativeAbi() and
++    if (std.zig.system.NativePaths.isCrossGuix(arena) or sysroot == null and 
cross_target.isNativeOs() and cross_target.isNativeAbi() and
+         (external_system_libs.len != 0 or want_native_include_dirs))
+     {
+         const paths = std.zig.system.NativePaths.detect(arena, target_info) 
catch |err| {
+-- 
+2.46.0
+
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
index 53ac137133..cc5b633ce2 100644
--- a/gnu/packages/zig.scm
+++ b/gnu/packages/zig.scm
@@ -29,6 +29,7 @@
   #:use-module (guix build-system cmake)
   #:use-module (gnu packages)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages gcc)
   #:use-module (gnu packages llvm)
   #:use-module (gnu packages llvm-meta)
   #:use-module (gnu packages web))
@@ -1031,4 +1032,57 @@ toolchain.  Among other features it provides
        (modify-inputs (package-native-inputs base)
          (replace "zig" `(,base "out")))))))
 
+(define-public zig-0.11
+  (package
+    (inherit zig-0.10)
+    (name "zig")
+    (version "0.11.0")
+    (source
+     (origin
+       (inherit (zig-source
+                 version version
+                 "0qh7c27cd4wcdjj0mbpkarvwypfk1js8hkyxs0z149qv75zkbrca"))
+       (patches
+        (search-patches
+         "zig-0.9-use-baseline-cpu-by-default.patch"
+         "zig-0.11-use-system-paths.patch"
+         "zig-0.11-fix-runpath.patch"))))
+    (arguments
+     (substitute-keyword-arguments (package-arguments zig-0.10)
+       ((#:phases phases '%standard-phases)
+        #~(modify-phases #$phases
+            (add-after 'unpack 'prepare-source
+              (lambda* (#:key native-inputs inputs #:allow-other-keys)
+                (install-file (search-input-file
+                               (or native-inputs inputs) "bin/zig1.wasm")
+                              "stage1")
+                (make-file-writable "stage1/zig1.wasm")))
+            (add-after 'install 'build-zig1
+              (lambda _
+                (invoke (string-append #$output "/bin/zig")
+                        "build" "update-zig1" "--verbose")))
+            (add-after 'build-zig1 'install-zig1
+              (lambda _
+                (install-file "stage1/zig1.wasm"
+                              (string-append #$output:zig1 "/bin"))))
+            ;; TODO: Disable tests for macOS target and run full test.
+            ;; Issue with glibc in CPLUS_INCLUDE_PATH:
+            ;; <https://github.com/ziglang/zig/issues/18063>.
+            (replace 'check
+              (lambda* (#:key tests? #:allow-other-keys)
+                (when tests?
+                  (invoke (string-append #$output "/bin/zig")
+                          "test" "-I" "test" "test/behavior.zig"))))))))
+    (inputs
+     (modify-inputs (package-inputs zig-0.10)
+       (replace "clang" clang-16)
+       (replace "lld" lld-16)))
+    (native-inputs
+     (modify-inputs (package-native-inputs zig-0.10)
+       (prepend binaryen `(,zig-0.10.0-3985 "zig1"))
+       (replace "llvm" llvm-16)))
+    (outputs '("out" "zig1"))
+    (properties `((max-silent-time . 9600)
+                  ,@(clang-compiler-cpu-architectures "16")))))
+
 (define-public zig zig-0.10)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]