@@ -15,7 +15,9 @@
1515, rust-cbindgen, nodejs, nasm, fetchpatch
1616, gnum4
1717, gtk3, wrapGAppsHook
18+, pkgsCross
1819, debugBuild ? false
20+, runCommand
1921
2022### optionals
2123
@@ -121,6 +123,15 @@ let
121123 })
122124 else stdenv;
123125
126+ # Compile the wasm32 sysroot to build the RLBox Sandbox
127+ # https://hacks.mozilla.org/2021/12/webassembly-and-back-again-fine-grained-sandboxing-in-firefox-95/
128+ # We only link c++ libs here, our compiler wrapper can find wasi libc and crt itself.
129+ wasiSysRoot = runCommand "wasi-sysroot" {} ''
130+ mkdir -p $out/lib/wasm32-wasi
131+ for lib in ${pkgsCross.wasi32.llvmPackages.libcxx}/lib/* ${pkgsCross.wasi32.llvmPackages.libcxxabi}/lib/*; do
132+ ln -s $lib $out/lib/wasm32-wasi
133+ done
134+ '';
124135in
125136
126137buildStdenv.mkDerivation ({
@@ -213,7 +224,11 @@ buildStdenv.mkDerivation ({
213224 configureScript="$(realpath ./mach) configure"
214225 export MOZBUILD_STATE_PATH=$(pwd)/mozbuild
215226
216− '' + (lib.optionalString googleAPISupport ''
227+ '' + (lib.optionalString (lib.versionAtLeast version "95.0") ''
228+ # RBox WASM Sandboxing
229+ export WASM_CC=${pkgsCross.wasi32.stdenv.cc}/bin/${pkgsCross.wasi32.stdenv.cc.targetPrefix}cc
230+ export WASM_CXX=${pkgsCross.wasi32.stdenv.cc}/bin/${pkgsCross.wasi32.stdenv.cc.targetPrefix}c++
231+ '') + (lib.optionalString googleAPISupport ''
217232 # Google API key used by Chromium and Firefox.
218233 # Note: These are for NixOS/nixpkgs use ONLY. For your own distribution,
219234 # please get your own set of keys.
@@ -258,6 +273,7 @@ buildStdenv.mkDerivation ({
258273 ++ lib.optional ltoSupport "--enable-lto=cross" # Cross-language LTO.
259274 ++ lib.optional (ltoSupport && (buildStdenv.isAarch32 || buildStdenv.isi686 || buildStdenv.isx86_64)) "--disable-elf-hack"
260275 ++ lib.optional (ltoSupport && !buildStdenv.isDarwin) "--enable-linker=lld"
276+ ++ lib.optional (lib.versionAtLeast version "95") "--with-wasi-sysroot=${wasiSysRoot}"
261277
262278 ++ flag alsaSupport "alsa"
263279 ++ flag pulseaudioSupport "pulseaudio"
@@ -277,7 +293,6 @@ buildStdenv.mkDerivation ({
277293 ++ lib.optionals enableDebugSymbols [ "--disable-strip" "--disable-install-strip" ]
278294
279295 ++ lib.optional enableOfficialBranding "--enable-official-branding"
280− ++ lib.optional (lib.versionAtLeast version "95") "--without-wasm-sandboxed-libraries"
281296 ++ extraConfigureFlags;
282297
283298 postConfigure = ''
@@ -356,6 +371,7 @@ buildStdenv.mkDerivation ({
356371 inherit applicationName;
357372 inherit tests;
358373 inherit gtk3;
374+ inherit wasiSysRoot;
359375 } // extraPassthru;
360376
361377 hardeningDisable = [ "format" ]; # -Werror=format-security