Subject: Re: [bug#77653] [PATCH 1/4] gnu: Add wasi-libc.

From: Z572 <[email-masked]>
Date: Wed, 09 Apr 2025 10:54:56 +0800

Ian Eure <[email-masked]> writes:

> * gnu/packages/wasm.scm (wasi-libc): New variable.
>
> Change-Id: I1aefc4573424e19119d225904b5461b1bea0221e
> ---
>  gnu/packages/wasm.scm | 78 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 78 insertions(+)
>  create mode 100644 gnu/packages/wasm.scm
>
> diff --git a/gnu/packages/wasm.scm b/gnu/packages/wasm.scm
> new file mode 100644
> index 0000000000..060e1e420f
> --- /dev/null
> +++ b/gnu/packages/wasm.scm
> @@ -0,0 +1,78 @@
> +;;; GNU Guix --- Functional package management for GNU
> +;;; Copyright © 2022-2023 Pierre Langlois <[email-masked]>
> +;;; Copyright © 2023, 2024, 2025 Ian Eure <[email-masked]>
> +;;;
> +;;; This file is part of GNU Guix.
> +;;;
> +;;; GNU Guix is free software; you can redistribute it and/or modify it
> +;;; under the terms of the GNU General Public License as published by
> +;;; the Free Software Foundation; either version 3 of the License, or (at
> +;;; your option) any later version.
> +;;;
> +;;; GNU Guix is distributed in the hope that it will be useful, but
> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;;; GNU General Public License for more details.
> +;;;
> +;;; You should have received a copy of the GNU General Public License
> +;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
> +
> +(define-module (gnu packages wasm)
> +  #:use-module (gnu packages llvm)
> +  #:use-module (guix base32)
> +  #:use-module (guix build-system gnu)
> +  #:use-module (guix gexp)
> +  #:use-module (guix git-download)
> +  #:use-module ((guix licenses) #:prefix license:)
> +  #:use-module (guix packages))
> +
> +(define-public wasi-libc
> +  (package
> +    (name "wasi-libc")
> +    (version "sdk-20")

i think sould "20"

> +    (source (origin
> +              (method git-fetch)
> +              (uri (git-reference
> +                    (url "https://github.com/WebAssembly/wasi-libc")
> +                    (commit (string-append "wasi-" version))
                                              "wasi-sdk-"
> +                    (recursive? #t)))

Why do we need recursive

> +              (file-name (git-file-name name version))
> +              (sha256
> +               (base32
> +                "0knm5ch499dksmv1k0kh7356pjd9n1gjn0p3vp9bw57mn478zp8z"))))
> +    (build-system gnu-build-system)
> +    (native-inputs (list clang-16))

Please add a comment why clang-16 is needed instead of clang.

> +    (arguments
> +     (list #:tests? #f ;No test suite
> +           ;; Firefox uses wasm2c to compile WebAssembly to C code, and it
> +           ;; does not support the memory.copy opcode.
> +           ;; See https://bugzilla.mozilla.org/show_bug.cgi?id=1773200#c4
> +           #:make-flags ''("BULK_MEMORY_SOURCES=")
                           #~(list "BULK_MEMORY_SOURCES=")
> +           #:phases
> +           #~(modify-phases %standard-phases
> +               (delete 'configure)
> +               (add-before 'build 'set-sysroot-include
> +                 (lambda _
> +                   (setenv "C_INCLUDE_PATH"
> +                           (string-append (getcwd) "/sysroot/include"))))
> +               (add-before 'install 'set-install-dir
> +                 (lambda _
> +                   (setenv "INSTALL_DIR"
> +                           (string-append #$output "/wasm32-wasi")))))))
> +    (home-page "https://wasi.dev")
> +    (synopsis "WASI libc implementation for WebAssembly")
> +    (description
> +     "WASI Libc is a libc for WebAssembly programs built on top of WASI
> +system calls.  It provides a wide array of POSIX-compatible C APIs, including
> +support for standard I/O, file I/O, filesystem manipulation, memory
> +management, time, string, environment variables, program startup, and many
> +other APIs.")
> +    (license (list
> +              ;; For wasi-libc, with LLVM exceptions
> +              license:asl2.0
> +              ;; For malloc.c.
> +              license:cc0
> +              ;; For cloudlibc.
> +              license:bsd-2
> +              ;; For wasi-libc and musl-libc.
> +              license:expat))))