[bug#78102,v2,2/3] gnu: libcxx: Fix cross-compilation build.

Message ID 47cce130906c96519b8f1505897c3986663b6276.1745940699.git.maxim.cournoyer@gmail.com
State New
Headers
Series [bug#78102,v2,1/3] build/cmake: Add #:implicit-inputs? and #:implicit-cross-inputs? arguments. |

Commit Message

Maxim Cournoyer April 29, 2025, 3:31 p.m. UTC
* gnu/packages/llvm.scm (libcxx) [arguments] <#:implicit-inputs?>: Set to #f.
<#:phases>: Remove adjust-CPLUS_INCLUDE_PATH.
[native-inputs]: Explicitly provide standard inputs, filtering out gcc.

Change-Id: I8cbc73ef90dce0a57bf2f8198c3176932bf24185
---
 gnu/packages/llvm.scm | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)
  

Comments

Greg Hogan May 1, 2025, 4:08 p.m. UTC | #1
On Tue, Apr 29, 2025 at 11:33 AM Maxim Cournoyer
<maxim.cournoyer@gmail.com> wrote:
>
> * gnu/packages/llvm.scm (libcxx) [arguments] <#:implicit-inputs?>: Set to #f.
> <#:phases>: Remove adjust-CPLUS_INCLUDE_PATH.
> [native-inputs]: Explicitly provide standard inputs, filtering out gcc.
>
> Change-Id: I8cbc73ef90dce0a57bf2f8198c3176932bf24185
> ---
>  gnu/packages/llvm.scm | 27 ++++++++++-----------------
>  1 file changed, 10 insertions(+), 17 deletions(-)
>
> diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
> index a0f47447bee..49b6e27bff9 100644
> --- a/gnu/packages/llvm.scm
> +++ b/gnu/packages/llvm.scm
> @@ -17,7 +17,7 @@
>  ;;; Copyright © 2020 Giacomo Leidi <goodoldpaul@autistici.org>
>  ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
>  ;;; Copyright © 2021, 2022 Maxime Devos <maximedevos@telenet.be>
> -;;; Copyright © 2020, 2021, 2022, 2024 Maxim Cournoyer <maxim.cournoyer@gmail.com>
> +;;; Copyright © 2020-2022, 2024-2025 Maxim Cournoyer <maxim.cournoyer@gmail.com>
>  ;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu>
>  ;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net>
>  ;;; Copyright © 2021, 2022 Guillaume Le Vaillant <glv@posteo.net>
> @@ -52,6 +52,7 @@ (define-module (gnu packages llvm)
>    #:use-module (guix memoization)
>    #:use-module (guix search-paths)
>    #:use-module (guix utils)
> +  #:use-module (guix build-system gnu)

Should we keep this build-system section sorted?

>    #:use-module (guix build-system cmake)
>    #:use-module (guix build-system emacs)
>    #:use-module (guix build-system python)
> @@ -1905,6 +1906,7 @@ (define-public libcxx
>      (build-system cmake-build-system)
>      (arguments
>       (list
> +      #:implicit-inputs? #f             ;to avoid conflicting GCC headers
>        #:tests? #f
>        #:configure-flags
>        #~(list "-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind"
> @@ -1920,23 +1922,14 @@ (define-public libcxx
>        #~(modify-phases %standard-phases
>            (add-after 'unpack 'enter-subdirectory
>              (lambda _
> -              (chdir "runtimes")))
> -          (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
> -            (lambda* (#:key inputs #:allow-other-keys)
> -              (let ((gcc (assoc-ref inputs  "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 (delete (string-append gcc "/include/c++")
> -                                             (string-split (getenv "CPLUS_INCLUDE_PATH")
> -                                                           #\:))
> -                                     ":"))
> -                (format #t
> -                        "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
> -                        (getenv "CPLUS_INCLUDE_PATH"))
> -                #t))))))
> +              (chdir "runtimes"))))))
>      (native-inputs
> -     (list clang-19 libunwind-headers llvm python))
> +     (append (list clang-19 libunwind-headers llvm python)

Does this work to combine clang-19 with llvm-13?

> +             ;; Remove GCC from the build environment, to avoid its C++
> +             ;; headers (include/c++), which would interfere and cause build
> +             ;; failures.
> +             (map second

With the map are we not also dropping the package output as the third
field? So we wind up with a second "libc" but no "libc:static". It
might not matter here but this kind of trick is often copied into
additional packages. Can we use modify-inputs on standard-packages,
delete "gcc", and append the list of additional packages? Or revert to
the old-style inputs.

> +                  (alist-delete  "gcc" (standard-packages)))))

There is an extra space after alist-delete.

>      (home-page "https://libcxx.llvm.org")
>      (synopsis "C++ standard library")
>      (description
> --
> 2.49.0
  
Maxim Cournoyer May 2, 2025, 12:33 a.m. UTC | #2
Hi Greg,

Thanks for the review.

Greg Hogan <code@greghogan.com> writes:

[...]

>> @@ -52,6 +52,7 @@ (define-module (gnu packages llvm)
>>    #:use-module (guix memoization)
>>    #:use-module (guix search-paths)
>>    #:use-module (guix utils)
>> +  #:use-module (guix build-system gnu)
>
> Should we keep this build-system section sorted?

Definitely!  Done.

>>    #:use-module (guix build-system cmake)
>>    #:use-module (guix build-system emacs)
>>    #:use-module (guix build-system python)
>> @@ -1905,6 +1906,7 @@ (define-public libcxx
>>      (build-system cmake-build-system)
>>      (arguments
>>       (list
>> +      #:implicit-inputs? #f             ;to avoid conflicting GCC headers
>>        #:tests? #f
>>        #:configure-flags
>>        #~(list "-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind"
>> @@ -1920,23 +1922,14 @@ (define-public libcxx
>>        #~(modify-phases %standard-phases
>>            (add-after 'unpack 'enter-subdirectory
>>              (lambda _
>> -              (chdir "runtimes")))
>> -          (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
>> -            (lambda* (#:key inputs #:allow-other-keys)
>> -              (let ((gcc (assoc-ref inputs  "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 (delete (string-append gcc "/include/c++")
>> -                                             (string-split (getenv "CPLUS_INCLUDE_PATH")
>> -                                                           #\:))
>> -                                     ":"))
>> -                (format #t
>> -                        "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
>> -                        (getenv "CPLUS_INCLUDE_PATH"))
>> -                #t))))))
>> +              (chdir "runtimes"))))))
>>      (native-inputs
>> -     (list clang-19 libunwind-headers llvm python))
>> +     (append (list clang-19 libunwind-headers llvm python)
>
> Does this work to combine clang-19 with llvm-13?

Good catch.  It worked, because both llvm and libunwind-headers appeared
to be extraneous inputs, which I've now removed.

>
>> +             ;; Remove GCC from the build environment, to avoid its C++
>> +             ;; headers (include/c++), which would interfere and cause build
>> +             ;; failures.
>> +             (map second
>
> With the map are we not also dropping the package output as the third
> field? So we wind up with a second "libc" but no "libc:static". It
> might not matter here but this kind of trick is often copied into
> additional packages. Can we use modify-inputs on standard-packages,
> delete "gcc", and append the list of additional packages? Or revert to
> the old-style inputs.

Good point, I've rewritten it to use modify-inputs.  I don't think we
should use old-style inputs in any case now.

>> +                  (alist-delete  "gcc" (standard-packages)))))
>
> There is an extra space after alist-delete.

Fixed!

Thanks again for the review!  I'll push shortly.
  

Patch

diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index a0f47447bee..49b6e27bff9 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -17,7 +17,7 @@ 
 ;;; Copyright © 2020 Giacomo Leidi <goodoldpaul@autistici.org>
 ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
 ;;; Copyright © 2021, 2022 Maxime Devos <maximedevos@telenet.be>
-;;; Copyright © 2020, 2021, 2022, 2024 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2020-2022, 2024-2025 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu>
 ;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net>
 ;;; Copyright © 2021, 2022 Guillaume Le Vaillant <glv@posteo.net>
@@ -52,6 +52,7 @@  (define-module (gnu packages llvm)
   #:use-module (guix memoization)
   #:use-module (guix search-paths)
   #:use-module (guix utils)
+  #:use-module (guix build-system gnu)
   #:use-module (guix build-system cmake)
   #:use-module (guix build-system emacs)
   #:use-module (guix build-system python)
@@ -1905,6 +1906,7 @@  (define-public libcxx
     (build-system cmake-build-system)
     (arguments
      (list
+      #:implicit-inputs? #f             ;to avoid conflicting GCC headers
       #:tests? #f
       #:configure-flags
       #~(list "-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind"
@@ -1920,23 +1922,14 @@  (define-public libcxx
       #~(modify-phases %standard-phases
           (add-after 'unpack 'enter-subdirectory
             (lambda _
-              (chdir "runtimes")))
-          (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
-            (lambda* (#:key inputs #:allow-other-keys)
-              (let ((gcc (assoc-ref inputs  "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 (delete (string-append gcc "/include/c++")
-                                             (string-split (getenv "CPLUS_INCLUDE_PATH")
-                                                           #\:))
-                                     ":"))
-                (format #t
-                        "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
-                        (getenv "CPLUS_INCLUDE_PATH"))
-                #t))))))
+              (chdir "runtimes"))))))
     (native-inputs
-     (list clang-19 libunwind-headers llvm python))
+     (append (list clang-19 libunwind-headers llvm python)
+             ;; Remove GCC from the build environment, to avoid its C++
+             ;; headers (include/c++), which would interfere and cause build
+             ;; failures.
+             (map second
+                  (alist-delete  "gcc" (standard-packages)))))
     (home-page "https://libcxx.llvm.org")
     (synopsis "C++ standard library")
     (description