[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/57: gnu: zig-0.9: Update patch.
From: |
guix-commits |
Subject: |
02/57: gnu: zig-0.9: Update patch. |
Date: |
Wed, 13 Nov 2024 11:46:49 -0500 (EST) |
hako pushed a commit to branch wip-zig-bootstrap
in repository guix.
commit ca594d460717046c992a08bf9bda429716e58a89
Author: Hilton Chain <hako@ultrarare.space>
AuthorDate: Wed Nov 13 21:29:54 2024 +0800
gnu: zig-0.9: Update patch.
Use upstream version of the patch, additionally check "CROSS_" environment
variables.
Also set RUNPATH for directories in CROSS_LIBRARY_PATH or LIBRARY_PATH.
This
is used for working around RUNPATH issue occurred in later versions, adding
it
here for consistent behavior.
* gnu/packages/patches/zig-use-system-paths.patch: Update file.
* gnu/packages/zig.scm (zig-source): Add patches.
(zig-0.9)[source]: Use it.
[arguments]: Add shrink-runpath phase.
Change-Id: I9c9dec911e00a797a959b83ab214c129743173fd
---
gnu/packages/patches/zig-use-system-paths.patch | 185 ++++++------------------
gnu/packages/zig.scm | 39 +++--
2 files changed, 74 insertions(+), 150 deletions(-)
diff --git a/gnu/packages/patches/zig-use-system-paths.patch
b/gnu/packages/patches/zig-use-system-paths.patch
index a008beafc2..92ae035ba7 100644
--- a/gnu/packages/patches/zig-use-system-paths.patch
+++ b/gnu/packages/patches/zig-use-system-paths.patch
@@ -1,148 +1,55 @@
-This patch replaces the OS-specific detection mechanism by one that solely
-relies on environment variables. This has the benefit that said environment
-variables can be used as search paths in Guix.
+From f1f8fe4e76c8ef6b58be75991499092bdcea9b63 Mon Sep 17 00:00:00 2001
+From: Hilton Chain <hako@ultrarare.space>
+Date: Wed, 13 Nov 2024 12:46:31 +0800
+Subject: [PATCH] Use system paths.
+
+Modified from upstream commit ca1c185eb616 ("std.zig: search include dir and
lib
+dir from environment variables"), additionally adds support for "CROSS_"
+environment variables, and sets RUNPATH for directories in
+CROSS_LIBRARY_PATH (or LIBRARY_PATH).
+---
+ lib/std/zig/system/NativePaths.zig | 28 ++++++++++++++++++++++++++++
+ 1 file changed, 28 insertions(+)
diff --git a/lib/std/zig/system/NativePaths.zig
b/lib/std/zig/system/NativePaths.zig
-index 8e3e46e48..1ed9d3206 100644
+index 8e3e46e481..9787ef2329 100644
--- a/lib/std/zig/system/NativePaths.zig
+++ b/lib/std/zig/system/NativePaths.zig
-@@ -26,73 +26,42 @@ pub fn detect(allocator: Allocator, native_info:
NativeTargetInfo) !NativePaths
- };
- errdefer self.deinit();
-
-- var is_nix = false;
-- if (process.getEnvVarOwned(allocator, "NIX_CFLAGS_COMPILE"))
|nix_cflags_compile| {
-- defer allocator.free(nix_cflags_compile);
--
-- is_nix = true;
-- var it = mem.tokenize(u8, nix_cflags_compile, " ");
-+ // TODO: Support cross-compile paths?
-+ if (process.getEnvVarOwned(allocator, "C_INCLUDE_PATH")) |c_include_path|
{
-+ defer allocator.free(c_include_path);
-+ var it = mem.tokenize(u8, c_include_path, ":");
- while (true) {
-- const word = it.next() orelse break;
-- if (mem.eql(u8, word, "-isystem")) {
-- const include_path = it.next() orelse {
-- try self.addWarning("Expected argument after -isystem in
NIX_CFLAGS_COMPILE");
-- break;
-- };
-- try self.addIncludeDir(include_path);
-- } else {
-- if (mem.startsWith(u8, word, "-frandom-seed=")) {
-- continue;
-- }
-- try self.addWarningFmt("Unrecognized C flag from
NIX_CFLAGS_COMPILE: {s}", .{word});
-- }
-+ const dir = it.next() orelse break;
-+ try self.addIncludeDir(dir);
- }
- } else |err| switch (err) {
- error.InvalidUtf8 => {},
- error.EnvironmentVariableNotFound => {},
- error.OutOfMemory => |e| return e,
- }
-- if (process.getEnvVarOwned(allocator, "NIX_LDFLAGS")) |nix_ldflags| {
-- defer allocator.free(nix_ldflags);
--
-- is_nix = true;
-- var it = mem.tokenize(u8, nix_ldflags, " ");
-+ if (process.getEnvVarOwned(allocator, "CPLUS_INCLUDE_PATH"))
|cplus_include_path| {
-+ defer allocator.free(cplus_include_path);
-+ var it = mem.tokenize(u8, cplus_include_path, ":");
- while (true) {
-- const word = it.next() orelse break;
-- if (mem.eql(u8, word, "-rpath")) {
-- const rpath = it.next() orelse {
-- try self.addWarning("Expected argument after -rpath in
NIX_LDFLAGS");
-- break;
-- };
-- try self.addRPath(rpath);
-- } else if (word.len > 2 and word[0] == '-' and word[1] == 'L') {
-- const lib_path = word[2..];
-- try self.addLibDir(lib_path);
-- } else {
-- try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS:
{s}", .{word});
-- break;
-- }
-+ const dir = it.next() orelse break;
-+ try self.addIncludeDir(dir);
- }
- } else |err| switch (err) {
- error.InvalidUtf8 => {},
- error.EnvironmentVariableNotFound => {},
- error.OutOfMemory => |e| return e,
- }
-- if (is_nix) {
-- return self;
-- }
--
-- if (comptime builtin.target.isDarwin()) {
-- try self.addIncludeDir("/usr/include");
-- try self.addIncludeDir("/usr/local/include");
--
-- try self.addLibDir("/usr/lib");
-- try self.addLibDir("/usr/local/lib");
--
-- try self.addFrameworkDir("/Library/Frameworks");
-- try self.addFrameworkDir("/System/Library/Frameworks");
--
-- return self;
-+ if (process.getEnvVarOwned(allocator, "LIBRARY_PATH")) |library_path| {
-+ defer allocator.free(library_path);
-+ var it = mem.tokenize(u8, library_path, ":");
-+ while (true) {
-+ const dir = it.next() orelse break;
-+ try self.addLibDir(dir);
+@@ -132,6 +132,34 @@ pub fn detect(allocator: Allocator, native_info:
NativeTargetInfo) !NativePaths
+ // zlib.h is in /usr/include (added above)
+ // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
+ try self.addLibDirFmt("/lib/{s}", .{triple});
++
++ // NOTE: distro like guix doesn't use FHS, so it relies on envorinment
++ // variables (C_INCLUDE_PATH, CPLUS_INCLUDE_PATH and LIBRARY_PATH) to
++ // search for headers and libraries
++ // NOTE: we use os.getenv here since this part won't be executed on
++ // windows, to get rid of unnecessary error handling
++ if (std.os.getenv("CROSS_C_INCLUDE_PATH") orelse
std.os.getenv("C_INCLUDE_PATH")) |c_include_path|
++ {
++ var it = mem.tokenize(u8, c_include_path, ":");
++ while (it.next()) |dir| {
++ try self.addIncludeDir(dir);
++ }
+ }
-+ } else |err| switch (err) {
-+ error.InvalidUtf8 => {},
-+ error.EnvironmentVariableNotFound => {},
-+ error.OutOfMemory => |e| return e,
- }
-
- if (comptime native_target.os.tag == .solaris) {
-@@ -106,32 +75,17 @@ pub fn detect(allocator: Allocator, native_info:
NativeTargetInfo) !NativePaths
- return self;
- }
-
-- if (native_target.os.tag != .windows) {
-- const triple = try native_target.linuxTriple(allocator);
-- const qual = native_target.cpu.arch.ptrBitWidth();
--
-- // TODO: $ ld --verbose | grep SEARCH_DIR
-- // the output contains some paths that end with lib64, maybe include
them too?
-- // TODO: what is the best possible order of things?
-- // TODO: some of these are suspect and should only be added on some
systems. audit needed.
--
-- try self.addIncludeDir("/usr/local/include");
-- try self.addLibDirFmt("/usr/local/lib{d}", .{qual});
-- try self.addLibDir("/usr/local/lib");
--
-- try self.addIncludeDirFmt("/usr/include/{s}", .{triple});
-- try self.addLibDirFmt("/usr/lib/{s}", .{triple});
--
-- try self.addIncludeDir("/usr/include");
-- try self.addLibDirFmt("/lib{d}", .{qual});
-- try self.addLibDir("/lib");
-- try self.addLibDirFmt("/usr/lib{d}", .{qual});
-- try self.addLibDir("/usr/lib");
--
-- // example: on a 64-bit debian-based linux distro, with zlib
installed from apt:
-- // zlib.h is in /usr/include (added above)
-- // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
-- try self.addLibDirFmt("/lib/{s}", .{triple});
-+ if (process.getEnvVarOwned(allocator, "DYLD_FRAMEWORK_PATH"))
|dyld_framework_path| {
-+ defer allocator.free(dyld_framework_path);
-+ var it = mem.tokenize(u8, dyld_framework_path, ":");
-+ while (true) {
-+ const dir = it.next() orelse break;
-+ try self.addFrameworkDir(dir);
++
++ if (std.os.getenv("CROSS_CPLUS_INCLUDE_PATH") orelse
std.os.getenv("CPLUS_INCLUDE_PATH")) |cplus_include_path| {
++ var it = mem.tokenize(u8, cplus_include_path, ":");
++ while (it.next()) |dir| {
++ try self.addIncludeDir(dir);
++ }
++ }
++
++ if (std.os.getenv("CROSS_LIBRARY_PATH") orelse
std.os.getenv("LIBRARY_PATH")) |library_path| {
++ var it = mem.tokenize(u8, library_path, ":");
++ while (it.next()) |dir| {
++ try self.addLibDir(dir);
++ try self.addRPath(dir);
++ }
+ }
-+ } else |err| switch (err) {
-+ error.InvalidUtf8 => {},
-+ error.EnvironmentVariableNotFound => {},
-+ error.OutOfMemory => |e| return e,
}
return self;
+--
+2.46.0
+
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
index bae66a4692..cd8d5fbe3f 100644
--- a/gnu/packages/zig.scm
+++ b/gnu/packages/zig.scm
@@ -26,6 +26,7 @@
#:use-module (guix git-download)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix build-system cmake)
+ #:use-module (guix build-system meson)
#:use-module (gnu packages)
#:use-module (gnu packages compression)
#:use-module (gnu packages llvm)
@@ -39,6 +40,14 @@
(commit commit)))
(file-name (git-file-name "zig" version))
(sha256 (base32 hash))
+ (patches
+ (append
+ (search-patches "zig-use-baseline-cpu-by-default.patch")
+ ;; FIXME: Workaround RUNPATH issue by adding all paths in
+ ;; CROSS_LIBRARY_PATH or LIBRARY_PATH environment variable to RUNPATH.
+ ;; This is meant to be handled with a 'shrink-runpath' build phase.
+ ;; May be related: <https://github.com/ziglang/zig/issues/18434>.
+ (search-patches "zig-use-system-paths.patch")))
(snippet
#~(for-each (lambda (file)
(when (file-exists? file)
@@ -51,19 +60,25 @@
(name "zig")
(version "0.9.1")
(source
- (origin
- (method git-fetch)
- (uri (git-reference
- (url "https://github.com/ziglang/zig.git")
- (commit version)))
- (file-name (git-file-name name version))
- (sha256
- (base32 "0nfvgg23sw50ksy0z0ml6lkdsvmd0278mq29m23dbb2jsirkhry7"))
- (patches (search-patches "zig-0.9-riscv-support.patch"
- "zig-use-system-paths.patch"))))
+ (let ((base (zig-source
+ version version
+ "0nfvgg23sw50ksy0z0ml6lkdsvmd0278mq29m23dbb2jsirkhry7")))
+ (origin
+ (inherit base)
+ (patches
+ (append (origin-patches base)
+ (search-patches "zig-0.9-riscv-support.patch"))))))
(build-system cmake-build-system)
(arguments
(list
+ ;; TODO: Move shrink-runpath to (guix build utils).
+ #:imported-modules
+ (append %meson-build-system-modules
+ %cmake-build-system-modules)
+ #:modules
+ (cons '((guix build meson-build-system) #:prefix meson:)
+ '((guix build cmake-build-system)
+ (guix build utils)))
#:configure-flags
#~(list #$@(if (%current-target-system)
(list (string-append "-DZIG_TARGET_TRIPLE="
@@ -110,7 +125,9 @@
"-Dskip-stage2-tests"
;; Non-native tests try to link and execute non-native
;; binaries.
- "-Dskip-non-native")))))))
+ "-Dskip-non-native"))))
+ (add-after 'strip 'shrink-runpath
+ (assoc-ref meson:%standard-phases 'shrink-runpath)))))
(inputs
(list clang-13 ;Clang propagates llvm.
lld-13))
- branch wip-zig-bootstrap created (now 3243e3f231), guix-commits, 2024/11/13
- 05/57: gnu: zig-0.10: Adjust package style., guix-commits, 2024/11/13
- 09/57: gnu: Add zig-0.10.0-747., guix-commits, 2024/11/13
- 13/57: gnu: Add zig-0.10.0-961., guix-commits, 2024/11/13
- 18/57: gnu: Add zig-0.10.0-1506., guix-commits, 2024/11/13
- 02/57: gnu: zig-0.9: Update patch.,
guix-commits <=
- 01/57: gnu: zig: Add 'zig-source' procedure., guix-commits, 2024/11/13
- 21/57: gnu: Add zig-0.10.0-1681., guix-commits, 2024/11/13
- 34/57: gnu: Add zig-0.10.0-3807., guix-commits, 2024/11/13
- 32/57: gnu: Add zig-0.10.0-3726., guix-commits, 2024/11/13
- 45/57: gnu: Add zig-0.11.0-702., guix-commits, 2024/11/13
- 42/57: gnu: Add zig-0.11.0-587., guix-commits, 2024/11/13
- 53/57: gnu: Add zig-0.11.0-3604., guix-commits, 2024/11/13
- 04/57: build-system: zig: Add shrink-runpath phase., guix-commits, 2024/11/13
- 11/57: gnu: Add zig-0.10.0-851., guix-commits, 2024/11/13
- 03/57: gnu: zig-0.10: Workaround RUNPATH issue., guix-commits, 2024/11/13