guix-commits
[Top][All Lists]
Advanced

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

02/04: DRAFT: build-system: zig: Support cross compilation.


From: guix-commits
Subject: 02/04: DRAFT: build-system: zig: Support cross compilation.
Date: Sat, 16 Nov 2024 13:53:58 -0500 (EST)

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

commit 627ab700eb96d585933da10ba9a3f72a67f3fbb8
Author: Hilton Chain <hako@ultrarare.space>
AuthorDate: Sun Nov 17 02:42:35 2024 +0800

    DRAFT: build-system: zig: Support cross compilation.
    
    * guix/build/zig-build-system.scm (set-guix-zig-libc-dir)
    (write-zig-libc-paths-file): New procedures.
    (build): Add "--libc" argument.
    (set-cc): Delete procedure.
    (%standard-phases): Adjust accordingly.
    
    Change-Id: I08d15add2b249f7016f9cbb07f151ecf469fe656
---
 guix/build/zig-build-system.scm | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/guix/build/zig-build-system.scm b/guix/build/zig-build-system.scm
index 8352a73324..1971a3be65 100644
--- a/guix/build/zig-build-system.scm
+++ b/guix/build/zig-build-system.scm
@@ -34,15 +34,31 @@
 ;; https://github.com/riverwm/river/blob/master/PACKAGING.md
 (define global-cache-dir "zig-cache")
 
-(define* (set-cc #:rest args)
-  ;; TODO: Zig needs the gcc-toolchain in order to find the libc.
-  ;;       we need to think about how to solve this in the build system
-  ;;       directly: --libc
-  (setenv "CC" "gcc"))
-
 (define* (set-zig-global-cache-dir #:rest args)
   (setenv "ZIG_GLOBAL_CACHE_DIR" global-cache-dir))
 
+(define* (set-guix-zig-libc-dir #:key inputs target #:allow-other-keys)
+  (let ((libc (if target
+                  (assoc-ref inputs "cross-libc")
+                  (assoc-ref inputs "libc"))))
+    (setenv "GUIX_ZIG_LIBC_DIR" libc)))
+
+(define* (write-zig-libc-paths-file #:key inputs target #:allow-other-keys)
+  (let ((port (open-file "/tmp/guix-zig-libc-paths" "w" #:encoding "utf8"))
+        (libc (if target
+                  (assoc-ref inputs "cross-libc")
+                  (assoc-ref inputs "libc"))))
+    (display
+     (string-append "\
+include_dir=" libc "/include
+sys_include_dir=" libc "/include
+crt_dir=" libc "/lib
+msvc_lib_dir=
+kernel32_lib_dir=
+gcc_dir=")
+     port)
+    (close-port port)))
+
 (define* (build #:key
                 zig-build-flags
                 zig-release-type       ;; "safe", "fast" or "small" empty for a
@@ -63,6 +79,7 @@
                      ,@(if zig-release-type
                          (list (string-append "-Drelease-" zig-release-type))
                          '())
+                     "--libc" "/tmp/guix-zig-libc-paths"
                      ,@zig-build-flags)))
   (format #t "running: ~s~%" call)
   (apply invoke call)))
@@ -93,7 +110,8 @@
     (delete 'bootstrap)
     (delete 'configure)
     (add-before 'build 'set-zig-global-cache-dir set-zig-global-cache-dir)
-    (add-before 'build 'set-cc set-cc)
+    (add-before 'build 'set-guix-zig-libc-dir set-guix-zig-libc-dir)
+    (add-before 'build 'write-zig-libc-paths-file write-zig-libc-paths-file)
     (replace 'build build)
     (replace 'check check)
     (replace 'install install)))



reply via email to

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