about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/emscripten
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/emscripten')
-rw-r--r--nixpkgs/pkgs/development/compilers/emscripten/default.nix70
-rw-r--r--nixpkgs/pkgs/development/compilers/emscripten/fastcomp/default.nix28
-rw-r--r--nixpkgs/pkgs/development/compilers/emscripten/fastcomp/emscripten-fastcomp.nix55
3 files changed, 153 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/compilers/emscripten/default.nix b/nixpkgs/pkgs/development/compilers/emscripten/default.nix
new file mode 100644
index 000000000000..e03039cb5e14
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/emscripten/default.nix
@@ -0,0 +1,70 @@
+{ emscriptenVersion, stdenv, fetchFromGitHub, emscriptenfastcomp, python, nodejs, closurecompiler
+, jre, binaryen, enableWasm ? true ,  cmake
+}:
+
+let
+  rev = emscriptenVersion;
+  appdir = "share/emscripten";
+  binaryenVersioned = binaryen.override { emscriptenRev = rev; };
+in
+
+stdenv.mkDerivation {
+  name = "emscripten-${rev}";
+
+  src = fetchFromGitHub {
+    owner = "kripken";
+    repo = "emscripten";
+    sha256 = "02p0cp86vd1mydlpq544xbydggpnrq9dhbxx7h08j235frjm5cdc";
+    inherit rev;
+  };
+
+  buildInputs = [ nodejs cmake python ];
+
+  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
+    # 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 -----------------"
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/kripken/emscripten;
+    description = "An LLVM-to-JavaScript Compiler";
+    platforms = platforms.all;
+    maintainers = with maintainers; [ qknight matthewbauer ];
+    license = licenses.ncsa;
+  };
+}
diff --git a/nixpkgs/pkgs/development/compilers/emscripten/fastcomp/default.nix b/nixpkgs/pkgs/development/compilers/emscripten/fastcomp/default.nix
new file mode 100644
index 000000000000..57496d288605
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/emscripten/fastcomp/default.nix
@@ -0,0 +1,28 @@
+{ newScope, stdenv, binutils, wrapCCWith, symlinkJoin }:
+let
+  callPackage = newScope (self // {inherit stdenv;});
+
+  self = {
+    emscriptenfastcomp-unwrapped = callPackage ./emscripten-fastcomp.nix {};
+    emscriptenfastcomp-wrapped = wrapCCWith {
+      cc = self.emscriptenfastcomp-unwrapped;
+      # Never want Apple's cctools for WASM target
+      bintools = binutils;
+      libc = stdenv.cc.libc;
+      extraBuildCommands = ''
+        # hardening flags break WASM support
+        cat > $out/nix-support/add-hardening.sh
+      '';
+    };
+    emscriptenfastcomp = symlinkJoin {
+      name = "emscriptenfastcomp-${stdenv.lib.getVersion self.emscriptenfastcomp-unwrapped}";
+      paths = [ self.emscriptenfastcomp-wrapped self.emscriptenfastcomp-unwrapped ];
+      preferLocalBuild = false;
+      allowSubstitutes = true;
+      postBuild = ''
+        # replace unwrapped clang-3.9 binary by wrapper
+        ln -sf $out/bin/clang $out/bin/clang-[0-9]*
+      '';
+    };
+  };
+in self
diff --git a/nixpkgs/pkgs/development/compilers/emscripten/fastcomp/emscripten-fastcomp.nix b/nixpkgs/pkgs/development/compilers/emscripten/fastcomp/emscripten-fastcomp.nix
new file mode 100644
index 000000000000..06acebd2ba4a
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/emscripten/fastcomp/emscripten-fastcomp.nix
@@ -0,0 +1,55 @@
+{ emscriptenVersion, stdenv, fetchFromGitHub, cmake, python, gtest, ... }:
+
+let
+  rev = emscriptenVersion;
+  gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
+in
+stdenv.mkDerivation rec {
+  name = "emscripten-fastcomp-${rev}";
+
+  src = fetchFromGitHub {
+    owner = "kripken";
+    repo = "emscripten-fastcomp";
+    sha256 = "04j698gmp686b5lricjakm5hyh2z2kh28m1ffkghmkyz4zkzmx98";
+    inherit rev;
+  };
+
+  srcFL = fetchFromGitHub {
+    owner = "kripken";
+    repo = "emscripten-fastcomp-clang";
+    sha256 = "1ici51mmpgg80xk3y8f376nbbfak6rz27qdy98l8lxkrymklp5g5";
+    inherit rev;
+  };
+
+  nativeBuildInputs = [ cmake python gtest ];
+  preConfigure = ''
+    cp -Lr ${srcFL} tools/clang
+    chmod +w -R tools/clang
+  '';
+  cmakeFlags = [
+    "-DCMAKE_BUILD_TYPE=Release"
+    "-DLLVM_TARGETS_TO_BUILD='X86;JSBackend'"
+    "-DLLVM_INCLUDE_EXAMPLES=OFF"
+    "-DLLVM_INCLUDE_TESTS=ON"
+    #"-DLLVM_CONFIG=${llvm}/bin/llvm-config"
+    "-DLLVM_BUILD_TESTS=ON"
+    "-DCLANG_INCLUDE_TESTS=ON"
+  ] ++ (stdenv.lib.optional stdenv.isLinux
+    # necessary for clang to find crtend.o
+    "-DGCC_INSTALL_PREFIX=${gcc}"
+  );
+  enableParallelBuilding = true;
+
+  passthru = {
+    isClang = true;
+    inherit gcc;
+  };
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/kripken/emscripten-fastcomp;
+    description = "Emscripten LLVM";
+    platforms = platforms.all;
+    maintainers = with maintainers; [ qknight matthewbauer ];
+    license = stdenv.lib.licenses.ncsa;
+  };
+}