Subject: [PATCH 4/4] gnu: Add wasm-sandboxed.

From: Ian Eure <[email-masked]>
Date: Tue, 8 Apr 2025 12:58:29 -0700

* gnu/packages/gnuzilla.scm (wasm-sandboxed): New variable.

Change-Id: I568e6cb9aca43122a06f46fd3a8d9a462754c36a
---
 gnu/packages/gnuzilla.scm | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/gnu/packages/gnuzilla.scm b/gnu/packages/gnuzilla.scm
index f4a912d8d5..32b2d13de5 100644
--- a/gnu/packages/gnuzilla.scm
+++ b/gnu/packages/gnuzilla.scm
@@ -99,8 +99,38 @@ (define-module (gnu packages gnuzilla)
   #:use-module (gnu packages xdisorg)
   #:use-module (gnu packages readline)
   #:use-module (gnu packages sqlite)
+  #:use-module (gnu packages wasm)
   #:autoload (json parser) (json->scm))
 
+(define-public (wasm-sandboxed orig-package)
+  "Given a Firefox or Firefox-derived package ORIG-PACKAGE, return a
+variant package which enables WASM sandboxing."
+  (package
+    (inherit orig-package)
+    (name (string-append (package-name orig-package) "-wasm-sandboxed"))
+    (arguments
+     (substitute-keyword-arguments (package-arguments orig-package)
+       ((#:configure-flags flags)
+        #~(let ((wasi-sysroot #$(this-package-native-input "wasm32-wasi-clang-toolchain")))
+            (append (delq "--without-wasm-sandboxed-libraries" #$flags)
+                    (list
+                     (string-append "--with-wasi-sysroot=" wasi-sysroot "/wasm32-wasi")))))
+       ((#:phases phases)
+        #~(modify-phases #$phases
+            (add-before 'configure 'set-wasm-env
+              (lambda* (#:key inputs #:allow-other-keys)
+                (setenv "WASM_CC"
+                        (string-append (assoc-ref inputs
+                                                  "wasm32-wasi-clang-toolchain")
+                                       "/bin/clang"))
+                (setenv "WASM_CXX"
+                        (string-append (assoc-ref inputs
+                                                  "wasm32-wasi-clang-toolchain")
+                                       "/bin/clang++"))))))))
+    (native-inputs
+     (modify-inputs (package-native-inputs orig-package)
+       (append wasm32-wasi-clang-toolchain)))))
+
 (define-public mozjs
   (package
     (name "mozjs")
-- 
2.49.0