Subject: [bug#77653] [PATCH 3/4] gnu: Add wasm32-wasi-clang.

From: Maxim Cournoyer <[email-masked]>
Date: Fri, 25 Apr 2025 21:52:32 +0900

Hi,

Ian Eure <[email-masked]> writes:

> * gnu/packages/wasm.scm (wasm32-wasi-clang): New variable.
>
> Change-Id: Ibf1df3e93929442a8eed29eea20b2f83b491f3b3

[...]

> --- a/gnu/packages/wasm.scm
> +++ b/gnu/packages/wasm.scm
> @@ -24,7 +24,8 @@ (define-module (gnu packages wasm)
>    #:use-module (guix gexp)
>    #:use-module (guix git-download)
>    #:use-module ((guix licenses) #:prefix license:)
> -  #:use-module (guix packages))
> +  #:use-module (guix packages)
> +  #:use-module (guix utils))
>  
>  (define-public wasi-libc
>    (package
> @@ -106,3 +107,29 @@ (define-public wasm32-wasi-clang-runtime
>                ;; WASM only needs libclang_rt.builtins-wasm32.a from
>                ;; compiler-rt.
>                "../source/compiler-rt/lib/builtins")))))
> +
> +;; Although Clang can be built to support multiple compilation targets, Guix
> +;; builds only target the native architecture, so we have to build a build a
> +;; new toolchain that to target WASM.
> +
> +(define clang-from-llvm (@@ (gnu packages llvm) clang-from-llvm))
> +(define llvm-monorepo (@@ (gnu packages llvm) llvm-monorepo))
> +
> +(define-public wasm32-wasi-clang
> +  (let ((base (clang-from-llvm llvm-16 wasm32-wasi-clang-runtime)))
> +    (package (inherit base)

As explained previously, this should be package/inherit, and this new
clang variant should live in the same module as clang in (gnu packages
llvm).

> +      (name "wasm32-wasi-clang")
> +      (inputs
> +       (modify-inputs (package-inputs base)
> +         (prepend wasi-libc)))
> +      (arguments
> +       (substitute-keyword-arguments (package-arguments base)
> +         ((#:configure-flags flags)

Since it seems you strictly want to override #:configure-flags rather
than extend it, a better choice would be `ensure-keyword-arguments'.

> +          #~(list "-DCLANG_INCLUDE_TESTS=True"
> +                  ;; Use a sane default include directory.
> +                  (string-append "-DC_INCLUDE_DIRS="
> +                                 #$wasi-libc
> +                                 "/wasm32-wasi/include")))

It seems to be /include or /include/wasm32-wasi would be a "saner"
default :-).

> +         ((#:phases phases)
> +          `(modify-phases ,phases
> +             (delete 'symlink-cfi_ignorelist))))))))

Why is the above necessary?  A comment could help.

-- 
Thanks,
Maxim