5 # emscripten toolchain abstraction for nix
6 # https://github.com/NixOS/nixpkgs/pull/16208
9 json_c = (pkgs.json_c.override {
10 stdenv = pkgs.emscriptenStdenv;
13 nativeBuildInputs = [ pkg-config cmake ];
14 propagatedBuildInputs = [ zlib ];
17 mkdir -p .emscriptencache
18 export EM_CACHE=$(pwd)/.emscriptencache
19 emcmake cmake . $cmakeFlags -DCMAKE_INSTALL_PREFIX=$out -DCMAKE_INSTALL_INCLUDEDIR=$dev/include
22 echo "================= testing json_c using node ================="
24 echo "Compiling a custom test"
26 emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 tests/test1.c \
27 `pkg-config zlib --cflags` \
28 `pkg-config zlib --libs` \
33 echo "Using node to execute the test which basically outputs an error on stderr which we grep for"
34 ${pkgs.nodejs}/bin/node ./test1.js
38 echo "test1.js execution failed -> unit test failed, please fix"
41 echo "test1.js execution seems to work! very good."
43 echo "================= /testing json_c using node ================="
47 libxml2 = (pkgs.libxml2.override {
48 stdenv = emscriptenStdenv;
49 pythonSupport = false;
52 propagatedBuildInputs = [ zlib ];
53 nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ pkg-config ];
55 # just override it with nothing so it does not fail
56 autoreconfPhase = "echo autoreconfPhase not used...";
59 mkdir -p .emscriptencache
60 export EM_CACHE=$(pwd)/.emscriptencache
61 emconfigure ./configure --prefix=$out --without-python
64 echo "================= testing libxml2 using node ================="
66 echo "Compiling a custom test"
68 emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 xmllint.o \
69 ./.libs/libxml2.a `pkg-config zlib --cflags` `pkg-config zlib --libs` -o ./xmllint.test.js \
70 --embed-file ./test/xmlid/id_err1.xml
72 echo "Using node to execute the test which basically outputs an error on stderr which we grep for"
73 ${pkgs.nodejs}/bin/node ./xmllint.test.js --noout test/xmlid/id_err1.xml 2>&1 | grep 0bar
77 echo "xmllint unit test failed, please fix this package"
80 echo "since there is no stupid text containing 'foo xml:id' it seems to work! very good."
82 echo "================= /testing libxml2 using node ================="
86 xmlmirror = pkgs.buildEmscriptenPackage rec {
88 version = "unstable-2016-06-05";
90 buildInputs = [ libtool gnumake libxml2 nodejs openjdk json_c ];
91 nativeBuildInputs = [ pkg-config zlib autoconf automake ];
94 url = "https://gitlab.com/odfplugfest/xmlmirror.git";
95 rev = "4fd7e86f7c9526b8f4c1733e5c8b45175860a8fd";
96 sha256 = "1jasdqnbdnb83wbcnyrp32f36w3xwhwp0wq8lwwmhqagxrij1r4b";
100 rm -f fastXmlLint.js*
101 # a fix for ERROR:root:For asm.js, TOTAL_MEMORY must be a multiple of 16MB, was 234217728
102 # https://gitlab.com/odfplugfest/xmlmirror/issues/8
103 sed -e "s/TOTAL_MEMORY=234217728/TOTAL_MEMORY=268435456/g" -i Makefile.emEnv
104 # https://github.com/kripken/emscripten/issues/6344
105 # https://gitlab.com/odfplugfest/xmlmirror/issues/9
106 sed -e "s/\$(JSONC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(LIBXML20_LDFLAGS)/\$(JSONC_LDFLAGS) \$(LIBXML20_LDFLAGS) \$(ZLIB_LDFLAGS) /g" -i Makefile.emEnv
107 # https://gitlab.com/odfplugfest/xmlmirror/issues/11
108 sed -e "s/-o fastXmlLint.js/-s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]' -o fastXmlLint.js/g" -i Makefile.emEnv
109 mkdir -p .emscriptencache
110 export EM_CACHE=$(pwd)/.emscriptencache
115 make -f Makefile.emEnv
118 outputs = [ "out" "doc" ];
122 mkdir -p $doc/share/${pname}
125 cp -R codemirror-5.12 $out/share
126 cp fastXmlLint.js* $out/share
129 cp *.xhtml $out/share
133 cp README.md $doc/share/${pname}
139 zlib = (pkgs.zlib.override {
140 stdenv = pkgs.emscriptenStdenv;
141 }).overrideDerivation
143 nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ pkg-config ];
144 # we need to reset this setting!
145 NIX_CFLAGS_COMPILE="";
155 echo "================= testing zlib using node ================="
157 echo "Compiling a custom test"
159 emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 test/example.c -DZ_SOLO \
160 -L. libz.a -I . -o example.js
162 echo "Using node to execute the test"
163 ${pkgs.nodejs}/bin/node ./example.js
166 if [ $? -ne 0 ]; then
167 echo "test failed for some reason"
170 echo "it seems to work! very good."
172 echo "================= /testing zlib using node ================="
175 postPatch = pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
176 substituteInPlace configure \
177 --replace '/usr/bin/libtool' 'ar' \
178 --replace 'AR="libtool"' 'AR="ar"' \
179 --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"'