1{ pkgs }:
2
3with pkgs;
4
5# emscripten toolchain abstraction for nix
6# https://github.com/NixOS/nixpkgs/pull/16208
7
8rec {
9 json_c =
10 (pkgs.json_c.override {
11 stdenv = pkgs.emscriptenStdenv;
12 }).overrideAttrs
13 (old: {
14 nativeBuildInputs = [
15 pkg-config
16 cmake
17 ];
18 propagatedBuildInputs = [ zlib ];
19 configurePhase = ''
20 HOME=$TMPDIR
21 mkdir -p .emscriptencache
22 export EM_CACHE=$(pwd)/.emscriptencache
23 emcmake cmake . $cmakeFlags -DCMAKE_INSTALL_PREFIX=$out -DCMAKE_INSTALL_INCLUDEDIR=$dev/include
24 '';
25 checkPhase = ''
26 echo "================= testing json_c using node ================="
27
28 echo "Compiling a custom test"
29 set -x
30 emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 tests/test1.c \
31 `pkg-config zlib --cflags` \
32 `pkg-config zlib --libs` \
33 -I . \
34 libjson-c.a \
35 -o ./test1.js
36
37 echo "Using node to execute the test which basically outputs an error on stderr which we grep for"
38 ${pkgs.nodejs}/bin/node ./test1.js
39
40 set +x
41 if [ $? -ne 0 ]; then
42 echo "test1.js execution failed -> unit test failed, please fix"
43 exit 1;
44 else
45 echo "test1.js execution seems to work! very good."
46 fi
47 echo "================= /testing json_c using node ================="
48 '';
49 });
50
51 libxml2 =
52 (pkgs.libxml2.override {
53 stdenv = emscriptenStdenv;
54 pythonSupport = false;
55 }).overrideAttrs
56 (old: {
57 propagatedBuildInputs = [ zlib ];
58 nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkg-config ];
59
60 # just override it with nothing so it does not fail
61 autoreconfPhase = "echo autoreconfPhase not used...";
62 configurePhase = ''
63 HOME=$TMPDIR
64 mkdir -p .emscriptencache
65 export EM_CACHE=$(pwd)/.emscriptencache
66 emconfigure ./configure --prefix=$out --without-python
67 '';
68 checkPhase = ''
69 echo "================= testing libxml2 using node ================="
70
71 echo "Compiling a custom test"
72 set -x
73 emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 xmllint.o \
74 ./.libs/${
75 if pkgs.stdenv.hostPlatform.isDarwin then "libxml2.dylib" else "libxml2.a"
76 } `pkg-config zlib --cflags` `pkg-config zlib --libs` -o ./xmllint.test.js \
77 --embed-file ./test/xmlid/id_err1.xml
78
79 echo "Using node to execute the test which basically outputs an error on stderr which we grep for"
80 ${pkgs.nodejs}/bin/node ./xmllint.test.js --noout test/xmlid/id_err1.xml 2>&1 | grep 0bar
81
82 set +x
83 if [ $? -ne 0 ]; then
84 echo "xmllint unit test failed, please fix this package"
85 exit 1;
86 else
87 echo "since there is no stupid text containing 'foo xml:id' it seems to work! very good."
88 fi
89 echo "================= /testing libxml2 using node ================="
90 '';
91 });
92
93 xmlmirror = pkgs.buildEmscriptenPackage rec {
94 pname = "xmlmirror";
95 version = "unstable-2016-06-05";
96
97 buildInputs = [
98 libtool
99 gnumake
100 libxml2
101 nodejs
102 openjdk
103 json_c
104 ];
105 nativeBuildInputs = [
106 pkg-config
107 zlib
108 autoconf
109 automake
110 ];
111
112 src = pkgs.fetchgit {
113 url = "https://gitlab.com/odfplugfest/xmlmirror.git";
114 rev = "4fd7e86f7c9526b8f4c1733e5c8b45175860a8fd";
115 sha256 = "1jasdqnbdnb83wbcnyrp32f36w3xwhwp0wq8lwwmhqagxrij1r4b";
116 };
117
118 configurePhase = ''
119 rm -f fastXmlLint.js*
120 # a fix for ERROR:root:For asm.js, TOTAL_MEMORY must be a multiple of 16MB, was 234217728
121 # https://gitlab.com/odfplugfest/xmlmirror/issues/8
122 sed -e "s/TOTAL_MEMORY=234217728/TOTAL_MEMORY=268435456/g" -i Makefile.emEnv
123 # https://github.com/kripken/emscripten/issues/6344
124 # https://gitlab.com/odfplugfest/xmlmirror/issues/9
125 sed -e "s/\$(JSONC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(LIBXML20_LDFLAGS)/\$(JSONC_LDFLAGS) \$(LIBXML20_LDFLAGS) \$(ZLIB_LDFLAGS) /g" -i Makefile.emEnv
126 # https://gitlab.com/odfplugfest/xmlmirror/issues/11
127 sed -e "s/-o fastXmlLint.js/-s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]' -o fastXmlLint.js/g" -i Makefile.emEnv
128 mkdir -p .emscriptencache
129 export EM_CACHE=$(pwd)/.emscriptencache
130 '';
131
132 buildPhase = ''
133 HOME=$TMPDIR
134 make -f Makefile.emEnv
135 '';
136
137 outputs = [
138 "out"
139 "doc"
140 ];
141
142 installPhase = ''
143 mkdir -p $out/share
144 mkdir -p $doc/share/${pname}
145
146 cp Demo* $out/share
147 cp -R codemirror-5.12 $out/share
148 cp fastXmlLint.js* $out/share
149 cp *.xsd $out/share
150 cp *.js $out/share
151 cp *.xhtml $out/share
152 cp *.html $out/share
153 cp *.json $out/share
154 cp *.rng $out/share
155 cp README.md $doc/share/${pname}
156 '';
157 checkPhase = '''';
158 };
159
160 zlib =
161 (pkgs.zlib.override {
162 stdenv = pkgs.emscriptenStdenv;
163 }).overrideAttrs
164 (old: {
165 nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkg-config ];
166 # we need to reset this setting!
167 env = (old.env or { }) // {
168 NIX_CFLAGS_COMPILE = "";
169 };
170 dontStrip = true;
171 outputs = [ "out" ];
172 buildPhase = ''
173 emmake make
174 '';
175 installPhase = ''
176 emmake make install
177 '';
178 checkPhase = ''
179 echo "================= testing zlib using node ================="
180
181 echo "Compiling a custom test"
182 set -x
183 emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 test/example.c -DZ_SOLO \
184 -L. libz.a -I . -o example.js
185
186 echo "Using node to execute the test"
187 ${pkgs.nodejs}/bin/node ./example.js
188
189 set +x
190 if [ $? -ne 0 ]; then
191 echo "test failed for some reason"
192 exit 1;
193 else
194 echo "it seems to work! very good."
195 fi
196 echo "================= /testing zlib using node ================="
197 '';
198
199 postPatch = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin ''
200 substituteInPlace configure \
201 --replace '/usr/bin/libtool' 'ar' \
202 --replace 'AR="libtool"' 'AR="ar"' \
203 --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"'
204 '';
205 });
206
207}