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