diff options
author | Joachim Schiele <js@lastlog.de> | 2016-06-13 00:34:50 +0200 |
---|---|---|
committer | Joachim Schiele <js@lastlog.de> | 2016-07-04 12:02:37 +0200 |
commit | c514693eb62539545745b71cb0ac52733a9966ad (patch) | |
tree | 1824702a466c7e9d8eefb493bc1f7094b1cd4e2c | |
parent | c90242e657d46704d2d1b581693ffbe1aac205e3 (diff) |
adds support to build emscripten packages using nix:
example usage: - nix-env -I nixpkgs=../somewhere/nixpkgs -f default.nix -iA emscriptenPackages.libxml2 - nix-env -I nixpkgs=../somewhere/nixpkgs -f default.nix -iA emscriptenPackages.json_c - nix-env -I nixpkgs=../somewhere/nixpkgs -f default.nix -iA emscriptenPackages.zlib - nix-env -I nixpkgs=../somewhere/nixpkgs -f default.nix -iA emscriptenPackages.xmlmirror
-rw-r--r-- | pkgs/development/em-modules/generic/default.nix | 59 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 9 | ||||
-rw-r--r-- | pkgs/top-level/emscripten-packages.nix | 103 |
3 files changed, 171 insertions, 0 deletions
diff --git a/pkgs/development/em-modules/generic/default.nix b/pkgs/development/em-modules/generic/default.nix new file mode 100644 index 0000000000000..16b8f1df595e9 --- /dev/null +++ b/pkgs/development/em-modules/generic/default.nix @@ -0,0 +1,59 @@ +{ pkgs, lib, emscripten }: + +{ buildInputs ? [], nativeBuildInputs ? [] + +, enableParallelBuilding ? true + +, meta ? {}, ... } @ args: + +pkgs.stdenv.mkDerivation ( + args // + { + + name = "emscripten-${args.name}"; + buildInputs = [ emscripten ] ++ buildInputs; + nativeBuildInputs = [ emscripten ] ++ nativeBuildInputs; + + # fake conftest results with emscripten's python magic + EMCONFIGURE_JS=2; + + configurePhase = args.configurePhase or '' + # FIXME: Some tests require writing at $HOME + HOME=$TMPDIR + runHook preConfigure + + # probably requires autotools as dependency + ./autogen.sh + emconfigure ./configure --prefix=$out + + runHook postConfigure + ''; + + buildPhase = args.buildPhase or '' + runHook preBuild + + HOME=$TMPDIR + emmake make + + runHook postBuild + ''; + + checkPhase = args.checkPhase or '' + runHook preCheck + + runHook postCheck + ''; + + enableParallelBuilding = args.enableParallelBuilding or true; + + meta = { + # Add default meta information + platforms = lib.platforms.all; + # Do not build this automatically + hydraPlatforms = []; + } // meta // { + # add an extra maintainer to every package + maintainers = (meta.maintainers or []) ++ + [ lib.maintainers.qknight ]; + }; +}) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 2ec0152931723..f94c3c0dcbeea 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1402,10 +1402,19 @@ in eid-viewer = callPackage ../tools/security/eid-viewer { }; + ### DEVELOPMENT / EMSCRIPTEN + + buildEmscriptenPackage = callPackage ../development/em-modules/generic { }; + emscripten = callPackage ../development/compilers/emscripten { }; emscriptenfastcomp = callPackage ../development/compilers/emscripten-fastcomp { }; + emscriptenPackages = recurseIntoAttrs (callPackage ./emscripten-packages.nix { }); + + emscriptenStdenv = stdenv // { mkDerivation = buildEmscriptenPackage; }; + + efibootmgr = callPackage ../tools/system/efibootmgr { }; efivar = callPackage ../tools/system/efivar { }; diff --git a/pkgs/top-level/emscripten-packages.nix b/pkgs/top-level/emscripten-packages.nix new file mode 100644 index 0000000000000..0a1f463984185 --- /dev/null +++ b/pkgs/top-level/emscripten-packages.nix @@ -0,0 +1,103 @@ +{ pkgs }: + +# emscripten toolchain abstraction for nix +# https://github.com/NixOS/nixpkgs/pull/16208 + +with pkgs; rec { + json_c = pkgs.json_c.override { + stdenv = emscriptenStdenv; + }; + + libxml2 = (pkgs.libxml2.override { + stdenv = emscriptenStdenv; + supportPython = false; + }).overrideDerivation + (old: { + buildInputs = old.buildInputs ++ [ autoreconfHook pkgconfig zlib nodejs ]; + nativeBuildInputs = old.nativeBuildInputs ++ [ zlib pkgconfig ]; + # just override it with nothing so it does not fail + autoreconfPhase = "echo autoreconfPhase not used..."; + checkPhase = '' + echo "================= testing xmllint using node =================" + emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 xmllint.o \ + ./.libs/libxml2.a `pkg-config zlib --cflags` `pkg-config zlib --libs` -o ./xmllint.test.js \ + --embed-file ./test/xmlid/id_err1.xml + # test/xmlid/id_err2.xml:3: validity error : xml:id : attribute type should be ID + # <!ATTLIST foo xml:id CDATA #IMPLIED> + # ^ + node ./xmllint.test.js --noout test/xmlid/id_err1.xml 2>&1 | grep 0bar + if [ $? -ne 0 ]; then + echo "xmllint unit test failed, please fix this package" + exit 1; + else + echo "since there is no stupid text containing 'foo xml:id' it seems to work! very good." + fi + echo "================= /testing xmllint using node =================" + ''; + }); + + xmlmirror = buildEmscriptenPackage rec { + name = "xmlmirror"; + + buildInputs = [ autoconf automake libtool pkgconfig gnumake libxml2 nodejs + python openjdk json_c zlib ]; + + src = fetchgit { + url = "https://gitlab.com/odfplugfest/xmlmirror.git"; + rev = "4fd7e86f7c9526b8f4c1733e5c8b45175860a8fd"; + sha256 = "1jasdqnbdnb83wbcnyrp32f36w3xwhwp0wq8lwwmhqagxrij1r4b"; + }; + + configurePhase = '' + rm -f fastXmlLint.js* + ''; + + buildPhase = '' + HOME=$TMPDIR + make -f Makefile.emEnv + ''; + + outputs = [ "out" "doc" ]; + + installPhase = '' + mkdir -p $out/share + mkdir -p $doc + + cp Demo* $out/share + cp -R codemirror-5.12 $out/share + cp fastXmlLint.js* $out/share + cp *.xsd $out/share + cp *.js $out/share + cp *.xhtml $out/share + cp *.html $out/share + cp *.json $out/share + cp *.rng $out/share + cp README.md $doc/ + ''; + + postInstall = '' + ''; + }; + + zlib = (pkgs.zlib.override { + stdenv = emscriptenStdenv; + }).overrideDerivation + (old: { + configurePhase = '' + # FIXME: Some tests require writing at $HOME + HOME=$TMPDIR + runHook preConfigure + + emconfigure ./configure --prefix=$out + + runHook postConfigure + ''; + postPatch = stdenv.lib.optionalString stdenv.isDarwin '' + substituteInPlace configure \ + --replace '/usr/bin/libtool' 'ar' \ + --replace 'AR="libtool"' 'AR="ar"' \ + --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"' + ''; + }); + +} |