[PATCH] gnu: Add cross-clang.

  • Open
  • quality assurance status badge
Details
4 participants
  • Julien Lepiller
  • Ludovic Courtès
  • Maxime Devos
  • Pierre Langlois
Owner
unassigned
Submitted by
Julien Lepiller
Severity
normal
J
J
Julien Lepiller wrote on 3 Mar 2022 17:02
(address . guix-patches@gnu.org)
20220303170252.3caec0a6@tachikoma.lepiller.eu
Hi Guix!

This small patch series adds cross-clang, a cross-compiler version of
clang. Clang doesn't really make a distinction between a native and a
cross-build, it is already a cross-compiler, but this ensures that:

1. it actually works
2. it targets (%current-target-architecture) by default

The rest of the series ensures that libcxx and libcxxabi can be
cross-compiled with it.
J
J
Julien Lepiller wrote on 3 Mar 2022 17:07
[PATCH 1/5] gnu: Add cross-llvm.
(address . 54239@debbugs.gnu.org)
499e5dba47ef40df93a8b33fbb8e41cc2354e7a1.1646322873.git.julien@lepiller.eu
* gnu/packages/llvm.scm (cross-llvm): New variable.
---
gnu/packages/llvm.scm | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)

Toggle diff (48 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index eb949bed1b..d6e9846699 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -18,7 +18,7 @@
;;; Copyright © 2020 Jakub K?dzio?ka <kuba@kadziolka.net>
;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
-;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu>
+;;; Copyright © 2021, 2022 Julien Lepiller <julien@lepiller.eu>
;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net>
;;; Copyright © 2021 Guillaume Le Vaillant <glv@posteo.net>
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
@@ -74,7 +74,8 @@ (define-module (gnu packages llvm)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (make-lld-wrapper
- system->llvm-target))
+ system->llvm-target
+ cross-llvm))
(define* (system->llvm-target #:optional
(system (or (and=> (%current-target-system)
@@ -99,6 +100,22 @@ (define* (system->llvm-target #:optional
("i686" => "X86")
("i586" => "X86"))))
+(define (cross-llvm llvm target)
+ "Return a native LLVM package that targets a different system. The resulting
+libraries are running on the host but target a different system by default.
+This packge can be used to control clang's default target."
+ (package
+ (inherit llvm)
+ (arguments
+ (substitute-keyword-arguments (package-arguments llvm)
+ ((#:configure-flags flags)
+ #~(append
+ (list
+ (string-append "-DLLVM_DEFAULT_TARGET_TRIPLE=" #$target)
+ (string-append "-DLLVM_TARGET_ARCH="
+ #$(system->llvm-target (gnu-triplet->nix-system target))))
+ #$flags))))))
+
(define (llvm-uri component version)
;; LLVM release candidate file names are formatted 'tool-A.B.C-rcN/tool-A.B.CrcN.src.tar.xz'
;; so we specify the version as A.B.C-rcN and delete the hyphen when referencing the file name.
--
2.34.0
J
J
Julien Lepiller wrote on 3 Mar 2022 17:07
[PATCH 2/5] gnu: Add cross-clang.
(address . 54239@debbugs.gnu.org)
ce088a32bd3493e881efd5a2bb789eaa08e4609a.1646322873.git.julien@lepiller.eu
* gnu/packages/llvm.scm (cross-clang): New variable.
---
gnu/packages/llvm.scm | 125 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 124 insertions(+), 1 deletion(-)

Toggle diff (152 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index d6e9846699..c02f8e5c7a 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -54,6 +54,7 @@ (define-module (gnu packages llvm)
#:use-module (guix build-system trivial)
#:use-module (gnu packages)
#:use-module (gnu packages base)
+ #:use-module (gnu packages cross-base)
#:use-module (gnu packages gcc)
#:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
#:use-module (gnu packages check) ;python-lit
@@ -75,7 +76,8 @@ (define-module (gnu packages llvm)
#:use-module (ice-9 match)
#:export (make-lld-wrapper
system->llvm-target
- cross-llvm))
+ cross-llvm
+ cross-clang))
(define* (system->llvm-target #:optional
(system (or (and=> (%current-target-system)
@@ -1023,6 +1025,127 @@ (define-public clang-runtime clang-runtime-13)
(define-public clang clang-13)
(define-public clang-toolchain clang-toolchain-13)
+(define* (cross-clang target
+ #:optional
+ (libc (cross-libc target))
+ (xgcc (cross-gcc target
+ #:xbinutils (cross-binutils target)
+ #:libc (cross-libc target)))
+ (clang clang))
+ "Return a cross-clang compiler for target."
+ (package
+ (inherit clang)
+ (version (package-version clang))
+ ;; Support the same variables as clang, even in cross-compilation context.
+ ;; Clang does not make a difference between native and cross-compilation.
+ (search-paths
+ (append
+ (list
+ (search-path-specification
+ (variable "CROSS_LIBRARY_PATH")
+ (files '("lib" "lib64"))))
+ (package-native-search-paths clang)))
+ (native-search-paths '())
+ (arguments
+ (substitute-keyword-arguments (package-arguments clang)
+ ((#:configure-flags _)
+ `(list "-DCLANG_INCLUDE_TESTS=True"
+ (string-append "-DGCC_INSTALL_PREFIX="
+ (assoc-ref %build-inputs "cross-gcc-lib"))
+ (string-append "-DC_INCLUDE_DIRS="
+ (assoc-ref %build-inputs "target-libc")
+ "/include")))
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (add-after 'unpack 'add-missing-libdir
+ (lambda _
+ ;; cross-gcc installs its libraries in <target>/lib instead of
+ ;; lib.
+ (substitute* "lib/Driver/ToolChain.cpp"
+ (("\"-L\"\\) \\+ LibPath\\)\\);")
+ ,(string-append "\"-L\") + LibPath));
+ CmdArgs.push_back(Args.MakeArgString(StringRef(\"-L\") + "
+ "StringRef(GCC_INSTALL_PREFIX) + StringRef(\"/"
+ target "/lib\")));
+ CmdArgs.push_back(Args.MakeArgString(StringRef(\"-rpath=\") + "
+ "StringRef(GCC_INSTALL_PREFIX) + StringRef(\"/"
+ target "/lib\")));")))))
+ (add-after 'unpack 'support-cross-library-path
+ (lambda _
+ ;; LIBRARY_PATH is only supported for native builds, but we still
+ ;; need it (or CROSS_LIBRARY_PATH to be precise) when
+ ;; cross-compiling
+ (substitute* "lib/Driver/ToolChains/CommonArgs.cpp"
+ (("LIBRARY_PATH\"")
+ "LIBRARY_PATH\");
+ } else {
+ addDirectoryList(Args, CmdArgs, \"-L\", \"CROSS_LIBRARY_PATH\""))))
+ (replace 'set-glibc-file-names
+ (lambda* (#:key inputs #:allow-other-keys)
+ (let ((libc (assoc-ref inputs "target-libc"))
+ (compiler-rt (assoc-ref inputs "clang-runtime"))
+ (gcc (assoc-ref inputs "cross-gcc")))
+ (setenv "LIBRARY_PATH"
+ (string-append
+ (assoc-ref inputs "libc") "/lib:" (getenv "LIBRARY_PATH")))
+ ,@(cond
+ ((version>=? version "6.0")
+ `(;; Link to libclang_rt files from clang-runtime.
+ (substitute* "lib/Driver/ToolChain.cpp"
+ (("getDriver\\(\\)\\.ResourceDir")
+ (string-append "\"" compiler-rt "\"")))
+
+ ;; Make "LibDir" refer to <glibc>/lib so that it
+ ;; uses the right dynamic linker file name.
+ (substitute* "lib/Driver/ToolChains/Linux.cpp"
+ (("(^[[:blank:]]+LibDir = ).*" _ declaration)
+ (string-append declaration "\"" libc "/lib\";\n"))
+
+ ;; Make clang look for libstdc++ in the right
+ ;; location.
+ (("LibStdCXXIncludePathCandidates\\[\\] = \\{")
+ (string-append
+ "LibStdCXXIncludePathCandidates[] = { \"" gcc
+ "/include/c++\","))
+
+ ;; Make sure libc's libdir is on the search path, to
+ ;; allow crt1.o & co. to be found.
+ (("@GLIBC_LIBDIR@")
+ (string-append libc "/lib")))))
+ (else
+ `((substitute* "lib/Driver/Tools.cpp"
+ ;; Patch the 'getLinuxDynamicLinker' function so that
+ ;; it uses the right dynamic linker file name.
+ (("/lib64/ld-linux-x86-64.so.2")
+ (string-append libc ,(glibc-dynamic-linker))))
+
+ ;; Link to libclang_rt files from clang-runtime.
+ ;; This substitution needed slight adjustment in 3.8.
+ ,@(if (version>=? version "3.8")
+ '((substitute* "lib/Driver/Tools.cpp"
+ (("TC\\.getDriver\\(\\)\\.ResourceDir")
+ (string-append "\"" compiler-rt "\""))))
+ '((substitute* "lib/Driver/ToolChain.cpp"
+ (("getDriver\\(\\)\\.ResourceDir")
+ (string-append "\"" compiler-rt "\"")))))
+
+ ;; Make sure libc's libdir is on the search path, to
+ ;; allow crt1.o & co. to be found.
+ (substitute* "lib/Driver/ToolChains.cpp"
+ (("@GLIBC_LIBDIR@")
+ (string-append libc "/lib")))))))))))))
+ (inputs
+ `(("target-libc" ,libc)
+ ("cross-gcc-lib" ,xgcc "lib")
+ ("cross-gcc" ,xgcc)
+ ,@(package-inputs clang)))
+ (propagated-inputs
+ (modify-inputs (package-propagated-inputs clang)
+ (replace "llvm"
+ (cross-llvm
+ (car (assoc-ref (package-propagated-inputs clang) "llvm"))
+ target))))))
+
(define-public llvm-for-rocm
(package
;; Actually based on LLVM 13 as of v4.3, but llvm-12 works just fine.
--
2.34.0
J
J
Julien Lepiller wrote on 3 Mar 2022 17:07
[PATCH 3/5] gnu: libcxx: Allow cross-compilation.
(address . 54239@debbugs.gnu.org)
2c334d7e0557d21b59eb127b9384db954f57f79c.1646322873.git.julien@lepiller.eu
* gnu/packages/llvm.scm (libcxx)[native-inputs]: Use cross-clang for
cross-compilation. Move llvm to...
[inputs]: ...here.
[arguments]: adjust CROSS_INCLUDE_PATH when cross-compiling.
(libcxx-6)[native-inputs]: Use cross-clang for cross-compilation. Move
llvm to...
[inputs]: ...here.
---
gnu/packages/llvm.scm | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)

Toggle diff (67 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index c02f8e5c7a..9b5e495d08 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -1026,7 +1026,7 @@ (define-public clang clang-13)
(define-public clang-toolchain clang-toolchain-13)
(define* (cross-clang target
- #:optional
+ #:key
(libc (cross-libc target))
(xgcc (cross-gcc target
#:xbinutils (cross-binutils target)
@@ -1343,8 +1343,9 @@ (define-public libcxx
`(#:phases
(modify-phases (@ (guix build cmake-build-system) %standard-phases)
(add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
- (lambda* (#:key inputs #:allow-other-keys)
- (let ((gcc (assoc-ref inputs "gcc")))
+ (lambda* (#:key inputs native-inputs #:allow-other-keys)
+ (let ((gcc (or (assoc-ref (or native-inputs inputs) "gcc")))
+ (cross-gcc (assoc-ref native-inputs "cross-gcc")))
;; Hide GCC's C++ headers so that they do not interfere with
;; the ones we are attempting to build.
(setenv "CPLUS_INCLUDE_PATH"
@@ -1352,12 +1353,23 @@ (define-public libcxx
(string-split (getenv "CPLUS_INCLUDE_PATH")
#\:))
":"))
+ (when cross-gcc
+ (setenv "CROSS_CPLUS_INCLUDE_PATH"
+ (string-join (delete (string-append cross-gcc "/include/c++")
+ (string-split (getenv "CPLUS_INCLUDE_PATH")
+ #\:))
+ ":"))
+ (format #t
+ "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
+ (getenv "CROSS_CPLUS_INCLUDE_PATH")))
(format #t
"environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
- (getenv "CPLUS_INCLUDE_PATH"))
- #t))))))
+ (getenv "CPLUS_INCLUDE_PATH"))))))))
+ (inputs (list llvm-9))
(native-inputs
- (list clang llvm))
+ (list (if (%current-target-system)
+ (cross-clang (%current-target-system) #:clang clang-9)
+ clang-9)))
(home-page "https://libcxx.llvm.org")
(synopsis "C++ standard library")
(description
@@ -1378,8 +1390,11 @@ (define-public libcxx-6
(sha256
(base32
"0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"))))
+ (inputs (list llvm-6))
(native-inputs
- (list clang-6 llvm-6))))
+ (list (if (%current-target-system)
+ (cross-clang (%current-target-system) #:clang clang-6)
+ clang-6)))))
(define-public libcxxabi-6
(package
--
2.34.0
J
J
Julien Lepiller wrote on 3 Mar 2022 17:07
[PATCH 4/5] gnu: libcxxabi-6: Allow cross-compilation.
(address . 54239@debbugs.gnu.org)
593b2077bd42bc8b045c638567ff451d114b0195.1646322873.git.julien@lepiller.eu
* gnu/packages/llvm.scm (libcxxabi-6)[native-inputs]: Use cross-clang for
cross-compilation. Move llvm and libcxx to...
[inputs]: ...here.
[arguments]<adjust-CPLUS_INCLUDE_PATH>: Also adjust
CROSS_CPLUS_INCLUDE_PATH when necessary.
---
gnu/packages/llvm.scm | 41 ++++++++++++++++++++++++++++++++++-------
1 file changed, 34 insertions(+), 7 deletions(-)

Toggle diff (69 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 9b5e495d08..63b55ef3df 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -1422,19 +1422,43 @@ (define-public libcxxabi-6
(modify-phases (@ (guix build cmake-build-system) %standard-phases)
(add-after 'unpack 'chdir
(lambda _ (chdir "libcxxabi")))
- (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
- (lambda* (#:key inputs #:allow-other-keys)
- (let ((gcc (assoc-ref inputs "gcc")))
+ (add-after 'unpack 'adjust-CPLUS_INCLUDE_PATH
+ (lambda* (#:key inputs native-inputs #:allow-other-keys)
+ (define (delete* what lst)
+ (if (null? what)
+ lst
+ (delete* (cdr what) (delete (car what) lst))))
+
+ (let ((gcc (or (assoc-ref inputs "gcc") (assoc-ref native-inputs "gcc")))
+ (cross-gcc (assoc-ref native-inputs "cross-gcc")))
;; Hide GCC's C++ headers so that they do not interfere with
;; the ones we are attempting to build.
(setenv "CPLUS_INCLUDE_PATH"
(string-join
(cons (string-append
(assoc-ref inputs "libcxx") "/include/c++/v1")
- (delete (string-append gcc "/include/c++")
- (string-split (getenv "CPLUS_INCLUDE_PATH")
- #\:)))
+ (delete*
+ `(,(string-append gcc "/include/c++")
+ ,@(if cross-gcc
+ `(,(string-append cross-gcc "/include/c++"))
+ '()))
+ (string-split (getenv "CPLUS_INCLUDE_PATH")
+ #\:)))
":"))
+ (when cross-gcc
+ (setenv "CROSS_CPLUS_INCLUDE_PATH"
+ (string-join
+ (cons (string-append
+ (assoc-ref inputs "libcxx") "/include/c++/v1")
+ (delete*
+ (list (string-append cross-gcc "/include/c++")
+ (string-append gcc "/include/c++"))
+ (string-split (getenv "CROSS_CPLUS_INCLUDE_PATH")
+ #\:)))
+ ":"))
+ (format #true
+ "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
+ (getenv "CROSS_CPLUS_INCLUDE_PATH")))
(format #true
"environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
(getenv "CPLUS_INCLUDE_PATH")))))
@@ -1444,8 +1468,11 @@ (define-public libcxxabi-6
(assoc-ref outputs "out") "/include")))
(install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
(install-file "../libcxxabi/include/cxxabi.h" include-dir)))))))
+ (inputs (list llvm-6 libcxx-6))
(native-inputs
- (list clang-6 llvm-6 libcxx-6))
+ (list (if (%current-target-system)
+ (cross-clang (%current-target-system) #:clang clang-6)
+ clang-6)))
(home-page "https://libcxxabi.llvm.org")
(synopsis "C++ standard library support")
(description
--
2.34.0
J
J
Julien Lepiller wrote on 3 Mar 2022 17:07
[PATCH 5/5] gnu: Add libcxxabi-9.
(address . 54239@debbugs.gnu.org)
4f9bdee16d84acc93f51a0f1a73149366de2b818.1646322873.git.julien@lepiller.eu
* gnu/packages/llvm.scm (libcxxabi-9): New variable.
(libcxxabi-6): Inherit from it.
---
gnu/packages/llvm.scm | 72 +++++++++++++++++++++++++++++++------------
1 file changed, 53 insertions(+), 19 deletions(-)

Toggle diff (121 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 63b55ef3df..f1631bbe70 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -1396,20 +1396,17 @@ (define-public libcxx-6
(cross-clang (%current-target-system) #:clang clang-6)
clang-6)))))
-(define-public libcxxabi-6
+(define-public libcxxabi-9
(package
(name "libcxxabi")
- (version "6.0.1")
+ (version (package-version clang-9))
(source
(origin
- (method git-fetch)
- (uri (git-reference
- (url "https://github.com/llvm/llvm-project")
- (commit (string-append "llvmorg-" version))))
- (file-name (git-file-name name version))
+ (method url-fetch)
+ (uri (llvm-uri "libcxxabi" version))
(sha256
(base32
- "0ki6796b5z08kh3a3rbysr5wwb2dkl6wal5dzd03i4li5xfkvx1g"))))
+ "1b4aiaa8cirx52vk2p5kfk57qmbqf1ipb4nqnjhdgqps9jm7iyg8"))))
(build-system cmake-build-system)
(arguments
`(#:configure-flags
@@ -1420,8 +1417,6 @@ (define-public libcxxabi-6
"-DCMAKE_CXX_COMPILER=clang++")
#:phases
(modify-phases (@ (guix build cmake-build-system) %standard-phases)
- (add-after 'unpack 'chdir
- (lambda _ (chdir "libcxxabi")))
(add-after 'unpack 'adjust-CPLUS_INCLUDE_PATH
(lambda* (#:key inputs native-inputs #:allow-other-keys)
(define (delete* what lst)
@@ -1455,10 +1450,10 @@ (define-public libcxxabi-6
(string-append gcc "/include/c++"))
(string-split (getenv "CROSS_CPLUS_INCLUDE_PATH")
#\:)))
- ":"))
- (format #true
- "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
- (getenv "CROSS_CPLUS_INCLUDE_PATH")))
+ ":")))
+ (format #true
+ "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
+ (getenv "CROSS_CPLUS_INCLUDE_PATH"))
(format #true
"environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
(getenv "CPLUS_INCLUDE_PATH")))))
@@ -1466,13 +1461,19 @@ (define-public libcxxabi-6
(lambda* (#:key outputs #:allow-other-keys)
(let ((include-dir (string-append
(assoc-ref outputs "out") "/include")))
- (install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
- (install-file "../libcxxabi/include/cxxabi.h" include-dir)))))))
- (inputs (list llvm-6 libcxx-6))
+ (mkdir-p include-dir)
+ (install-file ,(string-append "../libcxxabi-" version
+ ".src/include/__cxxabi_config.h")
+ include-dir)
+ (install-file ,(string-append "../libcxxabi-" version
+ ".src/include/cxxabi.h")
+ include-dir)))))))
+ (inputs
+ (list llvm-9 libcxx))
(native-inputs
(list (if (%current-target-system)
- (cross-clang (%current-target-system) #:clang clang-6)
- clang-6)))
+ (cross-clang (%current-target-system) #:clang clang-9)
+ clang-9)))
(home-page "https://libcxxabi.llvm.org")
(synopsis "C++ standard library support")
(description
@@ -1480,6 +1481,39 @@ (define-public libcxxabi-6
standard C++ library.")
(license license:expat)))
+(define-public libcxxabi-6
+ (package
+ (inherit libcxxabi-9)
+ (name "libcxxabi")
+ (version "6.0.1")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/llvm/llvm-project")
+ (commit (string-append "llvmorg-" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32
+ "0ki6796b5z08kh3a3rbysr5wwb2dkl6wal5dzd03i4li5xfkvx1g"))))
+ (arguments
+ (substitute-keyword-arguments (package-arguments libcxxabi-9)
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (add-after 'unpack 'chdir
+ (lambda _ (chdir "libcxxabi")))
+ (replace 'install-headers
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let ((include-dir (string-append
+ (assoc-ref outputs "out") "/include")))
+ (install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
+ (install-file "../libcxxabi/include/cxxabi.h" include-dir))))))))
+ (inputs (list llvm-6 libcxx-6))
+ (native-inputs
+ (list (if (%current-target-system)
+ (cross-clang (%current-target-system) #:clang clang-6)
+ clang-6)))))
+
(define-public libcxx+libcxxabi-6
(package
(inherit libcxx-6)
--
2.34.0
M
M
Maxime Devos wrote on 3 Mar 2022 17:40
Re: [bug#54239] [PATCH] gnu: Add cross-clang.
70c3446488f9b76479f4f989c351403c461369d1.camel@telenet.be
Julien Lepiller schreef op do 03-03-2022 om 17:02 [+0100]:
Toggle quote (9 lines)
> Hi Guix!
>
> This small patch series adds cross-clang, a cross-compiler version of
> clang. Clang doesn't really make a distinction between a native and a
> cross-build, it is already a cross-compiler, but this ensures that:
>
> 1. it actually works
> 2. it targets (%current-target-architecture) by default

Do you mean (%current-target-system)?

Also, WDYT of making 'cross-clang' a memoising procedure, such
that there's only one package object for a cross-clang of a fixed
target system (and version)?

Toggle quote (6 lines)
> (native-inputs
> - (list clang llvm))
> + (list (if (%current-target-system)
> + (cross-clang (%current-target-system) #:clang clang-9)
> + clang-9)))

Probably a few other packages built with clang need such a thing as well.
How about making doing the right thing a bit easier? Suggestion: introduce
a 'clang-for-target' procedure, automatically returning the right clang:

(define (clang-for-target #:optional (clang clang))
(if (%current-target-system)
(cross-clang [...])
clang)) ; not cross-compiling

then packages just need to do

(native-inputs (list (clang-for-target) libfoo libbar ...))


The rest of the series ensures that libcxx and libcxxabi can be
cross-compiled with it.

Customarily, cross-compilers are named $TARGET-foo. WDYT of
renaming the clang binary to '$TARGET-clang', such that a package
can have both a native clang and a cross-clang in native-inputs if desired?
Also, Autoconf looks for $TARGET-compiler, where compiler is at least gcc,
but possibly also clang

And perhaps the package name can be changed '$TARGET-clang' like done for gcc?

Toggle quote (5 lines)
> + ;; Support the same variables as clang, even in cross-compilation
> + ;; context.
> + ;; Clang does not make a difference between native and
> + ;; cross-compilation.

Upstream clang doesn't, but this is in a 'cross-clang' procedure,
so I think it would make sense for Guix' cross-clang to ignore
LIBRARY_PATH and only use CROSS_LIBRARY_PATH. Mixing up
C_INCLUDE_PATH and CROSS_C_INCLUDE_PATH (& friends) is unlikely
to lead anything good, e.g. include/bits/setjmp.h is architecture-dependent.

Toggle quote (2 lines)
> + (files '("lib" "lib64"))))

I don't think Guix does a "lib" / "lib64" split, "lib" might
be sufficient. At least, there are a few comments like

;; Force powerpc libdir to be /lib and not /lib64

in Guix (though the gcc packages still includes "lib64" but
maybe that's only due to historical reasons).

How does this patch series interact with 'with-c-toolchain'?
Would "guix build hello --target=aarch64-linux-gnu --with-c-toolchain=..."
succesfully compile 'hello' with clang?

Greetings,
Maxime.
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYiDvhBccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7uqcAQDqffJqLQht4hDAoFTQnBrHB7T8
iCEOxBLwpkk/N5DA2wD+P8JGmvPywrdGpa9kkA6aaFDMZcq9onGN3RVvfrY+CAw=
=J8yF
-----END PGP SIGNATURE-----


J
J
Julien Lepiller wrote on 3 Mar 2022 19:35
(name . Maxime Devos)(address . maximedevos@telenet.be)(address . 54239@debbugs.gnu.org)
20220303193503.4c055cec@tachikoma.lepiller.eu
Le Thu, 03 Mar 2022 17:40:36 +0100,
Maxime Devos <maximedevos@telenet.be> a écrit :

Toggle quote (13 lines)
> Julien Lepiller schreef op do 03-03-2022 om 17:02 [+0100]:
> > Hi Guix!
> >
> > This small patch series adds cross-clang, a cross-compiler version
> > of clang. Clang doesn't really make a distinction between a native
> > and a cross-build, it is already a cross-compiler, but this ensures
> > that:
> >
> > 1. it actually works
> > 2. it targets (%current-target-architecture) by default
>
> Do you mean (%current-target-system)?

yes, that's what I meant.

Toggle quote (5 lines)
>
> Also, WDYT of making 'cross-clang' a memoising procedure, such
> that there's only one package object for a cross-clang of a fixed
> target system (and version)?

I don't know how to do that. Are there some examples around?

Toggle quote (22 lines)
>
> > (native-inputs
> > - (list clang llvm))
> > + (list (if (%current-target-system)
> > + (cross-clang (%current-target-system) #:clang
> > clang-9)
> > + clang-9)))
>
> Probably a few other packages built with clang need such a thing as
> well. How about making doing the right thing a bit easier?
> Suggestion: introduce a 'clang-for-target' procedure, automatically
> returning the right clang:
>
> (define (clang-for-target #:optional (clang clang))
> (if (%current-target-system)
> (cross-clang [...])
> clang)) ; not cross-compiling
>
> then packages just need to do
>
> (native-inputs (list (clang-for-target) libfoo libbar ...))

Great idea, I implemented that procedure.

Toggle quote (13 lines)
>
> The rest of the series ensures that libcxx and libcxxabi can be
> cross-compiled with it.
>
> Customarily, cross-compilers are named $TARGET-foo. WDYT of
> renaming the clang binary to '$TARGET-clang', such that a package
> can have both a native clang and a cross-clang in native-inputs if
> desired? Also, Autoconf looks for $TARGET-compiler, where compiler is
> at least gcc, but possibly also clang
>
> And perhaps the package name can be changed '$TARGET-clang' like done
> for gcc?

I can do that, but I don't think it'll be recognized by cmake. It's
building right now, and I'll have a try.

Toggle quote (13 lines)
> > + ;; Support the same variables as clang, even in cross-compilation
> > + ;; context.
> > + ;; Clang does not make a difference between native and
> > + ;; cross-compilation.
>
> Upstream clang doesn't, but this is in a 'cross-clang' procedure,
> so I think it would make sense for Guix' cross-clang to ignore
> LIBRARY_PATH and only use CROSS_LIBRARY_PATH. Mixing up
> C_INCLUDE_PATH and CROSS_C_INCLUDE_PATH (& friends) is unlikely
> to lead anything good, e.g. include/bits/setjmp.h is
> architecture-dependent.
>

OK, fixed.

Toggle quote (10 lines)
> > + (files '("lib" "lib64"))))
>
> I don't think Guix does a "lib" / "lib64" split, "lib" might
> be sufficient. At least, there are a few comments like
>
> ;; Force powerpc libdir to be /lib and not /lib64
>
> in Guix (though the gcc packages still includes "lib64" but
> maybe that's only due to historical reasons).

I saw that in GCC, so I just used the same specification, but just
'("lib") is fine with me. Fixed.

Toggle quote (4 lines)
> How does this patch series interact with 'with-c-toolchain'?
> Would "guix build hello --target=aarch64-linux-gnu
> --with-c-toolchain=..." succesfully compile 'hello' with clang?

It won't work, just like it doesn't work for gcc-toolchain. When you do
(without my patches):

guix build hello --with-c-toolchain=hello=clang-toolchain
--target=i686-unknown-linux-gnu

it builds, but that's because --with-c-toolchain replaces "gcc"
(and friends), but the cross package uses "cross-gcc".

guix build hello --with-c-toolchain=hello=gcc-toolchain@7
--target=i686-unknown-linux-gnu

also builds, but uses the latest gcc instead of gcc-toolchain@7.

Will send v2 shortly, after I've tested the rename works.

Toggle quote (2 lines)
> Greetings,
> Maxime.
M
M
Maxime Devos wrote on 3 Mar 2022 19:59
(name . Julien Lepiller)(address . julien@lepiller.eu)(address . 54239@debbugs.gnu.org)
9cd9c6e72b5c3e2b32544fbcb46f14b2b52247b0.camel@telenet.be
Julien Lepiller schreef op do 03-03-2022 om 19:35 [+0100]:
Toggle quote (7 lines)
> >
> > Also, WDYT of making 'cross-clang' a memoising procedure, such
> > that there's only one package object for a cross-clang of a fixed
> > target system (and version)?
>
> I don't know how to do that. Are there some examples around?

Search for 'cross-pkg-config' and 'standard-cross-packages'.

Greetings,
Maxime.
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYiEQBRccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7uLEAP90t0ERq6Pr3LUBJkmKFEPqdC+B
utVy9xEI/3IEfH/EBgEA5rW4ZNTRdbA7i5mDlGHQUTXoIV8R9vW6iYxPYl9FaAA=
=+6Zd
-----END PGP SIGNATURE-----


P
P
Pierre Langlois wrote on 3 Mar 2022 21:51
(name . Julien Lepiller)(address . julien@lepiller.eu)
87wnhapwsv.fsf@gmx.com
Hi Julien,

Julien Lepiller <julien@lepiller.eu> writes:

Toggle quote (12 lines)
> Hi Guix!
>
> This small patch series adds cross-clang, a cross-compiler version of
> clang. Clang doesn't really make a distinction between a native and a
> cross-build, it is already a cross-compiler, but this ensures that:
>
> 1. it actually works
> 2. it targets (%current-target-architecture) by default
>
> The rest of the series ensures that libcxx and libcxxabi can be
> cross-compiled with it.

That's really cool! Out of curiosity, what target are you interested in
that clang supports and GCC doesn't? For instance I'm interested in
WebAssembly, and I've actually been contemplating how we could improve
support for cross-compilers based on Clang in Guix, to be able to
provide a working WebAssembly toolchain.

For context, such a toolchain will be needed to enable potential use of
WebAssembly in IceCat, for security purposes, see

I actually have a toolchain that works already, which targets the
wasm32-wasi-unknown triplet, but I wasn't convinced the way I did it was
the right way to go long term, so it needs more work. I'm attaching the
patch in case there's anything useful to you in there already!

The approach I took was to create wrappers around clang/clang++ in order
to set the correct include paths, and then provide an isolated sysroot
for wasm32-wasi using union-build. This will work for IceCat, where
their should be a flag to pass a sysroot path, but we should be able to
do better in Guix.

I though I'd share in case that's helpful! I'll take a look at your
patches to see if I can build on top of them for a future WebAssembly
toolchain in Guix.

Thanks,
Pierre
-----BEGIN PGP SIGNATURE-----

iQFMBAEBCgA2FiEEctU9gYy29KFyWDdMqPyeRH9PfVQFAmIhLrAYHHBpZXJyZS5s
YW5nbG9pc0BnbXguY29tAAoJEKj8nkR/T31UR/YH/iEDqu/yeDZsPwvQfLNRk16h
Vs9BtkqAtHl5SLiDdC6BBaGTiJ814rE8gmHeJ5CuLo9YxOMFpYbo8MJi4DfhQr1r
cbBAy0cUJMRfDV963dJyA0HM1C9eUCzLZKnCNviYLdp11ZYsX0YlP6j6unUhac7t
gfsGa95zN/EhYZ2dSRiCpsH/WU6n36GrWkNQcQzlqgUzcFEKFvrkDOIiXpzdAb7L
8/kskeRh4mzJYiMNGrcnH1010okpPUyuOuW/aRRea34teFrwg45ogikenUEh5wRx
7kzKCagWgjvpK7XLappPi8stmNfJ5RV9OWWtjNnKKLixvM2an8+Cc/HlbZNERFQ=
=qGo9
-----END PGP SIGNATURE-----

J
J
Julien Lepiller wrote on 3 Mar 2022 22:11
(name . Maxime Devos)(address . maximedevos@telenet.be)(address . 54239@debbugs.gnu.org)
20220303221136.5c131ada@tachikoma.lepiller.eu
Le Thu, 03 Mar 2022 19:59:17 +0100,
Maxime Devos <maximedevos@telenet.be> a écrit :

Toggle quote (13 lines)
> Julien Lepiller schreef op do 03-03-2022 om 19:35 [+0100]:
> > >
> > > Also, WDYT of making 'cross-clang' a memoising procedure, such
> > > that there's only one package object for a cross-clang of a fixed
> > > target system (and version)?
> >
> > I don't know how to do that. Are there some examples around?
>
> Search for 'cross-pkg-config' and 'standard-cross-packages'.
>
> Greetings,
> Maxime.

Thanks! I used mlambda, I think it should work :)

So I tried renaming clang to <target>-clang, but then I noticed the
build of libcxxabi fails:

-- The CXX compiler identification is unknown
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:21 (project):
The CMAKE_CXX_COMPILER:

clang++

is not a full path and was not found in the PATH.

Tell CMake where to find the compiler by setting either the
environment variable "CXX" or the CMake cache entry
CMAKE_CXX_COMPILER to the full path to the compiler, or to the
compiler name if it is in the PATH.


This is because it really expects clang, not <target>-clang. The
autotools might be smarter (haven't tested), but they're the only one.
I don't want to substitute* every CMakeList.txt to make sure they
understand what we're the only ones to do.

Furthermore, clang is already a cross-compiler, and cross-clang only
makes it work in the context of guix packaging and changes the default
target for convenience. Outside of a guix package, although not very
convenient, our clang package already works like everyone else's I
think. I don't think it makes sense to have clang AND i586-gnu-clang in
your profile. Also, cross-clang just like cross-gcc is not accessible
from the CLI.

WDYT?
J
J
Julien Lepiller wrote on 3 Mar 2022 22:20
(name . Pierre Langlois)(address . pierre.langlois@gmx.com)(address . 54239@debbugs.gnu.org)
DB89C0F9-4C86-4412-98C6-250CF6813B8B@lepiller.eu
Oh wow!

I need clang for Android: it's only tested and built with clang, and some of the packages don't build with gcc. I don't really need any fancy target, but one of the goals I had was to be able to cross-build my android packages, hence this cross-compiler.

A wasm cross-compiler would be awesome!

On March 3, 2022 9:51:01 PM GMT+01:00, Pierre Langlois <pierre.langlois@gmx.com> wrote:
Toggle quote (44 lines)
>Hi Julien,
>
>Julien Lepiller <julien@lepiller.eu> writes:
>
>> Hi Guix!
>>
>> This small patch series adds cross-clang, a cross-compiler version of
>> clang. Clang doesn't really make a distinction between a native and a
>> cross-build, it is already a cross-compiler, but this ensures that:
>>
>> 1. it actually works
>> 2. it targets (%current-target-architecture) by default
>>
>> The rest of the series ensures that libcxx and libcxxabi can be
>> cross-compiled with it.
>
>That's really cool! Out of curiosity, what target are you interested in
>that clang supports and GCC doesn't? For instance I'm interested in
>WebAssembly, and I've actually been contemplating how we could improve
>support for cross-compilers based on Clang in Guix, to be able to
>provide a working WebAssembly toolchain.
>
>For context, such a toolchain will be needed to enable potential use of
>WebAssembly in IceCat, for security purposes, see
>https://hacks.mozilla.org/2021/12/webassembly-and-back-again-fine-grained-sandboxing-in-firefox-95/
>
>I actually have a toolchain that works already, which targets the
>wasm32-wasi-unknown triplet, but I wasn't convinced the way I did it was
>the right way to go long term, so it needs more work. I'm attaching the
>patch in case there's anything useful to you in there already!
>
>The approach I took was to create wrappers around clang/clang++ in order
>to set the correct include paths, and then provide an isolated sysroot
>for wasm32-wasi using union-build. This will work for IceCat, where
>their should be a flag to pass a sysroot path, but we should be able to
>do better in Guix.
>
>I though I'd share in case that's helpful! I'll take a look at your
>patches to see if I can build on top of them for a future WebAssembly
>toolchain in Guix.
>
>Thanks,
>Pierre
>
Attachment: file
J
J
Julien Lepiller wrote on 4 Mar 2022 10:59
[PATCH v2 1/5] gnu: Add cross-llvm.
(address . 54239@debbugs.gnu.org)
499e5dba47ef40df93a8b33fbb8e41cc2354e7a1.1646387919.git.julien@lepiller.eu
* gnu/packages/llvm.scm (cross-llvm): New variable.
---
gnu/packages/llvm.scm | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)

Toggle diff (48 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index eb949bed1b..d6e9846699 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -18,7 +18,7 @@
;;; Copyright © 2020 Jakub K?dzio?ka <kuba@kadziolka.net>
;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
-;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu>
+;;; Copyright © 2021, 2022 Julien Lepiller <julien@lepiller.eu>
;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net>
;;; Copyright © 2021 Guillaume Le Vaillant <glv@posteo.net>
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
@@ -74,7 +74,8 @@ (define-module (gnu packages llvm)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (make-lld-wrapper
- system->llvm-target))
+ system->llvm-target
+ cross-llvm))
(define* (system->llvm-target #:optional
(system (or (and=> (%current-target-system)
@@ -99,6 +100,22 @@ (define* (system->llvm-target #:optional
("i686" => "X86")
("i586" => "X86"))))
+(define (cross-llvm llvm target)
+ "Return a native LLVM package that targets a different system. The resulting
+libraries are running on the host but target a different system by default.
+This packge can be used to control clang's default target."
+ (package
+ (inherit llvm)
+ (arguments
+ (substitute-keyword-arguments (package-arguments llvm)
+ ((#:configure-flags flags)
+ #~(append
+ (list
+ (string-append "-DLLVM_DEFAULT_TARGET_TRIPLE=" #$target)
+ (string-append "-DLLVM_TARGET_ARCH="
+ #$(system->llvm-target (gnu-triplet->nix-system target))))
+ #$flags))))))
+
(define (llvm-uri component version)
;; LLVM release candidate file names are formatted 'tool-A.B.C-rcN/tool-A.B.CrcN.src.tar.xz'
;; so we specify the version as A.B.C-rcN and delete the hyphen when referencing the file name.
--
2.34.0
J
J
Julien Lepiller wrote on 4 Mar 2022 10:59
[PATCH v2 2/5] gnu: Add cross-clang.
(address . 54239@debbugs.gnu.org)
de91f63243153229e558311bb91f688ca8e177fb.1646387919.git.julien@lepiller.eu
* gnu/packages/llvm.scm (cross-clang): New variable.
---
gnu/packages/llvm.scm | 144 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 143 insertions(+), 1 deletion(-)

Toggle diff (171 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index d6e9846699..c277e2ac35 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -54,6 +54,7 @@ (define-module (gnu packages llvm)
#:use-module (guix build-system trivial)
#:use-module (gnu packages)
#:use-module (gnu packages base)
+ #:use-module (gnu packages cross-base)
#:use-module (gnu packages gcc)
#:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
#:use-module (gnu packages check) ;python-lit
@@ -75,7 +76,9 @@ (define-module (gnu packages llvm)
#:use-module (ice-9 match)
#:export (make-lld-wrapper
system->llvm-target
- cross-llvm))
+ cross-llvm
+ cross-clang
+ clang-for-target))
(define* (system->llvm-target #:optional
(system (or (and=> (%current-target-system)
@@ -1023,6 +1026,145 @@ (define-public clang-runtime clang-runtime-13)
(define-public clang clang-13)
(define-public clang-toolchain clang-toolchain-13)
+(define* (cross-clang target
+ #:key
+ (libc (cross-libc target))
+ (xgcc (cross-gcc target
+ #:xbinutils (cross-binutils target)
+ #:libc (cross-libc target)))
+ (clang clang))
+ "Return a cross-clang compiler for target."
+ (define cross-clang-aux
+ (mlambda (target libc xgcc clang)
+ (package
+ (inherit clang)
+ (name (string-append "clang-cross-" target))
+ (version (package-version clang))
+ ;; Support the same variables as clang, even in cross-compilation context.
+ ;; Clang does not make a difference between native and cross-compilation.
+ (search-paths
+ (list
+ (search-path-specification
+ (variable "CROSS_LIBRARY_PATH")
+ (files '("lib")))
+ (search-path-specification
+ (variable "CROSS_C_INCLUDE_PATH")
+ (files '("include")))
+ (search-path-specification
+ (variable "CROSS_CPLUS_INCLUDE_PATH")
+ (files '("include/c++" "include")))))
+ (native-search-paths '())
+ (arguments
+ (substitute-keyword-arguments (package-arguments clang)
+ ((#:configure-flags _)
+ `(list "-DCLANG_INCLUDE_TESTS=True"
+ (string-append "-DGCC_INSTALL_PREFIX="
+ (assoc-ref %build-inputs "cross-gcc-lib"))
+ (string-append "-DC_INCLUDE_DIRS="
+ (assoc-ref %build-inputs "target-libc")
+ "/include")))
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (add-after 'unpack 'add-missing-libdir
+ (lambda _
+ ;; cross-gcc installs its libraries in <target>/lib instead of
+ ;; lib.
+ (substitute* "lib/Driver/ToolChain.cpp"
+ (("\"-L\"\\) \\+ LibPath\\)\\);")
+ ,(string-append "\"-L\") + LibPath));
+ CmdArgs.push_back(Args.MakeArgString(StringRef(\"-L\") + "
+ "StringRef(GCC_INSTALL_PREFIX) + StringRef(\"/"
+ target "/lib\")));
+ CmdArgs.push_back(Args.MakeArgString(StringRef(\"-rpath=\") + "
+ "StringRef(GCC_INSTALL_PREFIX) + StringRef(\"/"
+ target "/lib\")));")))))
+ (add-after 'unpack 'support-cross-include-path
+ (lambda _
+ (substitute* "lib/Driver/ToolChains/Clang.cpp"
+ (("C_INCLUDE_PATH") "CROSS_C_INCLUDE_PATH")
+ (("CPLUS_INCLUDE_PATH") "CROSS_CPLUS_INCLUDE_PATH"))))
+ (add-after 'unpack 'support-cross-library-path
+ (lambda _
+ ;; LIBRARY_PATH is only supported for native builds, but we still
+ ;; need it (or CROSS_LIBRARY_PATH to be precise) when
+ ;; cross-compiling
+ (substitute* "lib/Driver/ToolChains/CommonArgs.cpp"
+ (("LIBRARY_PATH\"")
+ "LIBRARY_PATH\");
+ } else {
+ addDirectoryList(Args, CmdArgs, \"-L\", \"CROSS_LIBRARY_PATH\""))))
+ (replace 'set-glibc-file-names
+ (lambda* (#:key inputs #:allow-other-keys)
+ (let ((libc (assoc-ref inputs "target-libc"))
+ (compiler-rt (assoc-ref inputs "clang-runtime"))
+ (gcc (assoc-ref inputs "cross-gcc")))
+ (setenv "LIBRARY_PATH"
+ (string-append
+ (assoc-ref inputs "libc") "/lib:" (getenv "LIBRARY_PATH")))
+ ,@(cond
+ ((version>=? version "6.0")
+ `(;; Link to libclang_rt files from clang-runtime.
+ (substitute* "lib/Driver/ToolChain.cpp"
+ (("getDriver\\(\\)\\.ResourceDir")
+ (string-append "\"" compiler-rt "\"")))
+
+ ;; Make "LibDir" refer to <glibc>/lib so that it
+ ;; uses the right dynamic linker file name.
+ (substitute* "lib/Driver/ToolChains/Linux.cpp"
+ (("(^[[:blank:]]+LibDir = ).*" _ declaration)
+ (string-append declaration "\"" libc "/lib\";\n"))
+
+ ;; Make clang look for libstdc++ in the right
+ ;; location.
+ (("LibStdCXXIncludePathCandidates\\[\\] = \\{")
+ (string-append
+ "LibStdCXXIncludePathCandidates[] = { \"" gcc
+ "/include/c++\","))
+
+ ;; Make sure libc's libdir is on the search path, to
+ ;; allow crt1.o & co. to be found.
+ (("@GLIBC_LIBDIR@")
+ (string-append libc "/lib")))))
+ (else
+ `((substitute* "lib/Driver/Tools.cpp"
+ ;; Patch the 'getLinuxDynamicLinker' function so that
+ ;; it uses the right dynamic linker file name.
+ (("/lib64/ld-linux-x86-64.so.2")
+ (string-append libc ,(glibc-dynamic-linker))))
+
+ ;; Link to libclang_rt files from clang-runtime.
+ ;; This substitution needed slight adjustment in 3.8.
+ ,@(if (version>=? version "3.8")
+ '((substitute* "lib/Driver/Tools.cpp"
+ (("TC\\.getDriver\\(\\)\\.ResourceDir")
+ (string-append "\"" compiler-rt "\""))))
+ '((substitute* "lib/Driver/ToolChain.cpp"
+ (("getDriver\\(\\)\\.ResourceDir")
+ (string-append "\"" compiler-rt "\"")))))
+
+ ;; Make sure libc's libdir is on the search path, to
+ ;; allow crt1.o & co. to be found.
+ (substitute* "lib/Driver/ToolChains.cpp"
+ (("@GLIBC_LIBDIR@")
+ (string-append libc "/lib")))))))))))))
+ (inputs
+ `(("target-libc" ,libc)
+ ("cross-gcc-lib" ,xgcc "lib")
+ ("cross-gcc" ,xgcc)
+ ,@(package-inputs clang)))
+ (propagated-inputs
+ (modify-inputs (package-propagated-inputs clang)
+ (replace "llvm"
+ (cross-llvm
+ (car (assoc-ref (package-propagated-inputs clang) "llvm"))
+ target)))))))
+ (cross-clang-aux target libc xgcc clang))
+
+(define* (clang-for-target #:optional (clang clang))
+ (if (%current-target-system)
+ (cross-clang (%current-target-system) #:clang clang)
+ clang))
+
(define-public llvm-for-rocm
(package
;; Actually based on LLVM 13 as of v4.3, but llvm-12 works just fine.
--
2.34.0
J
J
Julien Lepiller wrote on 4 Mar 2022 10:59
[PATCH v2 3/5] gnu: libcxx: Allow cross-compilation.
(address . 54239@debbugs.gnu.org)
4ed2af8f27dab19c56149a614b46f92fb3541ca7.1646387919.git.julien@lepiller.eu
* gnu/packages/llvm.scm (libcxx)[native-inputs]: Move llvm to...
[inputs]: ...here.
[arguments]: adjust CROSS_INCLUDE_PATH when cross-compiling.
(libcxx-6)[native-inputs]: Move llvm to...
[inputs]: ...here.
---
gnu/packages/llvm.scm | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)

Toggle diff (52 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index c277e2ac35..137bc99f35 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -1362,8 +1362,9 @@ (define-public libcxx
`(#:phases
(modify-phases (@ (guix build cmake-build-system) %standard-phases)
(add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
- (lambda* (#:key inputs #:allow-other-keys)
- (let ((gcc (assoc-ref inputs "gcc")))
+ (lambda* (#:key inputs native-inputs #:allow-other-keys)
+ (let ((gcc (or (assoc-ref (or native-inputs inputs) "gcc")))
+ (cross-gcc (assoc-ref native-inputs "cross-gcc")))
;; Hide GCC's C++ headers so that they do not interfere with
;; the ones we are attempting to build.
(setenv "CPLUS_INCLUDE_PATH"
@@ -1371,12 +1372,19 @@ (define-public libcxx
(string-split (getenv "CPLUS_INCLUDE_PATH")
#\:))
":"))
+ (when cross-gcc
+ (setenv "CROSS_CPLUS_INCLUDE_PATH"
+ (string-join (delete (string-append cross-gcc "/include/c++")
+ (string-split (getenv "CPLUS_INCLUDE_PATH")
+ #\:))
+ ":"))
+ (format #t
+ "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
+ (getenv "CROSS_CPLUS_INCLUDE_PATH")))
(format #t
"environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
- (getenv "CPLUS_INCLUDE_PATH"))
- #t))))))
- (native-inputs
- (list clang llvm))
+ (getenv "CPLUS_INCLUDE_PATH"))))))))
+ (inputs (list llvm-9))
(home-page "https://libcxx.llvm.org")
(synopsis "C++ standard library")
(description
@@ -1397,8 +1405,7 @@ (define-public libcxx-6
(sha256
(base32
"0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"))))
- (native-inputs
- (list clang-6 llvm-6))))
+ (inputs (list llvm-6))))
(define-public libcxxabi-6
(package
--
2.34.0
J
J
Julien Lepiller wrote on 4 Mar 2022 10:59
[PATCH v2 4/5] gnu: libcxxabi-6: Allow cross-compilation.
(address . 54239@debbugs.gnu.org)
ca97a5ae910b7620ed135b05f993dcfdb7b415c0.1646387919.git.julien@lepiller.eu
* gnu/packages/llvm.scm (libcxxabi-6)[native-inputs]: Use
clang-for-target for cross-compilation. Move llvm and libcxx to...
[inputs]: ...here.
[arguments]<adjust-CPLUS_INCLUDE_PATH>: Also adjust
CROSS_CPLUS_INCLUDE_PATH when necessary.
---
gnu/packages/llvm.scm | 40 ++++++++++++++++++++++++++++++++--------
1 file changed, 32 insertions(+), 8 deletions(-)

Toggle diff (67 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 137bc99f35..e00e92aa8c 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -1433,19 +1433,43 @@ (define-public libcxxabi-6
(modify-phases (@ (guix build cmake-build-system) %standard-phases)
(add-after 'unpack 'chdir
(lambda _ (chdir "libcxxabi")))
- (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
- (lambda* (#:key inputs #:allow-other-keys)
- (let ((gcc (assoc-ref inputs "gcc")))
+ (add-after 'unpack 'adjust-CPLUS_INCLUDE_PATH
+ (lambda* (#:key inputs native-inputs #:allow-other-keys)
+ (define (delete* what lst)
+ (if (null? what)
+ lst
+ (delete* (cdr what) (delete (car what) lst))))
+
+ (let ((gcc (or (assoc-ref inputs "gcc") (assoc-ref native-inputs "gcc")))
+ (cross-gcc (assoc-ref native-inputs "cross-gcc")))
;; Hide GCC's C++ headers so that they do not interfere with
;; the ones we are attempting to build.
(setenv "CPLUS_INCLUDE_PATH"
(string-join
(cons (string-append
(assoc-ref inputs "libcxx") "/include/c++/v1")
- (delete (string-append gcc "/include/c++")
- (string-split (getenv "CPLUS_INCLUDE_PATH")
- #\:)))
+ (delete*
+ `(,(string-append gcc "/include/c++")
+ ,@(if cross-gcc
+ `(,(string-append cross-gcc "/include/c++"))
+ '()))
+ (string-split (getenv "CPLUS_INCLUDE_PATH")
+ #\:)))
":"))
+ (when cross-gcc
+ (setenv "CROSS_CPLUS_INCLUDE_PATH"
+ (string-join
+ (cons (string-append
+ (assoc-ref inputs "libcxx") "/include/c++/v1")
+ (delete*
+ (list (string-append cross-gcc "/include/c++")
+ (string-append gcc "/include/c++"))
+ (string-split (getenv "CROSS_CPLUS_INCLUDE_PATH")
+ #\:)))
+ ":"))
+ (format #true
+ "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
+ (getenv "CROSS_CPLUS_INCLUDE_PATH")))
(format #true
"environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
(getenv "CPLUS_INCLUDE_PATH")))))
@@ -1455,8 +1479,8 @@ (define-public libcxxabi-6
(assoc-ref outputs "out") "/include")))
(install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
(install-file "../libcxxabi/include/cxxabi.h" include-dir)))))))
- (native-inputs
- (list clang-6 llvm-6 libcxx-6))
+ (inputs (list llvm-6 libcxx-6))
+ (native-inputs (list (clang-for-target clang-6)))
(home-page "https://libcxxabi.llvm.org")
(synopsis "C++ standard library support")
(description
--
2.34.0
J
J
Julien Lepiller wrote on 4 Mar 2022 10:59
[PATCH v2 5/5] gnu: Add libcxxabi-9.
(address . 54239@debbugs.gnu.org)
937fd2ca36d8368ea83be56ae29dbec1a97bfb41.1646387919.git.julien@lepiller.eu
* gnu/packages/llvm.scm (libcxxabi-9): New variable.
(libcxxabi-6): Inherit from it.
---
gnu/packages/llvm.scm | 69 ++++++++++++++++++++++++++++++++-----------
1 file changed, 51 insertions(+), 18 deletions(-)

Toggle diff (116 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index e00e92aa8c..47fd8e2442 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -1407,20 +1407,17 @@ (define-public libcxx-6
"0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"))))
(inputs (list llvm-6))))
-(define-public libcxxabi-6
+(define-public libcxxabi-9
(package
(name "libcxxabi")
- (version "6.0.1")
+ (version (package-version clang-9))
(source
(origin
- (method git-fetch)
- (uri (git-reference
- (url "https://github.com/llvm/llvm-project")
- (commit (string-append "llvmorg-" version))))
- (file-name (git-file-name name version))
+ (method url-fetch)
+ (uri (llvm-uri "libcxxabi" version))
(sha256
(base32
- "0ki6796b5z08kh3a3rbysr5wwb2dkl6wal5dzd03i4li5xfkvx1g"))))
+ "1b4aiaa8cirx52vk2p5kfk57qmbqf1ipb4nqnjhdgqps9jm7iyg8"))))
(build-system cmake-build-system)
(arguments
`(#:configure-flags
@@ -1431,8 +1428,6 @@ (define-public libcxxabi-6
"-DCMAKE_CXX_COMPILER=clang++")
#:phases
(modify-phases (@ (guix build cmake-build-system) %standard-phases)
- (add-after 'unpack 'chdir
- (lambda _ (chdir "libcxxabi")))
(add-after 'unpack 'adjust-CPLUS_INCLUDE_PATH
(lambda* (#:key inputs native-inputs #:allow-other-keys)
(define (delete* what lst)
@@ -1466,10 +1461,10 @@ (define-public libcxxabi-6
(string-append gcc "/include/c++"))
(string-split (getenv "CROSS_CPLUS_INCLUDE_PATH")
#\:)))
- ":"))
- (format #true
- "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
- (getenv "CROSS_CPLUS_INCLUDE_PATH")))
+ ":")))
+ (format #true
+ "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
+ (getenv "CROSS_CPLUS_INCLUDE_PATH"))
(format #true
"environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
(getenv "CPLUS_INCLUDE_PATH")))))
@@ -1477,10 +1472,15 @@ (define-public libcxxabi-6
(lambda* (#:key outputs #:allow-other-keys)
(let ((include-dir (string-append
(assoc-ref outputs "out") "/include")))
- (install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
- (install-file "../libcxxabi/include/cxxabi.h" include-dir)))))))
- (inputs (list llvm-6 libcxx-6))
- (native-inputs (list (clang-for-target clang-6)))
+ (mkdir-p include-dir)
+ (install-file ,(string-append "../libcxxabi-" version
+ ".src/include/__cxxabi_config.h")
+ include-dir)
+ (install-file ,(string-append "../libcxxabi-" version
+ ".src/include/cxxabi.h")
+ include-dir)))))))
+ (inputs (list llvm-9 libcxx))
+ (native-inputs (list (clang-for-target clang-9)))
(home-page "https://libcxxabi.llvm.org")
(synopsis "C++ standard library support")
(description
@@ -1488,6 +1488,39 @@ (define-public libcxxabi-6
standard C++ library.")
(license license:expat)))
+(define-public libcxxabi-6
+ (package
+ (inherit libcxxabi-9)
+ (name "libcxxabi")
+ (version "6.0.1")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/llvm/llvm-project")
+ (commit (string-append "llvmorg-" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32
+ "0ki6796b5z08kh3a3rbysr5wwb2dkl6wal5dzd03i4li5xfkvx1g"))))
+ (arguments
+ (substitute-keyword-arguments (package-arguments libcxxabi-9)
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (add-after 'unpack 'chdir
+ (lambda _ (chdir "libcxxabi")))
+ (replace 'install-headers
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let ((include-dir (string-append
+ (assoc-ref outputs "out") "/include")))
+ (install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
+ (install-file "../libcxxabi/include/cxxabi.h" include-dir))))))))
+ (inputs (list llvm-6 libcxx-6))
+ (native-inputs
+ (list (if (%current-target-system)
+ (cross-clang (%current-target-system) #:clang clang-6)
+ clang-6)))))
+
(define-public libcxx+libcxxabi-6
(package
(inherit libcxx-6)
--
2.34.0
P
P
Pierre Langlois wrote on 4 Mar 2022 20:34
Re: [bug#54239] [PATCH v2 1/5] gnu: Add cross-llvm.
(name . Julien Lepiller)(address . julien@lepiller.eu)
87bkylo6ai.fsf@gmx.com
Hi Julien,

Julien Lepiller <julien@lepiller.eu> writes:

Toggle quote (2 lines)
> * gnu/packages/llvm.scm (cross-llvm): New variable.

Do you really need to define a cross package for LLVM? In my experience
it was possible to use the same llvm libraries for native and cross
compilation. By default LLVM builds support for all supported targets
(provided they are not "experimental" IIRC).

Whereas for the clang package, at the moment it does have to be built
for a specific target IIUC. I hope that one day we could have the same
clang for native and cross compilation in Guix, but I don't think it can
work without some serious re-design of how cross-compilation works. I've
been trying to think about it but I don't yet have a good understanding
of it.

Thanks,
Pierre
-----BEGIN PGP SIGNATURE-----

iQFMBAEBCgA2FiEEctU9gYy29KFyWDdMqPyeRH9PfVQFAmIiayUYHHBpZXJyZS5s
YW5nbG9pc0BnbXguY29tAAoJEKj8nkR/T31U24YH/1l7ln2fJnUtVun5qmCQlvJy
nbKnNQ7O+HibdMqivHT9b4eDOOTO1O8D6REU+uzjvb8qU0aIY45p+V6rYSP1GIe3
uCybteA+YTh4iPkbDrMu1RLXH+cYNG1HgxN+l4/K1t1L+Httnk1e6H7WQ/QD0R1Q
I26tSHczktvs7ZR5DLQYR8TP+r9fmYP7TQEI+3Gb62sy85JfEkS6aWH6NGZXSQMY
D36mSohSOhXdGb1PCBe8MiKVFH9eQt+DQ8NqMdYuXxGTozL0NagWeE73lz+QseJu
Pg/JiFtCn8AQ5nIvmWiTn6D+NFcoz425mTzuB84/S1bzm5WaZolCEvGNjQ8/FpI=
=bXNa
-----END PGP SIGNATURE-----

M
M
Maxime Devos wrote on 4 Mar 2022 20:50
Re: [bug#54239] [PATCH v2 5/5] gnu: Add libcxxabi-9.
04c47fe2e1f964a675697f3e389f6226e11f9815.camel@telenet.be
Julien Lepiller schreef op vr 04-03-2022 om 10:59 [+0100]:
Toggle quote (4 lines)
> +     (list (if (%current-target-system)
> +               (cross-clang (%current-target-system) #:clang clang-6)
> +               clang-6)))))

Could the new procedure could 'clang-for-target' be used here?
Likewise for a few other packages (e.g. hedgewards), but those could be
left for future patches.

Greetings,
Maxime
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYiJtkxccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7g+SAPwNtiBWZWQka5/VxCpnIR9A+eLD
i3AfQ/q+2hNyJU4szwD9EVtb47tcflyQ7VAqPDGokz0iGABWEXNCypB+tOKiHA4=
=5T+3
-----END PGP SIGNATURE-----


M
M
Maxime Devos wrote on 4 Mar 2022 20:53
Re: [bug#54239] [PATCH v2 2/5] gnu: Add cross-clang.
d128d502479628c326db2e95925f14a1e596e3e8.camel@telenet.be
Julien Lepiller schreef op vr 04-03-2022 om 10:59 [+0100]:
Toggle quote (3 lines)
> +           ((#:configure-flags _)
> +            `(list "-DCLANG_INCLUDE_TESTS=True"

This is a bit fragile. If the definition of the 'clang' package mad
the #:configure-flags a gexp, then this would fail because of the
'sexp->gexp' optimisation in 'cmake-build-system'. As such, I
recommend #~(list "-DCLANG_INCLUDE_TESTS=True" ...) here instead of
sexp quasiquoting.

Greetings,
Maxime.
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYiJuJhccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7s/3AQC/TO8VUDws76nMb4GKctaWxt4B
SS9iuG25J5wzb7WWhQD/WEHGk+RiyfpFrRHWRKXagskPCaX6skuy3vSwF6bJ+Q0=
=7V8F
-----END PGP SIGNATURE-----


M
M
Maxime Devos wrote on 4 Mar 2022 20:54
cc5830dc3779618436c23eaa0c2af3715273683a.camel@telenet.be
Julien Lepiller schreef op vr 04-03-2022 om 10:59 [+0100]:
Toggle quote (6 lines)
> +                         `((substitute* "lib/Driver/Tools.cpp"
> +                             ;; Patch the 'getLinuxDynamicLinker' function so that
> +                             ;; it uses the right dynamic linker file name.
> +                             (("/lib64/ld-linux-x86-64.so.2")
> +                              (string-append libc ,(glibc-dynamic-linker))))

Do we need something similar for non-x86-64 architectures as well?

Greetings,
Maxime.
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYiJubhccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7m4/AP9Inisv/2UlDlnlUiqJ74zRBxsr
s0YYh4xJkhW0tKQEjgD/a6AD357eCGKfbziteEdFuIIYeKkS61AfYAe+9Y9c8As=
=bYbQ
-----END PGP SIGNATURE-----


M
M
Maxime Devos wrote on 4 Mar 2022 20:56
bdcd3f77f0d5d1e298e562ccbc6fc690b699a5f1.camel@telenet.be
Julien Lepiller schreef op vr 04-03-2022 om 10:59 [+0100]:
Toggle quote (7 lines)
> +                        (else
> +                         `((substitute* "lib/Driver/Tools.cpp"
> +                             ;; Patch the 'getLinuxDynamicLinker' function so that
> +                             ;; it uses the right dynamic linker file name.
> +                             (("/lib64/ld-linux-x86-64.so.2")
> +                              (string-append libc ,(glibc-dynamic-linker))))

Shouldn't we use the architecture that the cross-clang is targetting be
passed to 'glibc-dynamic-linker' instead of the architecture that the
cross-clang will run on?

Greetings,
Maxime.
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYiJu2xccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7gZtAQCqhhpBXu1E/Xyt1zHUWZtM3MxA
+zDCtImIO7cPzVT/ogD/W5aLM9QHgI0ddK3wSaLonex711hTjK07SUJklv8u9Ao=
=b8Ct
-----END PGP SIGNATURE-----


M
M
Maxime Devos wrote on 4 Mar 2022 21:00
c4628a24fb6919ff35fc5f861e78b392a2447d2d.camel@telenet.be
Julien Lepiller schreef op vr 04-03-2022 om 10:59 [+0100]:
Toggle quote (2 lines)
> +  #:use-module (gnu packages cross-base)

Most of the time, we aren't cross-compiling. So WDYT of autoloading
this module? It's rather unusual to do this in (gnu packages ...), but
there does not appear to be any reason for this to be impossible to do.

Another option would be using 'module-ref' like (guix build-system ...)
does.

Greetings,
Maxime.
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYiJv9hccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7oKPAQD6IpCh/We0dAH+vGeBH/Br+1Mk
20kWUzHil8jG6p7oygD/VaPbN9vV2+YX3OPSMsPjMoCWDezuYJjci3aRB+yRvQ8=
=KJXK
-----END PGP SIGNATURE-----


M
M
Maxime Devos wrote on 4 Mar 2022 21:05
Re: [bug#54239] [PATCH] gnu: Add cross-clang.
(name . Julien Lepiller)(address . julien@lepiller.eu)(address . 54239@debbugs.gnu.org)
87986722191470a315336d6cf07b3106de1b725c.camel@telenet.be
Julien Lepiller schreef op do 03-03-2022 om 19:35 [+0100]:
Toggle quote (14 lines)
> It won't work, just like it doesn't work for gcc-toolchain. When you do
> (without my patches):
>
> guix build hello --with-c-toolchain=hello=clang-toolchain
> --target=i686-unknown-linux-gnu
>
> it builds, but that's because --with-c-toolchain replaces "gcc"
> (and friends), but the cross package uses "cross-gcc".
>
> guix build hello --with-c-toolchain=hello=gcc-toolchain@7
> --target=i686-unknown-linux-gnu
>
> also builds, but uses the latest gcc instead of gcc-toolchain@7.

In that case, could this limitation be documented in

@deffn {Scheme Procedure} package-with-c-toolchain @var{package} @var{toolchain}

in the manual? Modifying (guix transformations) to also replace
the cross-toolchain would be even better.

Greetings,
Maxime
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYiJw+BccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7hezAQDkymriyv+dfhA2Bf5jE/kOB2Yn
hLqzuoBdYFeFMWh/JAD/W8ERivlwqO+V7WtjPsgDaUzYqHjW8W1aCelDlvq4DgY=
=lWUb
-----END PGP SIGNATURE-----


J
J
Julien Lepiller wrote on 5 Mar 2022 09:24
Re: [bug#54239] [PATCH v2 1/5] gnu: Add cross-llvm.
(name . Pierre Langlois)(address . pierre.langlois@gmx.com)(address . 54239@debbugs.gnu.org)
20220305092445.27693167@tachikoma.lepiller.eu
Le Fri, 04 Mar 2022 19:34:07 +0000,
Pierre Langlois <pierre.langlois@gmx.com> a écrit :

Toggle quote (11 lines)
> Hi Julien,
>
> Julien Lepiller <julien@lepiller.eu> writes:
>
> > * gnu/packages/llvm.scm (cross-llvm): New variable.
>
> Do you really need to define a cross package for LLVM? In my
> experience it was possible to use the same llvm libraries for native
> and cross compilation. By default LLVM builds support for all
> supported targets (provided they are not "experimental" IIRC).

No, I don't think it's required. I only need it so I can define a
default target that's different from the host.

Toggle quote (8 lines)
>
> Whereas for the clang package, at the moment it does have to be built
> for a specific target IIUC. I hope that one day we could have the same
> clang for native and cross compilation in Guix, but I don't think it
> can work without some serious re-design of how cross-compilation
> works. I've been trying to think about it but I don't yet have a good
> understanding of it.

You can use --target to control which target clang builds for (although
I don't know if our clang package can work like that). I wanted to have
a default target though, because passing --target all the time is
cumbersome and we would have to adjust all recipes to pass the flag.
With the default target set appropriately, (clang-for-target) will
always produce binaries for the correct architecture, whether
cross-compiling or not.

Toggle quote (4 lines)
>
> Thanks,
> Pierre
>
J
J
Julien Lepiller wrote on 5 Mar 2022 09:30
Re: [bug#54239] [PATCH v2 2/5] gnu: Add cross-clang.
(name . Maxime Devos)(address . maximedevos@telenet.be)(address . 54239@debbugs.gnu.org)
20220305093010.470bf145@tachikoma.lepiller.eu
Le Fri, 04 Mar 2022 20:54:22 +0100,
Maxime Devos <maximedevos@telenet.be> a écrit :

Toggle quote (15 lines)
> Julien Lepiller schreef op vr 04-03-2022 om 10:59 [+0100]:
> > +                         `((substitute* "lib/Driver/Tools.cpp"
> > +                             ;; Patch the 'getLinuxDynamicLinker'
> > function so that
> > +                             ;; it uses the right dynamic linker
> > file name.
> > +                             (("/lib64/ld-linux-x86-64.so.2")
> > +                              (string-append libc
> > ,(glibc-dynamic-linker))))
>
> Do we need something similar for non-x86-64 architectures as well?
>
> Greetings,
> Maxime.

I don't know about that. This phase is mostly copied from clang itself.
P
P
Pierre Langlois wrote on 5 Mar 2022 14:02
Re: [bug#54239] [PATCH v2 1/5] gnu: Add cross-llvm.
(name . Julien Lepiller)(address . julien@lepiller.eu)
874k4cmtny.fsf@gmx.com
Julien Lepiller <julien@lepiller.eu> writes:

Toggle quote (34 lines)
> Le Fri, 04 Mar 2022 19:34:07 +0000,
> Pierre Langlois <pierre.langlois@gmx.com> a écrit :
>
>> Hi Julien,
>>
>> Julien Lepiller <julien@lepiller.eu> writes:
>>
>> > * gnu/packages/llvm.scm (cross-llvm): New variable.
>>
>> Do you really need to define a cross package for LLVM? In my
>> experience it was possible to use the same llvm libraries for native
>> and cross compilation. By default LLVM builds support for all
>> supported targets (provided they are not "experimental" IIRC).
>
> No, I don't think it's required. I only need it so I can define a
> default target that's different from the host.
>
>>
>> Whereas for the clang package, at the moment it does have to be built
>> for a specific target IIUC. I hope that one day we could have the same
>> clang for native and cross compilation in Guix, but I don't think it
>> can work without some serious re-design of how cross-compilation
>> works. I've been trying to think about it but I don't yet have a good
>> understanding of it.
>
> You can use --target to control which target clang builds for (although
> I don't know if our clang package can work like that). I wanted to have
> a default target though, because passing --target all the time is
> cumbersome and we would have to adjust all recipes to pass the flag.
> With the default target set appropriately, (clang-for-target) will
> always produce binaries for the correct architecture, whether
> cross-compiling or not.
>

Ah I see, that makes sense! I suppose a possible alternative could be
to define a wrapper around clang to pass the `--target=<triplet>' option
by default, but that might be a bit ugly (although we already have a
ld-wrapper).

Thanks,
Pierre
-----BEGIN PGP SIGNATURE-----

iQFMBAEBCgA2FiEEctU9gYy29KFyWDdMqPyeRH9PfVQFAmIjYVEYHHBpZXJyZS5s
YW5nbG9pc0BnbXguY29tAAoJEKj8nkR/T31Ux6kIALKVi4SszzwqrEnhV3Ie0UD/
vyWtGDyn7fnsAesFA/90tvNjCoKuyYZtIam7fNIlCZHvc5GihMqGCyF8az9MSrt3
DpsIJjTYqXK9yhlHCcX2yO6FkrGzYUoaG12PiyFtg9cGJFWCmc3V+LsvUEN0EfrF
+Eh2wsEypTrzApq9zXkZKhDuoi9BEVGbwW/5EP7guZGD+5iTn7PvNyTkKWE3uTyf
Twt+C9cSRyd+SaSTtczdBGpsqcnQj1CGAsYpW18L7WjamyIBIlS7DnkBUK+vguBR
PY+7yEtuGrHG4NYklarTsRkaoR8yLMGtfyi8emkXt5lz2N1296BugLQF3Pb92cg=
=yIpi
-----END PGP SIGNATURE-----

P
P
Pierre Langlois wrote on 5 Mar 2022 15:00
(name . Julien Lepiller)(address . julien@lepiller.eu)
87zgm4ihsp.fsf@gmx.com
Julien Lepiller <julien@lepiller.eu> writes:

Toggle quote (48 lines)
> * gnu/packages/llvm.scm (cross-llvm): New variable.
> ---
> gnu/packages/llvm.scm | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
> index eb949bed1b..d6e9846699 100644
> --- a/gnu/packages/llvm.scm
> +++ b/gnu/packages/llvm.scm
> @@ -18,7 +18,7 @@
> ;;; Copyright © 2020 Jakub K?dzio?ka <kuba@kadziolka.net>
> ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
> ;;; Copyright © 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
> -;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu>
> +;;; Copyright © 2021, 2022 Julien Lepiller <julien@lepiller.eu>
> ;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net>
> ;;; Copyright © 2021 Guillaume Le Vaillant <glv@posteo.net>
> ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
> @@ -74,7 +74,8 @@ (define-module (gnu packages llvm)
> #:use-module (srfi srfi-1)
> #:use-module (ice-9 match)
> #:export (make-lld-wrapper
> - system->llvm-target))
> + system->llvm-target
> + cross-llvm))
>
> (define* (system->llvm-target #:optional
> (system (or (and=> (%current-target-system)
> @@ -99,6 +100,22 @@ (define* (system->llvm-target #:optional
> ("i686" => "X86")
> ("i586" => "X86"))))
>
> +(define (cross-llvm llvm target)
> + "Return a native LLVM package that targets a different system. The resulting
> +libraries are running on the host but target a different system by default.
> +This packge can be used to control clang's default target."
> + (package
> + (inherit llvm)
> + (arguments
> + (substitute-keyword-arguments (package-arguments llvm)
> + ((#:configure-flags flags)
> + #~(append
> + (list
> + (string-append "-DLLVM_DEFAULT_TARGET_TRIPLE=" #$target)
> + (string-append "-DLLVM_TARGET_ARCH="
> + #$(system->llvm-target (gnu-triplet->nix-system target))))


While playing with trying to use this series to build a WebAssembly
cross-compiler, I /think/ we have a bug here, and also in master, when
it comes to setting LLVM_TARGET_ARCH.

It's a bit confusing though, the documentation is as follows:

Toggle snippet (7 lines)
LLVM_TARGET_ARCH:STRING
LLVM target to use for native code generation. This is required for
JIT generation. It defaults to “host”, meaning that it shall pick
the architecture of the machine where LLVM is being built. If you
are cross-compiling, set it to the target architecture name.

It's not clear what naming scheme the variable needs, is it the internal
LLVM target name or the triplet? I think it's architecture part of the
triplet...ish? But instead we pass it the internal target name.

It still works at the moment because whenever LLVM_TARGET_ARCH is used,
the cmake code looks quite permissive and tries to do the right thing by
turning the string lowercase and matching common names (hence the "...ish" :-) ).


So if I try and add WebAssembly into the mix, the architecure name is
wasm32, but the LLVM target is called WebAssembly, and the lowercase
version of it doesn't work :-(

| nix-system | LLVM target | LLVM target lowercase | Does it match? |
|------------+-------------+-----------------------+----------------|
| aarch64 | AArch64 | aarch64 | Y |
| armhf | ARM | arm | Y |
| mips64el | Mips | mips | Y |
| powerpc | PowerPC | powerpc | Y |
| riscv | RISCV | riscv | Y |
| x86_64 | X86 | x86 | Y |
| i686 | X86 | x86 | Y |
| i586 | X86 | x86 | Y |
|------------+-------------+-----------------------+----------------|
| wasm32 | WebAssembly | webassembly | N :-( |


I /think/ we might want to use the nix-system instead of the LLVM target
for LLVM_TARGET_ARCH:

Toggle snippet (3 lines)
(string-append "-DLLVM_TARGET_ARCH=" #$(gnu-triplet->nix-system target)))

But I'm not sure, it might not work for mips64el for example, so we
could need yet-another-mapping.

Given it works as it is today with the current set of supported targets,
we don't necessarily need to fix it now. I'll be happy to take a look
later when eventually adding support for the wasm32-wasi toolchain in
Guix.

Thanks,
Pierre
-----BEGIN PGP SIGNATURE-----

iQFMBAEBCgA2FiEEctU9gYy29KFyWDdMqPyeRH9PfVQFAmIjdmYYHHBpZXJyZS5s
YW5nbG9pc0BnbXguY29tAAoJEKj8nkR/T31UCOwH/jFKIRa8Xi5gwAvaxu5HhC7c
XXWlEvz2rhfikOzU7TvNHTGXNBKu6Zhy0a+k3uN9hyYIYSdSi2cr2ZSjUDNYtefc
QekS48AyA17prUiK1kw9Hx+0ulV2uI2e6USl7aYPZ7NvZ4Necx6S1sGQze1oEdyj
m2uJagH6EQbELDq9fqzmdP2lLWhtTMFHnVJdA8/gN8pIycwehELSOQJ4pVhuNStq
cu97BefLhFUuNERTF0n2TxAgd1qwqBI2GwaT7dHBZNUhpVsoMQs6nQge2DakSx8V
jinX424tCaHONpL0RBwZsvyhfh3FF42U+i7FUph+rKZrXVUhn37Qu7lhrvDJTh8=
=/iOv
-----END PGP SIGNATURE-----

P
P
Pierre Langlois wrote on 5 Mar 2022 17:05
Re: [bug#54239] [PATCH v2 2/5] gnu: Add cross-clang.
(name . Julien Lepiller)(address . julien@lepiller.eu)
87wnh8gykq.fsf@gmx.com
Hi,

A couple of comments from me while testing this trying to build a
cross-toolchain with llvm-13. Hope this is helpful!

Julien Lepiller <julien@lepiller.eu> writes:

Toggle quote (100 lines)
> * gnu/packages/llvm.scm (cross-clang): New variable.
> ---
> gnu/packages/llvm.scm | 144 +++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 143 insertions(+), 1 deletion(-)
>
> diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
> index d6e9846699..c277e2ac35 100644
> --- a/gnu/packages/llvm.scm
> +++ b/gnu/packages/llvm.scm
> @@ -54,6 +54,7 @@ (define-module (gnu packages llvm)
> #:use-module (guix build-system trivial)
> #:use-module (gnu packages)
> #:use-module (gnu packages base)
> + #:use-module (gnu packages cross-base)
> #:use-module (gnu packages gcc)
> #:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
> #:use-module (gnu packages check) ;python-lit
> @@ -75,7 +76,9 @@ (define-module (gnu packages llvm)
> #:use-module (ice-9 match)
> #:export (make-lld-wrapper
> system->llvm-target
> - cross-llvm))
> + cross-llvm
> + cross-clang
> + clang-for-target))
>
> (define* (system->llvm-target #:optional
> (system (or (and=> (%current-target-system)
> @@ -1023,6 +1026,145 @@ (define-public clang-runtime clang-runtime-13)
> (define-public clang clang-13)
> (define-public clang-toolchain clang-toolchain-13)
>
> +(define* (cross-clang target
> + #:key
> + (libc (cross-libc target))
> + (xgcc (cross-gcc target
> + #:xbinutils (cross-binutils target)
> + #:libc (cross-libc target)))
> + (clang clang))
> + "Return a cross-clang compiler for target."
> + (define cross-clang-aux
> + (mlambda (target libc xgcc clang)
> + (package
> + (inherit clang)
> + (name (string-append "clang-cross-" target))
> + (version (package-version clang))
> + ;; Support the same variables as clang, even in cross-compilation context.
> + ;; Clang does not make a difference between native and cross-compilation.
> + (search-paths
> + (list
> + (search-path-specification
> + (variable "CROSS_LIBRARY_PATH")
> + (files '("lib")))
> + (search-path-specification
> + (variable "CROSS_C_INCLUDE_PATH")
> + (files '("include")))
> + (search-path-specification
> + (variable "CROSS_CPLUS_INCLUDE_PATH")
> + (files '("include/c++" "include")))))
> + (native-search-paths '())
> + (arguments
> + (substitute-keyword-arguments (package-arguments clang)
> + ((#:configure-flags _)
> + `(list "-DCLANG_INCLUDE_TESTS=True"
> + (string-append "-DGCC_INSTALL_PREFIX="
> + (assoc-ref %build-inputs "cross-gcc-lib"))
> + (string-append "-DC_INCLUDE_DIRS="
> + (assoc-ref %build-inputs "target-libc")
> + "/include")))
> + ((#:phases phases)
> + `(modify-phases ,phases
> + (add-after 'unpack 'add-missing-libdir
> + (lambda _
> + ;; cross-gcc installs its libraries in <target>/lib instead of
> + ;; lib.
> + (substitute* "lib/Driver/ToolChain.cpp"
> + (("\"-L\"\\) \\+ LibPath\\)\\);")
> + ,(string-append "\"-L\") + LibPath));
> + CmdArgs.push_back(Args.MakeArgString(StringRef(\"-L\") + "
> + "StringRef(GCC_INSTALL_PREFIX) + StringRef(\"/"
> + target "/lib\")));
> + CmdArgs.push_back(Args.MakeArgString(StringRef(\"-rpath=\") + "
> + "StringRef(GCC_INSTALL_PREFIX) + StringRef(\"/"
> + target "/lib\")));")))))
> + (add-after 'unpack 'support-cross-include-path
> + (lambda _
> + (substitute* "lib/Driver/ToolChains/Clang.cpp"
> + (("C_INCLUDE_PATH") "CROSS_C_INCLUDE_PATH")
> + (("CPLUS_INCLUDE_PATH") "CROSS_CPLUS_INCLUDE_PATH"))))
> + (add-after 'unpack 'support-cross-library-path
> + (lambda _
> + ;; LIBRARY_PATH is only supported for native builds, but we still
> + ;; need it (or CROSS_LIBRARY_PATH to be precise) when
> + ;; cross-compiling
> + (substitute* "lib/Driver/ToolChains/CommonArgs.cpp"
> + (("LIBRARY_PATH\"")
> + "LIBRARY_PATH\");
> + } else {
> + addDirectoryList(Args, CmdArgs, \"-L\", \"CROSS_LIBRARY_PATH\""))))

Testing this with llvm-13, this substitution doesn't look quite right
and causes the build to fail, they might have removed braces between
versions:

Doing a blame points to this commit, which suggest it's changed with
LLVM 10 release I believe.


Toggle quote (5 lines)
> + (replace 'set-glibc-file-names
> + (lambda* (#:key inputs #:allow-other-keys)
> + (let ((libc (assoc-ref inputs "target-libc"))
> + (compiler-rt (assoc-ref inputs "clang-runtime"))

Quick question, compiler-rt here is the host's runtime right? Do we not
need to cross-compile it as well?

It's not always clear to me what is part of compiler-rt vs libc vs
libgcc, it could be target-dependent. For example when trying to target
WebAssembly, I needed a cross-compiled compiler-rt to provide the
libclang_rt.builtins-wasm32.a library.

Toggle quote (71 lines)
> + (gcc (assoc-ref inputs "cross-gcc")))
> + (setenv "LIBRARY_PATH"
> + (string-append
> + (assoc-ref inputs "libc") "/lib:" (getenv "LIBRARY_PATH")))
> + ,@(cond
> + ((version>=? version "6.0")
> + `(;; Link to libclang_rt files from clang-runtime.
> + (substitute* "lib/Driver/ToolChain.cpp"
> + (("getDriver\\(\\)\\.ResourceDir")
> + (string-append "\"" compiler-rt "\"")))
> +
> + ;; Make "LibDir" refer to <glibc>/lib so that it
> + ;; uses the right dynamic linker file name.
> + (substitute* "lib/Driver/ToolChains/Linux.cpp"
> + (("(^[[:blank:]]+LibDir = ).*" _ declaration)
> + (string-append declaration "\"" libc "/lib\";\n"))
> +
> + ;; Make clang look for libstdc++ in the right
> + ;; location.
> + (("LibStdCXXIncludePathCandidates\\[\\] = \\{")
> + (string-append
> + "LibStdCXXIncludePathCandidates[] = { \"" gcc
> + "/include/c++\","))
> +
> + ;; Make sure libc's libdir is on the search path, to
> + ;; allow crt1.o & co. to be found.
> + (("@GLIBC_LIBDIR@")
> + (string-append libc "/lib")))))
> + (else
> + `((substitute* "lib/Driver/Tools.cpp"
> + ;; Patch the 'getLinuxDynamicLinker' function so that
> + ;; it uses the right dynamic linker file name.
> + (("/lib64/ld-linux-x86-64.so.2")
> + (string-append libc ,(glibc-dynamic-linker))))
> +
> + ;; Link to libclang_rt files from clang-runtime.
> + ;; This substitution needed slight adjustment in 3.8.
> + ,@(if (version>=? version "3.8")
> + '((substitute* "lib/Driver/Tools.cpp"
> + (("TC\\.getDriver\\(\\)\\.ResourceDir")
> + (string-append "\"" compiler-rt "\""))))
> + '((substitute* "lib/Driver/ToolChain.cpp"
> + (("getDriver\\(\\)\\.ResourceDir")
> + (string-append "\"" compiler-rt "\"")))))
> +
> + ;; Make sure libc's libdir is on the search path, to
> + ;; allow crt1.o & co. to be found.
> + (substitute* "lib/Driver/ToolChains.cpp"
> + (("@GLIBC_LIBDIR@")
> + (string-append libc "/lib")))))))))))))
> + (inputs
> + `(("target-libc" ,libc)
> + ("cross-gcc-lib" ,xgcc "lib")
> + ("cross-gcc" ,xgcc)
> + ,@(package-inputs clang)))
> + (propagated-inputs
> + (modify-inputs (package-propagated-inputs clang)
> + (replace "llvm"
> + (cross-llvm
> + (car (assoc-ref (package-propagated-inputs clang) "llvm"))
> + target)))))))
> + (cross-clang-aux target libc xgcc clang))
> +
> +(define* (clang-for-target #:optional (clang clang))
> + (if (%current-target-system)
> + (cross-clang (%current-target-system) #:clang clang)
> + clang))
> +
> (define-public llvm-for-rocm
> (package
> ;; Actually based on LLVM 13 as of v4.3, but llvm-12 works just fine.
-----BEGIN PGP SIGNATURE-----

iQFMBAEBCgA2FiEEctU9gYy29KFyWDdMqPyeRH9PfVQFAmIjjfUYHHBpZXJyZS5s
YW5nbG9pc0BnbXguY29tAAoJEKj8nkR/T31UWZ8H/RkJveoN8jLYnHtYmxuNW3d5
C856RQ2StnV+QJGaspgT90iQRwsyGGxUplJBVt5I2Whwtutsq10bIH0/eD6WQQ55
ZipUbb8jLeHJqx1hy4Slc6G41ZDr3j5r213AXWj67K6t3d2mYwnkwbxypR/EeLQy
OVM6rjPBkfU+86buBsBOVFlwfBEQWvgI67oNa/68E9fzZNwAt9HgTiFgpO5KnfLA
M7tbCXhmoul21mxXIcijE3tsHGPQ4A+H2QjNT45TxXb6DEh2ZtrVJDfODItpS/kS
VpWYAauqYsb8lFsHfbtah6TJUTn0YVQLo/w6KJh/rnYHHu4pSBv/GzOKYrBIyk0=
=M4mc
-----END PGP SIGNATURE-----

L
L
Ludovic Courtès wrote on 21 May 2022 15:41
Re: bug#54239: [PATCH] gnu: Add cross-clang.
(name . Julien Lepiller)(address . julien@lepiller.eu)
87czg7uho8.fsf_-_@gnu.org
Hello Julien and all,

Looks like quite a lot of work has gone into this patch series. What’s
the status? It would be nice to push it past the finish line!

TIA,
Ludo’.
J
J
Julien Lepiller wrote on 16 Jul 2022 21:44
(name . Ludovic Courtès)(address . ludo@gnu.org)
20220716214424.1d521d65@sybil.lepiller.eu
So, I tried using only a wrapper around clang to pass --target.
However, this doesn't seem to be enough: the code disables LIBRARY_PATH
when cross-compiling and it picks up the wrong gcc:lib and libc
headers.

Instead, I tried to improve the previous patches, and here is v3. To
reply (maybe again) to remarks on the previous version:

- no it's not necessary to build a specific llvm package, but that way
we make sure that the default target is the one we want, so we don't
have to change the instructions for packages that use it, or to use a
wrapper to pass the --target argument. Maybe a wrapper could work
better though.
- clang-for-target was added in the patch that adds cross-clang.
- the configure flags are now a gexp
- I kept the substitute for "/lib64/ld-linux-x86-64.so.2", it's the
same instructions as in clang, so I prefer not to change it. It's a
bit sad that we'll have to change in both places if needed :/
- (gnu packages cross-base) is autoloaded now
- I'll leave documenting limitations of package-with-c-toolchain (or
improving it) to another time.
- I have no idea how to make it work for wasm, but that can probably be
fixed another time. Also, it's not listed in supported targets, and
guix doesn't let me build for that target anymore.
- Fixed build issues for clang >=10.

I also agree that clang-runtime should be cross-compiled. It is a
propagated-input, but cross-clang is a native package that is a
cross-compiler for another architecture, so the inputs are native too.

Since I couldn't figure out how to make a package for a given target, I
added a transformation to (guix build-system) that replaces the
keywords to force a package to build for a given architecture.

Also, I added libcxx and libcxxabi 12 at the end because I need them
for the newer versions of android tools.
J
J
Julien Lepiller wrote on 16 Jul 2022 21:47
[PATCH v3 01/10] guix: Add build-system transformation for target.
(address . 54239@debbugs.gnu.org)
20220716194807.20378-1-julien@lepiller.eu
* guix/build-system.scm (build-system-with-target): New procedure.
---
guix/build-system.scm | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)

Toggle diff (45 lines)
diff --git a/guix/build-system.scm b/guix/build-system.scm
index 76d670995c..7d864423e3 100644
--- a/guix/build-system.scm
+++ b/guix/build-system.scm
@@ -18,6 +18,7 @@
(define-module (guix build-system)
#:use-module (guix records)
+ #:use-module (guix utils)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (build-system
@@ -40,7 +41,8 @@ (define-module (guix build-system)
make-bag
- build-system-with-c-toolchain))
+ build-system-with-c-toolchain
+ build-system-with-target))
(define-record-type* <build-system> build-system make-build-system
build-system?
@@ -129,3 +131,20 @@ (define (lower* . args)
(build-system
(inherit bs)
(lower lower*)))
+
+(define (build-system-with-target bs target)
+ "Return a variant of @var{bs}, a build system, that user @var{target} instead
+of the default target."
+ (define lower
+ (build-system-lower bs))
+
+ (define (lower* . args)
+ (parameterize ((%current-target-system target))
+ (apply lower
+ (append
+ (strip-keyword-arguments (list #:target) args)
+ (list #:target target)))))
+
+ (build-system
+ (inherit bs)
+ (lower lower*)))
--
2.37.0
J
J
Julien Lepiller wrote on 16 Jul 2022 21:47
[PATCH v3 02/10] gnu: clang-runtime: Fix cross-compilation.
(address . 54239@debbugs.gnu.org)
20220716194807.20378-2-julien@lepiller.eu
* gnu/packages/llvm.scm (clang-runtime-from-llvm): Sanitie
CROSS_CPLUS_INCLUDE_PATH in the same way as CPLUS_INCLUDE_PATH.
---
gnu/packages/llvm.scm | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

Toggle diff (37 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 5a2f411eb2..6428391650 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -141,7 +141,7 @@ (define* (clang-runtime-from-llvm llvm
;; Work around https://issues.guix.info/issue/36882. We need to
;; remove glibc from CPLUS_INCLUDE_PATH so that the one hardcoded
;; in GCC, at the bottom of GCC include search-path is used.
- (lambda* (#:key inputs #:allow-other-keys)
+ (lambda* (#:key inputs target #:allow-other-keys)
(let* ((filters '("libc"))
(input-directories
(filter-map (lambda (input)
@@ -153,7 +153,20 @@ (define* (clang-runtime-from-llvm llvm
(set-path-environment-variable "CPLUS_INCLUDE_PATH"
'("include")
input-directories)
- #t))))))
+ (when target
+ (let ((libc (assoc-ref inputs "cross-libc")))
+ (setenv "CROSS_CPLUS_INCLUDE_PATH"
+ (string-join
+ (filter
+ (lambda (path)
+ (and
+ (not (equal? path
+ (string-append libc "/include")))
+ (string-suffix? "include" path)))
+
+ (string-split (getenv "CROSS_CPLUS_INCLUDE_PATH")
+ #\:))
+ ":"))))))))))
(home-page "https://compiler-rt.llvm.org")
(synopsis "Runtime library for Clang/LLVM")
(description
--
2.37.0
J
J
Julien Lepiller wrote on 16 Jul 2022 21:48
[PATCH v3 03/10] gnu: llvm-9: Fix cross-compilation.
(address . 54239@debbugs.gnu.org)
20220716194807.20378-3-julien@lepiller.eu
`(package-arguments llvm-10)' evaluates `this-package' in the context of
llvm-10. `llvm-tblgen' in llvm-10 is not compatible with llvm-9, so
copy the configure-flags from llvm-12 to make sure `this-package' is
evaluated here.

* gnu/packages/llvm.scm (llvm-9)[arguments]: Fix cross-compilation.
---
gnu/packages/llvm.scm | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)

Toggle diff (38 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 6428391650..2aec2925cf 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -973,7 +973,30 @@ (define-public llvm-9
"if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES \"riscv64\")\n"
" target_link_libraries(dsymutil PRIVATE atomic)\n"
"endif()"))))))))
- (package-arguments llvm-10)))))
+ (substitute-keyword-arguments (package-arguments llvm-10)
+ ((#:configure-flags _)
+ #~(#$(if (%current-target-system)
+ #~quasiquote
+ #~quote)
+ ;; These options are required for cross-compiling LLVM according to
+ ;; https://llvm.org/docs/HowToCrossCompileLLVM.html.
+ (#$@(if (%current-target-system)
+ #~(,(string-append "-DLLVM_TABLEGEN="
+ #+(file-append this-package
+ "/bin/llvm-tblgen"))
+ #$(string-append "-DLLVM_DEFAULT_TARGET_TRIPLE="
+ (%current-target-system))
+ #$(string-append "-DLLVM_TARGET_ARCH="
+ (system->llvm-target))
+ #$(string-append "-DLLVM_TARGETS_TO_BUILD="
+ (system->llvm-target)))
+ #~())
+ "-DCMAKE_SKIP_BUILD_RPATH=FALSE"
+ "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
+ "-DBUILD_SHARED_LIBS:BOOL=TRUE"
+ "-DLLVM_ENABLE_FFI:BOOL=TRUE"
+ "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
+ "-DLLVM_INSTALL_UTILS=ON")))))))) ; Needed for rustc.
(define-public clang-runtime-9
(clang-runtime-from-llvm
--
2.37.0
J
J
Julien Lepiller wrote on 16 Jul 2022 21:48
[PATCH v3 04/10] gnu: Add cross-llvm.
(address . 54239@debbugs.gnu.org)
20220716194807.20378-4-julien@lepiller.eu
* gnu/packages/llvm.scm (cross-llvm): New variable.
---
gnu/packages/llvm.scm | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)

Toggle diff (48 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 2aec2925cf..caf8264bef 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -18,7 +18,7 @@
;;; Copyright © 2020 Jakub K?dzio?ka <kuba@kadziolka.net>
;;; Copyright © 2021, 2022 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2020, 2021, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
-;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu>
+;;; Copyright © 2021, 2022 Julien Lepiller <julien@lepiller.eu>
;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net>
;;; Copyright © 2021, 2022 Guillaume Le Vaillant <glv@posteo.net>
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
@@ -76,7 +76,8 @@ (define-module (gnu packages llvm)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (make-lld-wrapper
- system->llvm-target))
+ system->llvm-target
+ cross-llvm))
(define* (system->llvm-target #:optional
(system (or (and=> (%current-target-system)
@@ -101,6 +102,22 @@ (define* (system->llvm-target #:optional
("i686" => "X86")
("i586" => "X86"))))
+(define (cross-llvm llvm target)
+ "Return a native LLVM package that targets a different system. The resulting
+libraries are running on the host but target a different system by default.
+This packge can be used to control clang's default target."
+ (package
+ (inherit llvm)
+ (arguments
+ (substitute-keyword-arguments (package-arguments llvm)
+ ((#:configure-flags flags)
+ #~(append
+ (list
+ (string-append "-DLLVM_DEFAULT_TARGET_TRIPLE=" #$target)
+ (string-append "-DLLVM_TARGET_ARCH="
+ #$(system->llvm-target (gnu-triplet->nix-system target))))
+ #$flags))))))
+
(define (llvm-uri component version)
;; LLVM release candidate file names are formatted 'tool-A.B.C-rcN/tool-A.B.CrcN.src.tar.xz'
;; so we specify the version as A.B.C-rcN and delete the hyphen when referencing the file name.
--
2.37.0
J
J
Julien Lepiller wrote on 16 Jul 2022 21:48
[PATCH v3 05/10] gnu: Add cross-clang.
(address . 54239@debbugs.gnu.org)
20220716194807.20378-5-julien@lepiller.eu
* gnu/packages/llvm.scm (cross-clang): New variable.
---
gnu/packages/llvm.scm | 169 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 168 insertions(+), 1 deletion(-)

Toggle diff (198 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index caf8264bef..560a64840a 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -48,6 +48,7 @@ (define-module (gnu packages llvm)
#:use-module (guix git-download)
#:use-module (guix memoization)
#:use-module (guix utils)
+ #:use-module (guix build-system)
#:use-module (guix build-system gnu)
#:use-module (guix build-system cmake)
#:use-module (guix build-system emacs)
@@ -75,9 +76,12 @@ (define-module (gnu packages llvm)
#:use-module (gnu packages xml)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
+ #:autoload (gnu packages cross-base) (cross-libc cross-gcc cross-binutils)
#:export (make-lld-wrapper
system->llvm-target
- cross-llvm))
+ cross-llvm
+ cross-clang
+ clang-for-target))
(define* (system->llvm-target #:optional
(system (or (and=> (%current-target-system)
@@ -1263,6 +1267,169 @@ (define-public clang-runtime clang-runtime-13)
(define-public clang clang-13)
(define-public clang-toolchain clang-toolchain-13)
+(define* (cross-clang target
+ #:key
+ (libc (cross-libc target))
+ (xgcc (cross-gcc target
+ #:xbinutils (cross-binutils target)
+ #:libc (cross-libc target)))
+ (clang clang))
+ "Return a cross-clang compiler for target."
+ (define cross-clang-aux
+ (mlambda (target libc xgcc clang)
+ (package
+ (inherit clang)
+ (name (string-append "clang-cross-" target))
+ (version (package-version clang))
+ ;; Support the same variables as clang, even in cross-compilation context.
+ ;; Clang does not make a difference between native and cross-compilation.
+ (search-paths
+ (list
+ (search-path-specification
+ (variable "CROSS_LIBRARY_PATH")
+ (files '("lib")))
+ (search-path-specification
+ (variable "CROSS_C_INCLUDE_PATH")
+ (files '("include")))
+ (search-path-specification
+ (variable "CROSS_CPLUS_INCLUDE_PATH")
+ (files '("include/c++" "include")))))
+ (native-search-paths '())
+ (arguments
+ (substitute-keyword-arguments (package-arguments clang)
+ ((#:configure-flags _)
+ #~(list "-DCLANG_INCLUDE_TESTS=True"
+ (string-append "-DGCC_INSTALL_PREFIX="
+ (assoc-ref %build-inputs "cross-gcc-lib"))
+ (string-append "-DC_INCLUDE_DIRS="
+ (assoc-ref %build-inputs "target-libc")
+ "/include")))
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (add-after 'unpack 'add-missing-libdir
+ (lambda _
+ ;; cross-gcc installs its libraries in <target>/lib instead of
+ ;; lib.
+ (substitute* "lib/Driver/ToolChain.cpp"
+ (("\"-L\"\\) \\+ LibPath\\)\\);")
+ ,(string-append "\"-L\") + LibPath));
+ CmdArgs.push_back(Args.MakeArgString(StringRef(\"-L\") + "
+ "StringRef(GCC_INSTALL_PREFIX) + StringRef(\"/"
+ target "/lib\")));
+ CmdArgs.push_back(Args.MakeArgString(StringRef(\"-rpath=\") + "
+ "StringRef(GCC_INSTALL_PREFIX) + StringRef(\"/"
+ target "/lib\")));")))))
+ (add-after 'unpack 'support-cross-include-path
+ (lambda _
+ (substitute* ,(if (version>=? version "6.0")
+ "lib/Driver/ToolChains/Clang.cpp"
+ "lib/Driver/Tools.cpp")
+ (("C_INCLUDE_PATH") "CROSS_C_INCLUDE_PATH")
+ (("CPLUS_INCLUDE_PATH") "CROSS_CPLUS_INCLUDE_PATH"))))
+ (add-after 'unpack 'support-cross-library-path
+ (lambda _
+ ;; LIBRARY_PATH is only supported for native builds, but we still
+ ;; need it (or CROSS_LIBRARY_PATH to be precise) when
+ ;; cross-compiling
+ ,(cond
+ ((version>=? version "10")
+ `(substitute* "lib/Driver/ToolChains/CommonArgs.cpp"
+ (("LIBRARY_PATH\"")
+ "LIBRARY_PATH\");
+ else
+ addDirectoryList(Args, CmdArgs, \"-L\", \"CROSS_LIBRARY_PATH\"")))
+ ((version>=? version "6.0")
+ `(substitute* "lib/Driver/ToolChains/CommonArgs.cpp"
+ (("LIBRARY_PATH\"")
+ "LIBRARY_PATH\");
+ } else {
+ addDirectoryList(Args, CmdArgs, \"-L\", \"CROSS_LIBRARY_PATH\"")))
+ (else
+ `(substitute* "lib/Driver/Tools.cpp"
+ (("LIBRARY_PATH\"")
+ "LIBRARY_PATH\");
+ else
+ addDirectoryList(Args, CmdArgs, \"-L\", \"CROSS_LIBRARY_PATH\""))))))
+ (replace 'set-glibc-file-names
+ (lambda* (#:key inputs #:allow-other-keys)
+ (let ((libc (assoc-ref inputs "target-libc"))
+ (compiler-rt (assoc-ref inputs "clang-runtime"))
+ (gcc (assoc-ref inputs "cross-gcc")))
+ (setenv "LIBRARY_PATH"
+ (string-append
+ (assoc-ref inputs "libc") "/lib:" (getenv "LIBRARY_PATH")))
+ ,@(cond
+ ((version>=? version "6.0")
+ `(;; Link to libclang_rt files from clang-runtime.
+ (substitute* "lib/Driver/ToolChain.cpp"
+ (("getDriver\\(\\)\\.ResourceDir")
+ (string-append "\"" compiler-rt "\"")))
+
+ ;; Make "LibDir" refer to <glibc>/lib so that it
+ ;; uses the right dynamic linker file name.
+ (substitute* "lib/Driver/ToolChains/Linux.cpp"
+ (("(^[[:blank:]]+LibDir = ).*" _ declaration)
+ (string-append declaration "\"" libc "/lib\";\n"))
+
+ ;; Make clang look for libstdc++ in the right
+ ;; location.
+ (("LibStdCXXIncludePathCandidates\\[\\] = \\{")
+ (string-append
+ "LibStdCXXIncludePathCandidates[] = { \"" gcc
+ "/include/c++\","))
+
+ ;; Make sure libc's libdir is on the search path, to
+ ;; allow crt1.o & co. to be found.
+ (("@GLIBC_LIBDIR@")
+ (string-append libc "/lib")))))
+ (else
+ `((substitute* "lib/Driver/Tools.cpp"
+ ;; Patch the 'getLinuxDynamicLinker' function so that
+ ;; it uses the right dynamic linker file name.
+ (("/lib64/ld-linux-x86-64.so.2")
+ (string-append libc ,(glibc-dynamic-linker))))
+
+ ;; Link to libclang_rt files from clang-runtime.
+ ;; This substitution needed slight adjustment in 3.8.
+ ,@(if (version>=? version "3.8")
+ '((substitute* "lib/Driver/Tools.cpp"
+ (("TC\\.getDriver\\(\\)\\.ResourceDir")
+ (string-append "\"" compiler-rt "\""))))
+ '((substitute* "lib/Driver/ToolChain.cpp"
+ (("getDriver\\(\\)\\.ResourceDir")
+ (string-append "\"" compiler-rt "\"")))))
+
+ ;; Make sure libc's libdir is on the search path, to
+ ;; allow crt1.o & co. to be found.
+ (substitute* "lib/Driver/ToolChains.cpp"
+ (("@GLIBC_LIBDIR@")
+ (string-append libc "/lib")))))))))))))
+ (inputs
+ `(("target-libc" ,libc)
+ ("cross-gcc-lib" ,xgcc "lib")
+ ("cross-gcc" ,xgcc)
+ ,@(package-inputs clang)))
+ (propagated-inputs
+ (modify-inputs (package-propagated-inputs clang)
+ (replace "clang-runtime"
+ (let ((base (car (assoc-ref (package-propagated-inputs clang)
+ "clang-runtime"))))
+ (package
+ (inherit base)
+ (build-system (build-system-with-target
+ (package-build-system base)
+ target)))))
+ (replace "llvm"
+ (cross-llvm
+ (car (assoc-ref (package-propagated-inputs clang) "llvm"))
+ target)))))))
+ (cross-clang-aux target libc xgcc clang))
+
+(define* (clang-for-target #:optional (clang clang))
+ (if (%current-target-system)
+ (cross-clang (%current-target-system) #:clang clang)
+ clang))
+
(define-public llvm-for-rocm
(package
;; Based on LLVM 14 as of v5.0.0
--
2.37.0
J
J
Julien Lepiller wrote on 16 Jul 2022 21:48
[PATCH v3 06/10] gnu: libcxx: Allow cross-compilation.
(address . 54239@debbugs.gnu.org)
20220716194807.20378-6-julien@lepiller.eu
* gnu/packages/llvm.scm (libcxx)[native-inputs]: Move llvm to...
[inputs]: ...here.
[arguments]: adjust CROSS_INCLUDE_PATH when cross-compiling.
(libcxx-6)[native-inputs]: Move llvm to...
[inputs]: ...here.
---
gnu/packages/llvm.scm | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)

Toggle diff (52 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 560a64840a..96620f1c3c 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -1640,8 +1640,9 @@ (define-public libcxx
`(#:phases
(modify-phases (@ (guix build cmake-build-system) %standard-phases)
(add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
- (lambda* (#:key inputs #:allow-other-keys)
- (let ((gcc (assoc-ref inputs "gcc")))
+ (lambda* (#:key inputs native-inputs #:allow-other-keys)
+ (let ((gcc (or (assoc-ref (or native-inputs inputs) "gcc")))
+ (cross-gcc (assoc-ref native-inputs "cross-gcc")))
;; Hide GCC's C++ headers so that they do not interfere with
;; the ones we are attempting to build.
(setenv "CPLUS_INCLUDE_PATH"
@@ -1649,12 +1650,19 @@ (define-public libcxx
(string-split (getenv "CPLUS_INCLUDE_PATH")
#\:))
":"))
+ (when cross-gcc
+ (setenv "CROSS_CPLUS_INCLUDE_PATH"
+ (string-join (delete (string-append cross-gcc "/include/c++")
+ (string-split (getenv "CROSS_CPLUS_INCLUDE_PATH")
+ #\:))
+ ":"))
+ (format #t
+ "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
+ (getenv "CROSS_CPLUS_INCLUDE_PATH")))
(format #t
"environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
- (getenv "CPLUS_INCLUDE_PATH"))
- #t))))))
- (native-inputs
- (list clang llvm))
+ (getenv "CPLUS_INCLUDE_PATH"))))))))
+ (inputs (list llvm-9))
(home-page "https://libcxx.llvm.org")
(synopsis "C++ standard library")
(description
@@ -1675,8 +1683,7 @@ (define-public libcxx-6
(sha256
(base32
"0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"))))
- (native-inputs
- (list clang-6 llvm-6))))
+ (inputs (list llvm-6))))
(define-public libcxxabi-6
(package
--
2.37.0
J
J
Julien Lepiller wrote on 16 Jul 2022 21:48
[PATCH v3 07/10] gnu: libcxxabi-6: Allow cross-compilation.
(address . 54239@debbugs.gnu.org)
20220716194807.20378-7-julien@lepiller.eu
* gnu/packages/llvm.scm (libcxxabi-6)[native-inputs]: Use
clang-for-target for cross-compilation. Move llvm and libcxx to...
[inputs]: ...here.
[arguments]<adjust-CPLUS_INCLUDE_PATH>: Also adjust
CROSS_CPLUS_INCLUDE_PATH when necessary.
---
gnu/packages/llvm.scm | 40 ++++++++++++++++++++++++++++++++--------
1 file changed, 32 insertions(+), 8 deletions(-)

Toggle diff (67 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 96620f1c3c..ba48897c8b 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -1711,19 +1711,43 @@ (define-public libcxxabi-6
(modify-phases (@ (guix build cmake-build-system) %standard-phases)
(add-after 'unpack 'chdir
(lambda _ (chdir "libcxxabi")))
- (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
- (lambda* (#:key inputs #:allow-other-keys)
- (let ((gcc (assoc-ref inputs "gcc")))
+ (add-after 'unpack 'adjust-CPLUS_INCLUDE_PATH
+ (lambda* (#:key inputs native-inputs #:allow-other-keys)
+ (define (delete* what lst)
+ (if (null? what)
+ lst
+ (delete* (cdr what) (delete (car what) lst))))
+
+ (let ((gcc (or (assoc-ref inputs "gcc") (assoc-ref native-inputs "gcc")))
+ (cross-gcc (assoc-ref native-inputs "cross-gcc")))
;; Hide GCC's C++ headers so that they do not interfere with
;; the ones we are attempting to build.
(setenv "CPLUS_INCLUDE_PATH"
(string-join
(cons (string-append
(assoc-ref inputs "libcxx") "/include/c++/v1")
- (delete (string-append gcc "/include/c++")
- (string-split (getenv "CPLUS_INCLUDE_PATH")
- #\:)))
+ (delete*
+ `(,(string-append gcc "/include/c++")
+ ,@(if cross-gcc
+ `(,(string-append cross-gcc "/include/c++"))
+ '()))
+ (string-split (getenv "CPLUS_INCLUDE_PATH")
+ #\:)))
":"))
+ (when cross-gcc
+ (setenv "CROSS_CPLUS_INCLUDE_PATH"
+ (string-join
+ (cons (string-append
+ (assoc-ref inputs "libcxx") "/include/c++/v1")
+ (delete*
+ (list (string-append cross-gcc "/include/c++")
+ (string-append gcc "/include/c++"))
+ (string-split (getenv "CROSS_CPLUS_INCLUDE_PATH")
+ #\:)))
+ ":"))
+ (format #true
+ "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
+ (getenv "CROSS_CPLUS_INCLUDE_PATH")))
(format #true
"environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
(getenv "CPLUS_INCLUDE_PATH")))))
@@ -1733,8 +1757,8 @@ (define-public libcxxabi-6
(assoc-ref outputs "out") "/include")))
(install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
(install-file "../libcxxabi/include/cxxabi.h" include-dir)))))))
- (native-inputs
- (list clang-6 llvm-6 libcxx-6))
+ (inputs (list llvm-6 libcxx-6))
+ (native-inputs (list (clang-for-target clang-6)))
(home-page "https://libcxxabi.llvm.org")
(synopsis "C++ standard library support")
(description
--
2.37.0
J
J
Julien Lepiller wrote on 16 Jul 2022 21:48
[PATCH v3 08/10] gnu: Add libcxxabi-9.
(address . 54239@debbugs.gnu.org)
20220716194807.20378-8-julien@lepiller.eu
* gnu/packages/llvm.scm (libcxxabi-9): New variable.
(libcxxabi-6): Inherit from it.
---
gnu/packages/llvm.scm | 66 +++++++++++++++++++++++++++++++------------
1 file changed, 48 insertions(+), 18 deletions(-)

Toggle diff (113 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index ba48897c8b..77c3ab73e0 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -1685,20 +1685,17 @@ (define-public libcxx-6
"0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"))))
(inputs (list llvm-6))))
-(define-public libcxxabi-6
+(define-public libcxxabi-9
(package
(name "libcxxabi")
- (version "6.0.1")
+ (version (package-version clang-9))
(source
(origin
- (method git-fetch)
- (uri (git-reference
- (url "https://github.com/llvm/llvm-project")
- (commit (string-append "llvmorg-" version))))
- (file-name (git-file-name name version))
+ (method url-fetch)
+ (uri (llvm-uri "libcxxabi" version))
(sha256
(base32
- "0ki6796b5z08kh3a3rbysr5wwb2dkl6wal5dzd03i4li5xfkvx1g"))))
+ "1b4aiaa8cirx52vk2p5kfk57qmbqf1ipb4nqnjhdgqps9jm7iyg8"))))
(build-system cmake-build-system)
(arguments
`(#:configure-flags
@@ -1709,8 +1706,6 @@ (define-public libcxxabi-6
"-DCMAKE_CXX_COMPILER=clang++")
#:phases
(modify-phases (@ (guix build cmake-build-system) %standard-phases)
- (add-after 'unpack 'chdir
- (lambda _ (chdir "libcxxabi")))
(add-after 'unpack 'adjust-CPLUS_INCLUDE_PATH
(lambda* (#:key inputs native-inputs #:allow-other-keys)
(define (delete* what lst)
@@ -1744,10 +1739,10 @@ (define (delete* what lst)
(string-append gcc "/include/c++"))
(string-split (getenv "CROSS_CPLUS_INCLUDE_PATH")
#\:)))
- ":"))
- (format #true
- "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
- (getenv "CROSS_CPLUS_INCLUDE_PATH")))
+ ":")))
+ (format #true
+ "environment variable `CROSS_CPLUS_INCLUDE_PATH' changed to ~a~%"
+ (getenv "CROSS_CPLUS_INCLUDE_PATH"))
(format #true
"environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
(getenv "CPLUS_INCLUDE_PATH")))))
@@ -1755,10 +1750,15 @@ (define (delete* what lst)
(lambda* (#:key outputs #:allow-other-keys)
(let ((include-dir (string-append
(assoc-ref outputs "out") "/include")))
- (install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
- (install-file "../libcxxabi/include/cxxabi.h" include-dir)))))))
- (inputs (list llvm-6 libcxx-6))
- (native-inputs (list (clang-for-target clang-6)))
+ (mkdir-p include-dir)
+ (install-file ,(string-append "../libcxxabi-" version
+ ".src/include/__cxxabi_config.h")
+ include-dir)
+ (install-file ,(string-append "../libcxxabi-" version
+ ".src/include/cxxabi.h")
+ include-dir)))))))
+ (inputs (list llvm-9 libcxx))
+ (native-inputs (list (clang-for-target clang-9)))
(home-page "https://libcxxabi.llvm.org")
(synopsis "C++ standard library support")
(description
@@ -1766,6 +1766,36 @@ (define (delete* what lst)
standard C++ library.")
(license license:expat)))
+(define-public libcxxabi-6
+ (package
+ (inherit libcxxabi-9)
+ (name "libcxxabi")
+ (version "6.0.1")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/llvm/llvm-project")
+ (commit (string-append "llvmorg-" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32
+ "0ki6796b5z08kh3a3rbysr5wwb2dkl6wal5dzd03i4li5xfkvx1g"))))
+ (arguments
+ (substitute-keyword-arguments (package-arguments libcxxabi-9)
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (add-after 'unpack 'chdir
+ (lambda _ (chdir "libcxxabi")))
+ (replace 'install-headers
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let ((include-dir (string-append
+ (assoc-ref outputs "out") "/include")))
+ (install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
+ (install-file "../libcxxabi/include/cxxabi.h" include-dir))))))))
+ (inputs (list llvm-6 libcxx-6))
+ (native-inputs (list (clang-for-target clang-6)))))
+
(define-public libcxx+libcxxabi-6
(package
(inherit libcxx-6)
--
2.37.0
J
J
Julien Lepiller wrote on 16 Jul 2022 21:48
[PATCH v3 09/10] gnu: Add libcxx-12.
(address . 54239@debbugs.gnu.org)
20220716194807.20378-9-julien@lepiller.eu
* gnu/packages/llvm.scm (libcxx): Rename to...
(libcxx-9): ...this.
(libcxx-12): New variable.
---
gnu/packages/llvm.scm | 38 ++++++++++++++++++++++++++++++--------
1 file changed, 30 insertions(+), 8 deletions(-)

Toggle diff (89 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 77c3ab73e0..4f0b57a990 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -1624,21 +1624,24 @@ (define-public lldb
(properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
(license license:asl2.0))) ;with LLVM exceptions
-(define-public libcxx
+(define-public libcxx-12
(package
(name "libcxx")
- (version "9.0.1")
+ (version (package-version llvm-12))
(source
(origin
(method url-fetch)
- (uri (llvm-uri "libcxx" version))
+ (uri (llvm-uri "llvm-project" version))
(sha256
(base32
- "0d2bj5i6mk4caq7skd5nsdmz8c2m5w5anximl5wz3x32p08zz089"))))
+ "03ps7akvbkxxa4xzal49v7lw3bz41zmjsp6fa7cslxrns5fb570j"))))
(build-system cmake-build-system)
(arguments
`(#:phases
(modify-phases (@ (guix build cmake-build-system) %standard-phases)
+ (add-after 'unpack 'chdir
+ (lambda _
+ (chdir "libcxx")))
(add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
(lambda* (#:key inputs native-inputs #:allow-other-keys)
(let ((gcc (or (assoc-ref (or native-inputs inputs) "gcc")))
@@ -1662,7 +1665,8 @@ (define-public libcxx
(format #t
"environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
(getenv "CPLUS_INCLUDE_PATH"))))))))
- (inputs (list llvm-9))
+ (inputs (list llvm-12))
+ (native-inputs (list python))
(home-page "https://libcxx.llvm.org")
(synopsis "C++ standard library")
(description
@@ -1671,14 +1675,32 @@ (define-public libcxx
(properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
(license license:expat)))
+(define-public libcxx-9
+ (package
+ (inherit libcxx-12)
+ (version (package-version llvm-9))
+ (source
+ (origin
+ (method url-fetch)
+ (uri (llvm-uri "libcxx" version))
+ (sha256
+ (base32
+ "0d2bj5i6mk4caq7skd5nsdmz8c2m5w5anximl5wz3x32p08zz089"))))
+ (arguments
+ (substitute-keyword-arguments (package-arguments libcxx-12)
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (delete 'chdir)))))
+ (inputs (list llvm-9))))
+
;; Libcxx files specifically used by PySide2.
(define-public libcxx-6
(package
- (inherit libcxx)
+ (inherit libcxx-9)
(version (package-version llvm-6))
(source
(origin
- (inherit (package-source libcxx))
+ (inherit (package-source libcxx-9))
(uri (llvm-uri "libcxx" version))
(sha256
(base32
@@ -1757,7 +1779,7 @@ (define (delete* what lst)
(install-file ,(string-append "../libcxxabi-" version
".src/include/cxxabi.h")
include-dir)))))))
- (inputs (list llvm-9 libcxx))
+ (inputs (list llvm-9 libcxx-9))
(native-inputs (list (clang-for-target clang-9)))
(home-page "https://libcxxabi.llvm.org")
(synopsis "C++ standard library support")
--
2.37.0
J
J
Julien Lepiller wrote on 16 Jul 2022 21:48
[PATCH v3 10/10] gnu: Add libcxxabi-12.
(address . 54239@debbugs.gnu.org)
20220716194807.20378-10-julien@lepiller.eu
* gnu/packages/llvm.scm (libcxxabi-12): New variable.
(libcxxabi-9): Inherit from it.
---
gnu/packages/llvm.scm | 53 +++++++++++++++++++++++++++++++++----------
1 file changed, 41 insertions(+), 12 deletions(-)

Toggle diff (94 lines)
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 4f0b57a990..72fef43a5f 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -1707,17 +1707,17 @@ (define-public libcxx-6
"0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"))))
(inputs (list llvm-6))))
-(define-public libcxxabi-9
+(define-public libcxxabi-12
(package
(name "libcxxabi")
- (version (package-version clang-9))
+ (version (package-version clang-12))
(source
(origin
(method url-fetch)
- (uri (llvm-uri "libcxxabi" version))
+ (uri (llvm-uri "llvm-project" version))
(sha256
(base32
- "1b4aiaa8cirx52vk2p5kfk57qmbqf1ipb4nqnjhdgqps9jm7iyg8"))))
+ "03ps7akvbkxxa4xzal49v7lw3bz41zmjsp6fa7cslxrns5fb570j"))))
(build-system cmake-build-system)
(arguments
`(#:configure-flags
@@ -1728,6 +1728,9 @@ (define-public libcxxabi-9
"-DCMAKE_CXX_COMPILER=clang++")
#:phases
(modify-phases (@ (guix build cmake-build-system) %standard-phases)
+ (add-after 'unpack 'chdir
+ (lambda _
+ (chdir "libcxxabi")))
(add-after 'unpack 'adjust-CPLUS_INCLUDE_PATH
(lambda* (#:key inputs native-inputs #:allow-other-keys)
(define (delete* what lst)
@@ -1773,14 +1776,10 @@ (define (delete* what lst)
(let ((include-dir (string-append
(assoc-ref outputs "out") "/include")))
(mkdir-p include-dir)
- (install-file ,(string-append "../libcxxabi-" version
- ".src/include/__cxxabi_config.h")
- include-dir)
- (install-file ,(string-append "../libcxxabi-" version
- ".src/include/cxxabi.h")
- include-dir)))))))
- (inputs (list llvm-9 libcxx-9))
- (native-inputs (list (clang-for-target clang-9)))
+ (install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
+ (install-file "../libcxxabi/include/cxxabi.h" include-dir)))))))
+ (inputs (list llvm-12 libcxx-12))
+ (native-inputs (list (clang-for-target clang-12) python))
(home-page "https://libcxxabi.llvm.org")
(synopsis "C++ standard library support")
(description
@@ -1788,6 +1787,36 @@ (define (delete* what lst)
standard C++ library.")
(license license:expat)))
+(define-public libcxxabi-9
+ (package
+ (inherit libcxxabi-12)
+ (version (package-version clang-9))
+ (source
+ (origin
+ (method url-fetch)
+ (uri (llvm-uri "libcxxabi" version))
+ (sha256
+ (base32
+ "1b4aiaa8cirx52vk2p5kfk57qmbqf1ipb4nqnjhdgqps9jm7iyg8"))))
+ (arguments
+ (substitute-keyword-arguments (package-arguments libcxxabi-12)
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (delete 'chdir)
+ (replace 'install-headers
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let ((include-dir (string-append
+ (assoc-ref outputs "out") "/include")))
+ (mkdir-p include-dir)
+ (install-file ,(string-append "../libcxxabi-" version
+ ".src/include/__cxxabi_config.h")
+ include-dir)
+ (install-file ,(string-append "../libcxxabi-" version
+ ".src/include/cxxabi.h")
+ include-dir))))))))
+ (inputs (list llvm-9 libcxx-9))
+ (native-inputs (list (clang-for-target clang-9)))))
+
(define-public libcxxabi-6
(package
(inherit libcxxabi-9)
--
2.37.0
M
M
Maxime Devos wrote on 19 Jul 2022 21:54
Re: bug#54239: [PATCH] gnu: Add cross-clang.
57616987-f543-6b82-9490-8fc4ff30e406@telenet.be
On 16-07-2022 21:44, Julien Lepiller wrote:
Toggle quote (3 lines)
> Since I couldn't figure out how to make a package for a given target, I
> added a transformation to (guix build-system) that replaces the
> keywords to force a package to build for a given architecture.
Try:
scheme@(guix-user)> ,build (with-parameters ((%current-target-system
"aarch64-linux-gnu")) (specification->package "hello"))
[...]
$3 = "/gnu/store/rys78r4j72zh45xchq87x2y30ya8mzvi-hello-2.12.1"
Greetings,
Maxime.
Attachment: OpenPGP_signature
J
J
Julien Lepiller wrote on 19 Jul 2022 22:42
(name . Maxime Devos)(address . maximedevos@telenet.be)
20220719224206.30a88f45@sybil.lepiller.eu
Le Tue, 19 Jul 2022 21:54:16 +0200,
Maxime Devos <maximedevos@telenet.be> a écrit :

Toggle quote (21 lines)
> On 16-07-2022 21:44, Julien Lepiller wrote:
> > Since I couldn't figure out how to make a package for a given
> > target, I added a transformation to (guix build-system) that
> > replaces the keywords to force a package to build for a given
> > architecture.
>
>
> Try:
>
> scheme@(guix-user)> ,build (with-parameters ((%current-target-system
> "aarch64-linux-gnu")) (specification->package "hello"))
>
> [...]
>
> $3 = "/gnu/store/rys78r4j72zh45xchq87x2y30ya8mzvi-hello-2.12.1"
>
> Greetings,
>
> Maxime.
>

Thanks, that was a lot easier than I thought. So I removed the first
patch and changed to (with-parameters ((%current-target-system target))
base) in cross-clang.
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 54239@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 54239
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch