[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
60/60: DRAFT: gnu: zig: Build reproducibly.
From: |
guix-commits |
Subject: |
60/60: DRAFT: gnu: zig: Build reproducibly. |
Date: |
Mon, 18 Nov 2024 06:40:36 -0500 (EST) |
hako pushed a commit to branch wip-zig-bootstrap
in repository guix.
commit 98f3e32fc7e967fcf931f23c5af5a76da34d157f
Author: Hilton Chain <hako@ultrarare.space>
AuthorDate: Mon Nov 18 17:19:32 2024 +0800
DRAFT: gnu: zig: Build reproducibly.
* gnu/packages/patches/zig-0.10-cmake-support-libc-paths-file.patch: New
file.
* gnu/packages/patches/zig-0.11-cmake-support-libc-paths-file.patch: New
file.
* gnu/packages/patches/zig-0.12-cmake-support-libc-paths-file.patch: New
file.
* gnu/packages/patches/zig-0.13-cmake-support-libc-paths-file.patch: New
file.
* gnu/local.mk (dist_patch_DATA): Regisiter them.
* guix/build-system/zig.scm (%zig-build-system-modules): Export.
* guix/build/zig-build-system.scm (zig-target): Export.
* gnu/packages/zig.scm (zig-0.9)[arguments]: Add zig-build-system modules.
<#:configure-flags>: Set ZIG_TARGET_TRIPLE for native builds too.
<#:phases>: Apply 'configure phase from zig-build-system.
Remove 'set-cache-dir.
(zig-0.10)[source]: Add patch.
[arguments]<#:configure-flags>: Work around cross compilation issue.
(zig-0.10.0-610)[arguments]<#:configure-flags>: Remove ZIG_TARGET_TRIPLE.
(zig-0.11,zig-0.12,zig-0.13): Add patches.
Change-Id: Ie5d7d249ae7f199409136bf201d95cad2dc7a781
---
gnu/local.mk | 4 ++
.../zig-0.10-cmake-support-libc-paths-file.patch | 33 ++++++++++++++++
.../zig-0.11-cmake-support-libc-paths-file.patch | 33 ++++++++++++++++
.../zig-0.12-cmake-support-libc-paths-file.patch | 33 ++++++++++++++++
.../zig-0.13-cmake-support-libc-paths-file.patch | 33 ++++++++++++++++
gnu/packages/zig.scm | 45 +++++++++++++++++-----
guix/build-system/zig.scm | 3 +-
guix/build/zig-build-system.scm | 3 +-
8 files changed, 176 insertions(+), 11 deletions(-)
diff --git a/gnu/local.mk b/gnu/local.mk
index 56b111565c..808bcd2134 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2374,6 +2374,7 @@ dist_patch_DATA =
\
%D%/packages/patches/zig-0.9-use-baseline-cpu-by-default.patch \
%D%/packages/patches/zig-0.9-use-system-paths.patch \
%D%/packages/patches/zig-0.10-build-respect-PKG_CONFIG-env-var.patch \
+ %D%/packages/patches/zig-0.10-cmake-support-libc-paths-file.patch \
%D%/packages/patches/zig-0.10-fix-runpath.patch \
%D%/packages/patches/zig-0.10-use-system-paths.patch \
%D%/packages/patches/zig-0.10.0-610-bootstrap-resolve-conflicts.patch
\
@@ -2381,14 +2382,17 @@ dist_patch_DATA =
\
%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-build-respect-PKG_CONFIG-env-var.patch \
+ %D%/packages/patches/zig-0.11-cmake-support-libc-paths-file.patch \
%D%/packages/patches/zig-0.11-fix-runpath.patch \
%D%/packages/patches/zig-0.11-use-system-paths.patch \
%D%/packages/patches/zig-0.12-add-GUIX_ZIG_GLIBC_LINKER.patch \
%D%/packages/patches/zig-0.12-build-respect-PKG_CONFIG-env-var.patch \
+ %D%/packages/patches/zig-0.12-cmake-support-libc-paths-file.patch \
%D%/packages/patches/zig-0.12-fix-runpath.patch \
%D%/packages/patches/zig-0.12-use-baseline-cpu-by-default.patch \
%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-cmake-support-libc-paths-file.patch \
%D%/packages/patches/zsh-egrep-failing-test.patch \
%D%/packages/patches/zuo-bin-sh.patch
diff --git a/gnu/packages/patches/zig-0.10-cmake-support-libc-paths-file.patch
b/gnu/packages/patches/zig-0.10-cmake-support-libc-paths-file.patch
new file mode 100644
index 0000000000..1dc42fd14d
--- /dev/null
+++ b/gnu/packages/patches/zig-0.10-cmake-support-libc-paths-file.patch
@@ -0,0 +1,33 @@
+From a2726fb040d3852043afd46591f8ac5b126bc5fc Mon Sep 17 00:00:00 2001
+From: Hilton Chain <hako@ultrarare.space>
+Date: Mon, 18 Nov 2024 16:38:14 +0800
+Subject: [PATCH] cmake: Support libc paths file.
+
+---
+ CMakeLists.txt | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index b02677365f..24de2dc96c 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -1077,6 +1077,8 @@ elseif(MINGW)
+ target_link_libraries(zig2 ntdll)
+ endif()
+
++set(ZIG_LIBC_PATHS_FILE "" CACHE STRING "a file which specifies libc paths")
++
+ set(ZIG_BUILD_ARGS
+ --zig-lib-dir "${CMAKE_SOURCE_DIR}/lib"
+ "-Dconfig_h=${ZIG_CONFIG_H_OUT}"
+@@ -1089,6 +1091,7 @@ set(ZIG_BUILD_ARGS
+ "-Dtarget=${ZIG_TARGET_TRIPLE}"
+ "-Dcpu=${ZIG_TARGET_MCPU}"
+ "-Dversion-string=${ZIG_VERSION}"
++ --libc ${ZIG_LIBC_PATHS_FILE}
+ )
+
+ add_custom_target(stage3 ALL
+--
+2.46.0
+
diff --git a/gnu/packages/patches/zig-0.11-cmake-support-libc-paths-file.patch
b/gnu/packages/patches/zig-0.11-cmake-support-libc-paths-file.patch
new file mode 100644
index 0000000000..07b7a2baa6
--- /dev/null
+++ b/gnu/packages/patches/zig-0.11-cmake-support-libc-paths-file.patch
@@ -0,0 +1,33 @@
+From 25c75fe13126be8df6c5ae00829454c6f058f75e Mon Sep 17 00:00:00 2001
+From: Hilton Chain <hako@ultrarare.space>
+Date: Mon, 18 Nov 2024 16:39:14 +0800
+Subject: [PATCH] cmake: Support libc paths file.
+
+---
+ CMakeLists.txt | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 92be8fbfe8..d13b79d2f6 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -859,6 +859,8 @@ else()
+ set(ZIG_PIE_ARG "")
+ endif()
+
++set(ZIG_LIBC_PATHS_FILE "" CACHE STRING "a file which specifies libc paths")
++
+ # -Dno-langref is currently hardcoded because building the langref takes too
damn long
+ # -Dno-autodocs is currently hardcoded because the C backend generates a
miscompilation
+ # that prevents it from working.
+@@ -877,6 +879,7 @@ set(ZIG_BUILD_ARGS
+ "-Dtarget=${ZIG_TARGET_TRIPLE}"
+ "-Dcpu=${ZIG_TARGET_MCPU}"
+ "-Dversion-string=${RESOLVED_ZIG_VERSION}"
++ --libc ${ZIG_LIBC_PATHS_FILE}
+ )
+
+ add_custom_target(stage3 ALL
+--
+2.46.0
+
diff --git a/gnu/packages/patches/zig-0.12-cmake-support-libc-paths-file.patch
b/gnu/packages/patches/zig-0.12-cmake-support-libc-paths-file.patch
new file mode 100644
index 0000000000..0276042365
--- /dev/null
+++ b/gnu/packages/patches/zig-0.12-cmake-support-libc-paths-file.patch
@@ -0,0 +1,33 @@
+From 5d63b0f52d034a07cee2919c783526f9dac66135 Mon Sep 17 00:00:00 2001
+From: Hilton Chain <hako@ultrarare.space>
+Date: Mon, 18 Nov 2024 15:59:20 +0800
+Subject: [PATCH] cmake: Support libc paths file.
+
+---
+ CMakeLists.txt | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 8a409096e3..cf02677892 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -916,6 +916,8 @@ else()
+ set(ZIG_DYNAMIC_LINKER_ARG "-Ddynamic-linker=${ZIG_TARGET_DYNAMIC_LINKER}")
+ endif()
+
++set(ZIG_LIBC_PATHS_FILE "" CACHE STRING "a file which specifies libc paths")
++
+ # -Dno-langref is currently hardcoded because building the langref takes too
damn long
+ # To obtain these two forms of documentation, run zig build against stage3
rather than stage2.
+ set(ZIG_BUILD_ARGS
+@@ -932,6 +934,7 @@ set(ZIG_BUILD_ARGS
+ "-Dcpu=${ZIG_TARGET_MCPU}"
+ ${ZIG_DYNAMIC_LINKER_ARG}
+ "-Dversion-string=${RESOLVED_ZIG_VERSION}"
++ --libc ${ZIG_LIBC_PATHS_FILE}
+ )
+
+ add_custom_target(stage3 ALL
+--
+2.46.0
+
diff --git a/gnu/packages/patches/zig-0.13-cmake-support-libc-paths-file.patch
b/gnu/packages/patches/zig-0.13-cmake-support-libc-paths-file.patch
new file mode 100644
index 0000000000..d187bc7ddc
--- /dev/null
+++ b/gnu/packages/patches/zig-0.13-cmake-support-libc-paths-file.patch
@@ -0,0 +1,33 @@
+From b3893d5a3fca9b0a53c0cb16e8873bee30c7b6e3 Mon Sep 17 00:00:00 2001
+From: Hilton Chain <hako@ultrarare.space>
+Date: Mon, 18 Nov 2024 15:24:47 +0800
+Subject: [PATCH] cmake: Support libc paths file.
+
+---
+ CMakeLists.txt | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 22051f1902..2f44d3d01f 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -922,6 +922,7 @@ if(MSVC OR MINGW)
+ target_link_libraries(zig2 LINK_PUBLIC version)
+ endif()
+
++set(ZIG_LIBC_PATHS_FILE "" CACHE STRING "a file which specifies libc paths")
+
+ # "-Dno-langref" and "-Dstd-docs=false" are hardcoded because they take too
long to build.
+ # To obtain these two forms of documentation, run zig build against stage3
rather than stage2.
+@@ -937,6 +938,8 @@ set(ZIG_BUILD_ARGS
+
+ -Dno-langref
+ -Dstd-docs=false
++
++ --libc ${ZIG_LIBC_PATHS_FILE}
+ )
+
+ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
+--
+2.46.0
+
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
index 380f7d2ec8..2f9d6ddad5 100644
--- a/gnu/packages/zig.scm
+++ b/gnu/packages/zig.scm
@@ -22,12 +22,15 @@
(define-module (gnu packages zig)
#:use-module (guix gexp)
#:use-module (guix packages)
+ #:use-module (guix platform)
#:use-module (guix utils)
#:use-module (guix download)
#:use-module (guix git-download)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix build-system cmake)
+ #:use-module (guix build-system zig)
#:use-module (gnu packages)
+ #:use-module ((gnu packages bootstrap) #:select (glibc-dynamic-linker))
#:use-module (gnu packages compression)
#:use-module (gnu packages gcc)
#:use-module (gnu packages llvm)
@@ -69,11 +72,21 @@
(build-system cmake-build-system)
(arguments
(list
+ #:imported-modules
+ (append %zig-build-system-modules
+ %cmake-build-system-modules)
+ #:modules
+ (append '(((guix build zig-build-system) #:prefix zig:))
+ '((guix build cmake-build-system)
+ (guix build utils)))
#:configure-flags
- #~(list #$@(if (%current-target-system)
- (list (string-append "-DZIG_TARGET_TRIPLE="
- (%current-target-system)))
- '()))
+ #~(list (string-append
+ "-DZIG_TARGET_TRIPLE="
+ (zig:zig-target
+ #$(platform-target
+ (lookup-platform-by-target-or-system
+ (or (%current-target-system)
+ (%current-system)))))))
#:out-of-source? #f ; for tests
;; There are too many unclear test failures.
#:tests? (not (or (target-riscv64?)
@@ -96,11 +109,11 @@
;; Is this symbol x86 only in glibc?
((".*link_static_lib_as_system_lib.*") "")))))
'())
- (add-after 'configure 'set-cache-dir
- (lambda _
- ;; Set cache dir, otherwise Zig looks for `$HOME/.cache'.
- (setenv "ZIG_GLOBAL_CACHE_DIR"
- (string-append (getcwd) "/zig-cache"))))
+ (add-before 'configure 'zig-configure
+ (lambda* (#:rest args)
+ (apply (assoc-ref zig:%standard-phases 'configure)
+ #:zig-glibc-linker #$(glibc-dynamic-linker)
+ args)))
(delete 'check)
(add-after 'install 'check
(lambda* (#:key tests? #:allow-other-keys)
@@ -167,6 +180,7 @@ toolchain. Among other features it provides
(search-patches
"zig-0.9-add-GUIX_ZIG_GLIBC_LINKER.patch"
"zig-0.10-build-respect-PKG_CONFIG-env-var.patch"
+ "zig-0.10-cmake-support-libc-paths-file.patch"
"zig-0.10-fix-runpath.patch"
"zig-0.9-use-baseline-cpu-by-default.patch"
"zig-0.10-use-system-paths.patch"))))
@@ -177,6 +191,8 @@ toolchain. Among other features it provides
#~(cons* "-DZIG_TARGET_MCPU=baseline"
"-DZIG_SHARED_LLVM=ON"
(string-append "-DZIG_LIB_DIR=" #$output "/lib/zig")
+ "-DZIG_LIBC_PATHS_FILE=/tmp/guix-zig-libc-paths"
+ "-DZIG_USE_LLVM_CONFIG=ON"
#$flags))
((#:phases phases '%standard-phases)
#~(modify-phases #$phases
@@ -265,6 +281,14 @@ toolchain. Among other features it provides
(substitute-keyword-arguments (package-arguments base)
;; Patch for fixing RUNPATH not applied to intermediate versions.
((#:validate-runpath? _ #t) #f)
+ ;; Patch for cross-compilation not applied to intermediate versions.
+ ((#:target _ #f) #f)
+ ((#:modules modules '())
+ (cons '(srfi srfi-1) modules))
+ ((#:configure-flags flags #~())
+ #~(filter (lambda (flag)
+ (not (string-contains flag "ZIG_TARGET_TRIPLE")))
+ #$flags))
;; Disable tests for intermediate versions.
((#:tests? _ #t) #f)
((#:phases phases '%standard-phases)
@@ -1045,6 +1069,7 @@ toolchain. Among other features it provides
(search-patches
"zig-0.9-add-GUIX_ZIG_GLIBC_LINKER.patch"
"zig-0.11-build-respect-PKG_CONFIG-env-var.patch"
+ "zig-0.11-cmake-support-libc-paths-file.patch"
"zig-0.11-fix-runpath.patch"
"zig-0.9-use-baseline-cpu-by-default.patch"
"zig-0.11-use-system-paths.patch"))))
@@ -1387,6 +1412,7 @@ toolchain. Among other features it provides
(search-patches
"zig-0.12-add-GUIX_ZIG_GLIBC_LINKER.patch"
"zig-0.12-build-respect-PKG_CONFIG-env-var.patch"
+ "zig-0.12-cmake-support-libc-paths-file.patch"
"zig-0.12-fix-runpath.patch"
"zig-0.12-use-baseline-cpu-by-default.patch"
"zig-0.12-use-system-paths.patch"))))
@@ -1459,6 +1485,7 @@ toolchain. Among other features it provides
(search-patches
"zig-0.12-add-GUIX_ZIG_GLIBC_LINKER.patch"
"zig-0.13-build-respect-PKG_CONFIG-env-var.patch"
+ "zig-0.13-cmake-support-libc-paths-file.patch"
"zig-0.12-fix-runpath.patch"
"zig-0.12-use-baseline-cpu-by-default.patch"
"zig-0.12-use-system-paths.patch"))))
diff --git a/guix/build-system/zig.scm b/guix/build-system/zig.scm
index 32eaff3a51..c08ec9dd9d 100644
--- a/guix/build-system/zig.scm
+++ b/guix/build-system/zig.scm
@@ -28,7 +28,8 @@
#:use-module (guix build-system gnu)
#:use-module (ice-9 match)
#:use-module (srfi srfi-26)
- #:export (zig-build-system))
+ #:export (%zig-build-system-modules
+ zig-build-system))
(define (default-zig)
diff --git a/guix/build/zig-build-system.scm b/guix/build/zig-build-system.scm
index 8f143959e4..4bb48c786e 100644
--- a/guix/build/zig-build-system.scm
+++ b/guix/build/zig-build-system.scm
@@ -28,7 +28,8 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:export (%standard-phases
- zig-build))
+ zig-build
+ zig-target))
;; Interesting guide here:
;; https://github.com/riverwm/river/blob/master/PACKAGING.md
- 52/60: gnu: Add zig-0.11.0-3604., (continued)
- 52/60: gnu: Add zig-0.11.0-3604., guix-commits, 2024/11/18
- 44/60: gnu: Add zig-0.11.0-702., guix-commits, 2024/11/18
- 59/60: gnu: zig: Respect the PKG_CONFIG environment variable., guix-commits, 2024/11/18
- 55/60: gnu: Add zig-0.13., guix-commits, 2024/11/18
- 48/60: gnu: Add zig-0.11.0-3344., guix-commits, 2024/11/18
- 38/60: gnu: Add zig-0.11.0-149., guix-commits, 2024/11/18
- 54/60: gnu: Add zig-0.12.0-109., guix-commits, 2024/11/18
- 14/60: gnu: Add zig-0.10.0-1027., guix-commits, 2024/11/18
- 53/60: gnu: Add zig-0.12., guix-commits, 2024/11/18
- 57/60: build-system: zig: Support cross compilation., guix-commits, 2024/11/18
- 60/60: DRAFT: gnu: zig: Build reproducibly.,
guix-commits <=
- 43/60: gnu: Add zig-0.11.0-638., guix-commits, 2024/11/18