diff options
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/emscripten/default.nix')
-rw-r--r-- | nixpkgs/pkgs/development/compilers/emscripten/default.nix | 137 |
1 files changed, 89 insertions, 48 deletions
diff --git a/nixpkgs/pkgs/development/compilers/emscripten/default.nix b/nixpkgs/pkgs/development/compilers/emscripten/default.nix index cd5142acce8..ac13f955930 100644 --- a/nixpkgs/pkgs/development/compilers/emscripten/default.nix +++ b/nixpkgs/pkgs/development/compilers/emscripten/default.nix @@ -1,63 +1,104 @@ -{ emscriptenVersion, stdenv, fetchFromGitHub, emscriptenfastcomp, python, nodejs, closurecompiler -, jre, binaryen, enableWasm ? true , cmake +{ stdenv, fetchFromGitHub, python3, nodejs, closurecompiler +, jre, binaryen +, llvmPackages_11 +, symlinkJoin, makeWrapper +, mkYarnModules }: -let - rev = emscriptenVersion; - appdir = "share/emscripten"; - binaryenVersioned = binaryen.override { emscriptenRev = rev; }; -in +stdenv.mkDerivation rec { + pname = "emscripten"; + version = "2.0.1"; -stdenv.mkDerivation { - name = "emscripten-${rev}"; + llvmEnv = symlinkJoin { + name = "emscripten-llvm-${version}"; + paths = with llvmPackages_11; [ clang-unwrapped lld llvm ]; + }; + + nodeModules = mkYarnModules { + name = "emscripten-node-modules-${version}"; + inherit pname version; + # it is vitally important the the package.json has name and version fields + packageJSON = ./package.json; + yarnLock = ./yarn.lock; + yarnNix = ./yarn.nix; + }; src = fetchFromGitHub { owner = "emscripten-core"; repo = "emscripten"; - sha256 = "1j3f0hpy05qskaiyv75l7wv4n0nzxhrh9b296zchx3f6f9h2rghq"; - inherit rev; + sha256 = "06dsd819qjv4n2ihrz1mpn5aigmbv0gpkm7iw06wrqx30nzphnpk"; + rev = version; }; - buildInputs = [ nodejs cmake python ]; + nativeBuildInputs = [ makeWrapper ]; + buildInputs = [ nodejs python3 ]; + + buildPhase = '' + patchShebangs . - buildCommand = '' - mkdir -p $out/${appdir} - cp -r $src/* $out/${appdir} - chmod -R +w $out/${appdir} - grep -rl '^#!/usr.*python' $out/${appdir} | xargs sed -i -s 's@^#!/usr.*python.*@#!${python}/bin/python@' - sed -i -e "s,EM_CONFIG = '~/.emscripten',EM_CONFIG = '$out/${appdir}/config'," $out/${appdir}/tools/shared.py - sed -i -e 's,^.*did not see a source tree above the LLVM.*$, return True,' $out/${appdir}/tools/shared.py - sed -i -e 's,def check_sanity(force=False):,def check_sanity(force=False):\n return,' $out/${appdir}/tools/shared.py # fixes cmake support - sed -i -e "s/print \('emcc (Emscript.*\)/sys.stderr.write(\1); sys.stderr.flush()/g" $out/${appdir}/emcc.py - mkdir $out/bin - ln -s $out/${appdir}/{em++,em-config,emar,embuilder.py,emcc,emcmake,emconfigure,emlink.py,emmake,emranlib,emrun,emscons} $out/bin - - echo "EMSCRIPTEN_ROOT = '$out/${appdir}'" > $out/${appdir}/config - echo "LLVM_ROOT = '${emscriptenfastcomp}/bin'" >> $out/${appdir}/config - echo "PYTHON = '${python}/bin/python'" >> $out/${appdir}/config - echo "NODE_JS = '${nodejs}/bin/node'" >> $out/${appdir}/config - echo "JS_ENGINES = [NODE_JS]" >> $out/${appdir}/config - echo "COMPILER_ENGINE = NODE_JS" >> $out/${appdir}/config - echo "CLOSURE_COMPILER = '${closurecompiler}/share/java/closure-compiler-v${closurecompiler.version}.jar'" >> $out/${appdir}/config - echo "JAVA = '${jre}/bin/java'" >> $out/${appdir}/config + sed -i -e "s/print \('emcc (Emscript.*\)/sys.stderr.write(\1); sys.stderr.flush()/g" emcc.py + + # disables cache in user home, use installation directory instead + sed -i '/^def/!s/root_is_writable()/True/' tools/shared.py + sed -i "/^def check_sanity/a\\ return" tools/shared.py + + # required for wasm2c + ln -s ${nodeModules}/node_modules . + + echo "EMSCRIPTEN_ROOT = '$appdir'" > .emscripten + echo "LLVM_ROOT = '${llvmEnv}/bin'" >> .emscripten + echo "NODE_JS = '${nodejs}/bin/node'" >> .emscripten + echo "JS_ENGINES = [NODE_JS]" >> .emscripten + echo "CLOSURE_COMPILER = ['${closurecompiler}/bin/closure-compiler']" >> .emscripten + echo "JAVA = '${jre}/bin/java'" >> .emscripten # to make the test(s) below work - echo "SPIDERMONKEY_ENGINE = []" >> $out/${appdir}/config - '' - + stdenv.lib.optionalString enableWasm '' - echo "BINARYEN_ROOT = '${binaryenVersioned}'" >> $out/share/emscripten/config - '' - + - '' - echo "--------------- running test -----------------" - # quick hack to get the test working - HOME=$TMPDIR - cp $out/${appdir}/config $HOME/.emscripten - export PATH=$PATH:$out/bin - - #export EMCC_DEBUG=2 - ${python}/bin/python $src/tests/runner.py test_hello_world - echo "--------------- /running test -----------------" + # echo "SPIDERMONKEY_ENGINE = []" >> .emscripten + echo "BINARYEN_ROOT = '${binaryen}'" >> .emscripten + + # make emconfigure/emcmake use the correct (wrapped) binaries + sed -i "s|^EMCC =.*|EMCC='$out/bin/emcc'|" tools/shared.py + sed -i "s|^EMXX =.*|EMXX='$out/bin/em++'|" tools/shared.py + sed -i "s|^EMAR =.*|EMAR='$out/bin/emar'|" tools/shared.py + sed -i "s|^EMRANLIB =.*|EMRANLIB='$out/bin/emranlib'|" tools/shared.py + + # The tests use the C compiler to compile generated C code, + # use the wrapped compiler + sed -i 's/shared.CLANG_CC/"cc"/' tests/runner.py + ''; + + installPhase = '' + appdir=$out/share/emscripten + mkdir -p $appdir + cp -r . $appdir + chmod -R +w $appdir + + mkdir -p $out/bin + for b in em++ em-config emar embuilder.py emcc emcmake emconfigure emlink.py emmake emranlib emrun emscons; do + makeWrapper $appdir/$b $out/bin/$b \ + --set NODE_PATH ${nodeModules}/node_modules \ + --set EM_EXCLUSIVE_CACHE_ACCESS 1 \ + --set PYTHON ${python3}/bin/python + done + + # precompile libc (etc.) in all variants: + pushd $TMPDIR + echo 'int main() { return 42; }' >test.c + for LTO in -flto ""; do + # wasm2c doesn't work with PIC + $out/bin/emcc -s WASM2C -s STANDALONE_WASM $LTO test.c + + for RELOCATABLE in "" "-s RELOCATABLE"; do + $out/bin/emcc $RELOCATABLE $LTO test.c + done + done + popd + + export PYTHON=${python3}/bin/python + export NODE_PATH=${nodeModules}/node_modules + pushd $appdir + python tests/runner.py test_hello_world + popd ''; meta = with stdenv.lib; { |