Skip to content

Add emscripten overlay with fixes needed for ghcjs #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions overlays/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let
armv6l-linux = import ./armv6l-linux.nix;
musl = import ./musl.nix;
tools = import ./tools.nix;
emscripten = import ./emscripten.nix;
};

composeExtensions = f: g: final: prev:
Expand All @@ -38,6 +39,7 @@ let
armv6l-linux
musl
tools
emscripten
# Restore nixpkgs haskell and haskellPackages
(_: prev: { inherit (prev.haskell-nix-prev) haskell haskellPackages; })
];
Expand Down
20 changes: 20 additions & 0 deletions overlays/emscripten.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
final: prev: with final; {

binaryen = callPackage ./emscripten/binaryen.nix {};

emscriptenVersion = "1.39.1";

emscripten = callPackage ./emscripten { };

emscriptenfastcompPackages = dontRecurseIntoAttrs (callPackage ./emscripten/fastcomp { });

emscriptenfastcomp = emscriptenfastcompPackages.emscriptenfastcomp;

emscriptenupstreamPackages = dontRecurseIntoAttrs (callPackage ./emscripten/upstream { });

emscriptenupstream = emscriptenupstreamPackages.emscriptenupstream;

# emscriptenPackages = recurseIntoAttrs (callPackage ./emscripten-packages.nix { });

emscriptenStdenv = stdenv // { mkDerivation = buildEmscriptenPackage; };
}
46 changes: 46 additions & 0 deletions overlays/emscripten/binaryen.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{ stdenv, cmake, python3, fetchFromGitHub, emscriptenRev ? null, substituteAll }:

let
defaultVersion = "93";

# Map from git revs to SHA256 hashes
sha256s = {
version_93 = "15y3703ha6mxcq168br0wlydas5rq66msrcsd650zrjz0ndxwsfx";
"1.39.1" = "0ygm9m5322h4vfpf3j63q32qxk2l26yk62hh7dkb49j51zwl1y3y";
};
in

stdenv.mkDerivation rec {
version = if emscriptenRev == null
then defaultVersion
else "emscripten-${emscriptenRev}";
rev = if emscriptenRev == null
then "version_${version}"
else emscriptenRev;
pname = "binaryen";

src = fetchFromGitHub {
owner = "WebAssembly";
repo = "binaryen";
sha256 =
if builtins.hasAttr rev sha256s
then builtins.getAttr rev sha256s
else null;
inherit rev;
};

patches = stdenv.lib.optional (emscriptenRev != null) (substituteAll {
src = ./0001-Get-rid-of-git-dependency.patch;
emscriptenv = "1.39.1";
});

nativeBuildInputs = [ cmake python3 ];

meta = with stdenv.lib; {
homepage = "https://github.com/WebAssembly/binaryen";
description = "Compiler infrastructure and toolchain library for WebAssembly, in C++";
platforms = platforms.all;
maintainers = with maintainers; [ asppsa ];
license = licenses.asl20;
};
}
71 changes: 71 additions & 0 deletions overlays/emscripten/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{ emscriptenVersion, stdenv, fetchFromGitHub, emscriptenfastcomp, python, nodejs, closurecompiler
, jre, binaryen, enableWasm ? true , cmake, emscriptenBackend ? emscriptenfastcomp
}:

let
rev = emscriptenVersion;
appdir = "share/emscripten";
binaryenVersioned = binaryen;
in

stdenv.mkDerivation {
name = "emscripten-${rev}";

src = fetchFromGitHub {
owner = "emscripten-core";
repo = "emscripten";
sha256 = "10f2mlwh4s6v3rqghb7zdmv4ry0a4si915x4v17vp4nv7swkkwhn";
rev = "fc6a4bb97b421b6dcf5806d0dc42ab8ddd4da026";
};

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,emar.py,embuilder.py,emcc,emcc.py,emcmake,emconfigure,emlink.py,emmake,emranlib,emranlib.py,emrun,emscons} $out/bin

