From 7101805a348c7eca98ece49bea0d9d202f7089e3 Mon Sep 17 00:00:00 2001 From: Bryan Tan Date: Mon, 26 May 2025 15:05:49 -0700 Subject: [PATCH] emscripten: patch bugs involving EM_CACHE permissions As a workaround for https://github.com/NixOS/nixpkgs/issues/282509, packages built with `emscriptenStdenv` need to set the `EM_CACHE` environment variable to a folder in the build directory, so that emscripten uses a copy of the sysroot cache instead of attempting to write to the sysroot in the Nix store. However, due to the bug https://github.com/emscripten-core/emscripten/issues/24404, the copied cache has the same permission bits as the (readonly) one in the Nix store, resulting in "Permission Denied" errors. This bug has since been fixed in upstream emscripten, so we can backport the relevant patches. --- pkgs/development/compilers/emscripten/default.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/development/compilers/emscripten/default.nix b/pkgs/development/compilers/emscripten/default.nix index 01d038a687d7..c168f87ab64b 100644 --- a/pkgs/development/compilers/emscripten/default.nix +++ b/pkgs/development/compilers/emscripten/default.nix @@ -2,6 +2,7 @@ lib, stdenv, fetchFromGitHub, + fetchpatch, python3, nodejs, closurecompiler, @@ -60,6 +61,17 @@ stdenv.mkDerivation rec { (replaceVars ./0001-emulate-clang-sysroot-include-logic.patch { resourceDir = "${llvmEnv}/lib/clang/${lib.versions.major llvmPackages.llvm.version}/"; }) + # The following patches work around a bug where EM_CACHE is not copied with + # the correct permissions; the bug will be fixed in the next release (probably 4.0.10). + # See also: https://github.com/emscripten-core/emscripten/issues/24404 + (fetchpatch { + url = "https://github.com/emscripten-core/emscripten/commit/99c6e41154f701e423074e33a4fdaf5eea49d073.patch"; + hash = "sha256-/wkhz08NhbgxsrXd7YFfdCGX6LrS2Ncct8dcwxBMsjY="; + }) + (fetchpatch { + url = "https://github.com/emscripten-core/emscripten/commit/f4d358d740a238b67a1d6935e71638519d25afa0.patch"; + hash = "sha256-hib5ZAN/R2dH+rTv3nYF37+xKZmeboKxnS+5mkht2lM="; + }) ]; buildPhase = ''