about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGabriel Ebner <gebner@gebner.org>2020-08-29 14:14:20 +0200
committerAlyssa Ross <hi@alyssa.is>2020-11-27 13:28:10 +0000
commit033649ccbdba51a00e38d8a680263493f6eff23b (patch)
treebd57f01c22f3ef069162aa2de172ce7807abe6ce
parentd8e12be3afabf4ce83327f443fb0320c97c09601 (diff)
downloadnixlib-033649ccbdba51a00e38d8a680263493f6eff23b.tar
nixlib-033649ccbdba51a00e38d8a680263493f6eff23b.tar.gz
nixlib-033649ccbdba51a00e38d8a680263493f6eff23b.tar.bz2
nixlib-033649ccbdba51a00e38d8a680263493f6eff23b.tar.lz
nixlib-033649ccbdba51a00e38d8a680263493f6eff23b.tar.xz
nixlib-033649ccbdba51a00e38d8a680263493f6eff23b.tar.zst
nixlib-033649ccbdba51a00e38d8a680263493f6eff23b.zip
emscripten: precompile libraries for wasm2c
(cherry picked from commit ad330434031519fd5dd7e52f32d7d8a30f36a4db)
-rw-r--r--nixpkgs/pkgs/development/compilers/emscripten/default.nix25
1 files changed, 18 insertions, 7 deletions
diff --git a/nixpkgs/pkgs/development/compilers/emscripten/default.nix b/nixpkgs/pkgs/development/compilers/emscripten/default.nix
index 0b43017aa120..ac13f9559305 100644
--- a/nixpkgs/pkgs/development/compilers/emscripten/default.nix
+++ b/nixpkgs/pkgs/development/compilers/emscripten/default.nix
@@ -61,6 +61,10 @@ stdenv.mkDerivation rec {
     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 = ''
@@ -77,16 +81,23 @@ stdenv.mkDerivation rec {
         --set PYTHON ${python3}/bin/python
     done
 
-    # precompile libc in all four variants:
-    # wasm, wasm-pic, wasm-lto, wasm-lto-pic
+    # 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
-    for lto in wasm2 wasmlto2; do
-      for pic in test_hello_world test_relocatable_void_function; do
-        python tests/runner.py $lto.$pic
-      done
-    done
+    python tests/runner.py test_hello_world
     popd
   '';