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 \
70 + pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin "libxml2.dylib "
71 + pkgs.lib.optionalString (!pkgs.stdenv.hostPlatform.isDarwin) "libxml2.a "
72 + '' `pkg-config zlib --cflags` `pkg-config zlib --libs` -o ./xmllint.test.js \
73 --embed-file ./test/xmlid/id_err1.xml
75 echo "Using node to execute the test which basically outputs an error on stderr which we grep for"
76 ${pkgs.nodejs}/bin/node ./xmllint.test.js --noout test/xmlid/id_err1.xml 2>&1 | grep 0bar
80 echo "xmllint unit test failed, please fix this package"
83 echo "since there is no stupid text containing 'foo xml:id' it seems to work! very good."
85 echo "================= /testing libxml2 using node ================="
89 xmlmirror = pkgs.buildEmscriptenPackage rec {
91 version = "unstable-2016-06-05";
93 buildInputs = [ libtool gnumake libxml2 nodejs openjdk json_c ];
94 nativeBuildInputs = [ pkg-config zlib autoconf automake ];
97 url = "https://gitlab.com/odfplugfest/xmlmirror.git";
98 rev = "4fd7e86f7c9526b8f4c1733e5c8b45175860a8fd";
99 sha256 = "1jasdqnbdnb83wbcnyrp32f36w3xwhwp0wq8lwwmhqagxrij1r4b";
103 rm -f fastXmlLint.js*
104 # a fix for ERROR:root:For asm.js, TOTAL_MEMORY must be a multiple of 16MB, was 234217728
105 # https://gitlab.com/odfplugfest/xmlmirror/issues/8
106 sed -e "s/TOTAL_MEMORY=234217728/TOTAL_MEMORY=268435456/g" -i Makefile.emEnv
107 # https://github.com/kripken/emscripten/issues/6344
108 # https://gitlab.com/odfplugfest/xmlmirror/issues/9
109 sed -e "s/\$(JSONC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(LIBXML20_LDFLAGS)/\$(JSONC_LDFLAGS) \$(LIBXML20_LDFLAGS) \$(ZLIB_LDFLAGS) /g" -i Makefile.emEnv
110 # https://gitlab.com/odfplugfest/xmlmirror/issues/11
111 sed -e "s/-o fastXmlLint.js/-s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]' -o fastXmlLint.js/g" -i Makefile.emEnv
112 mkdir -p .emscriptencache
113 export EM_CACHE=$(pwd)/.emscriptencache
118 make -f Makefile.emEnv
121 outputs = [ "out" "doc" ];
125 mkdir -p $doc/share/${pname}
128 cp -R codemirror-5.12 $out/share
129 cp fastXmlLint.js* $out/share
132 cp *.xhtml $out/share
136 cp README.md $doc/share/${pname}
142 zlib = (pkgs.zlib.override {
143 stdenv = pkgs.emscriptenStdenv;
146 nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ pkg-config ];
147 # we need to reset this setting!
148 env = (old.env or { }) // { NIX_CFLAGS_COMPILE = ""; };
158 echo "================= testing zlib using node ================="
160 echo "Compiling a custom test"
162 emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 test/example.c -DZ_SOLO \
163 -L. libz.a -I . -o example.js
165 echo "Using node to execute the test"
166 ${pkgs.nodejs}/bin/node ./example.js
169 if [ $? -ne 0 ]; then
170 echo "test failed for some reason"
173 echo "it seems to work! very good."
175 echo "================= /testing zlib using node ================="
178 postPatch = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin ''
179 substituteInPlace configure \
180 --replace '/usr/bin/libtool' 'ar' \
181 --replace 'AR="libtool"' 'AR="ar"' \
182 --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"'