echo "EMSCRIPTEN_ROOT = '$out/${appdir}'" > $out/${appdir}/config
echo "LLVM_ROOT = '${emscriptenBackend}/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
echo "EMCC_FAST_COMPILER = 0" >> $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/emscripten-core/emscripten";
description = "An LLVM-to-JavaScript Compiler";
platforms = platforms.all;
maintainers = with maintainers; [ qknight matthewbauer ];
license = licenses.ncsa;
};
}
28 changes: 28 additions & 0 deletions overlays/emscripten/fastcomp/default.nix
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions overlays/emscripten/fastcomp/emscripten-fastcomp.nix
Original file line number Diff line number Diff line change
@@ -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 = "emscripten-core";
repo = "emscripten-fastcomp";
sha256 = "0bd0l5k2fa4k0nax2cpxi003pqffqivx4z4m2j5xdha1a12sid8i";
inherit rev;
};

srcFL = fetchFromGitHub {
owner = "emscripten-core";
repo = "emscripten-fastcomp-clang";
sha256 = "1iw2qplhp489qzw0rma73sab7asnm27g4m95sr36c6kq9cq6agri";
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/emscripten-core/emscripten-fastcomp";
description = "Emscripten LLVM";
platforms = platforms.all;
maintainers = with maintainers; [ qknight matthewbauer ];
license = stdenv.lib.licenses.ncsa;
};
}
28 changes: 28 additions & 0 deletions overlays/emscripten/upstream/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ newScope, stdenv, binutils, wrapCCWith, symlinkJoin }:
let
callPackage = newScope (self // {inherit stdenv;});

self = {
emscriptenupstream-unwrapped = callPackage ./emscripten-upstream.nix {};
emscriptenupstream-wrapped = wrapCCWith {
cc = self.emscriptenupstream-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
'';
};
emscriptenupstream = symlinkJoin {
name = "emscriptenupstream-${stdenv.lib.getVersion self.emscriptenupstream-unwrapped}";
paths = [ self.emscriptenupstream-wrapped self.emscriptenupstream-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
60 changes: 60 additions & 0 deletions overlays/emscripten/upstream/emscripten-upstream.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{ emscriptenVersion, stdenv, fetchFromGitHub, cmake, python, gtest, ... }:

let
gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
in
stdenv.mkDerivation rec {
name = "emscripten-upstream";

src = (fetchFromGitHub {
owner = "llvm";
repo = "llvm-project";
rev = "5f7ea85e789d5b5f3f463e538a28c040e373620b";
sha256 = "1kik1zdl1igkdri9zkdri7jwjjfjwhzniaw2a57lr80ajhs60kr7";
});

nativeBuildInputs = [ cmake python gtest ];
setSourceRoot = ''
sourceRoot=$(echo */llvm)
'';
cmakeFlags = [
"-DCMAKE_CXX_FLAGS=-Wno-nonportable-include-path"
"-DLLVM_ENABLE_LIBXML2=OFF"
"-DLLVM_INCLUDE_EXAMPLES=OFF"
"-DCOMPILER_RT_BUILD_XRAY=OFF"
"-DCOMPILER_RT_INCLUDE_TESTS=OFF"
"-DCOMPILER_RT_ENABLE_IOS=OFF"
"-DLLVM_BUILD_LLVM_DYLIB=ON"
"-DLLVM_LINK_LLVM_DYLIB=ON"
"-DLLVM_TOOL_LTO_BUILD=OFF"
# "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON"
"-DLLVM_ENABLE_ASSERTIONS=ON"
"-DLLVM_TARGETS_TO_BUILD=X86;WebAssembly"
"-DLLVM_ENABLE_PROJECTS=lld;clang"
"-DLLVM_ENABLE_TERMINFO=0"

"-DCMAKE_BUILD_TYPE=Release"
"-DLLVM_INCLUDE_EXAMPLES=OFF"
"-DLLVM_INCLUDE_TESTS=ON"
#"-DLLVM_CONFIG=${llvm}/bin/llvm-config"
"-DLLVM_BUILD_TESTS=ON"
"-DCLANG_INCLUDE_TESTS=OFF"
] ++ (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 = "http://github.com/llvm/llvm-project";
description = "LLVM";
platforms = platforms.all;
maintainers = with maintainers; [ ];
license = stdenv.lib.licenses.ncsa;
};
}