2016-06-13 00:34:50 +02:00
|
|
|
{ pkgs }:
|
|
|
|
|
2018-03-18 13:34:46 +01:00
|
|
|
with pkgs;
|
|
|
|
|
2016-06-13 00:34:50 +02:00
|
|
|
# emscripten toolchain abstraction for nix
|
|
|
|
# https://github.com/NixOS/nixpkgs/pull/16208
|
|
|
|
|
2018-03-18 13:34:46 +01:00
|
|
|
rec {
|
|
|
|
json_c = (pkgs.json_c.override {
|
|
|
|
stdenv = pkgs.emscriptenStdenv;
|
2023-02-23 17:09:09 +01:00
|
|
|
}).overrideAttrs
|
2018-03-18 13:34:46 +01:00
|
|
|
(old: {
|
2021-08-07 13:26:45 +02:00
|
|
|
nativeBuildInputs = [ pkg-config cmake ];
|
2018-03-18 13:34:46 +01:00
|
|
|
propagatedBuildInputs = [ zlib ];
|
|
|
|
configurePhase = ''
|
|
|
|
HOME=$TMPDIR
|
2022-05-09 16:57:18 +02:00
|
|
|
mkdir -p .emscriptencache
|
|
|
|
export EM_CACHE=$(pwd)/.emscriptencache
|
2021-08-07 13:26:45 +02:00
|
|
|
emcmake cmake . $cmakeFlags -DCMAKE_INSTALL_PREFIX=$out -DCMAKE_INSTALL_INCLUDEDIR=$dev/include
|
2018-03-18 13:34:46 +01:00
|
|
|
'';
|
|
|
|
checkPhase = ''
|
|
|
|
echo "================= testing json_c using node ================="
|
|
|
|
|
|
|
|
echo "Compiling a custom test"
|
|
|
|
set -x
|
|
|
|
emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 tests/test1.c \
|
|
|
|
`pkg-config zlib --cflags` \
|
|
|
|
`pkg-config zlib --libs` \
|
|
|
|
-I . \
|
2021-08-07 13:26:45 +02:00
|
|
|
libjson-c.a \
|
2018-03-18 13:34:46 +01:00
|
|
|
-o ./test1.js
|
|
|
|
|
2021-10-03 19:08:14 +02:00
|
|
|
echo "Using node to execute the test which basically outputs an error on stderr which we grep for"
|
|
|
|
${pkgs.nodejs}/bin/node ./test1.js
|
2018-03-18 13:34:46 +01:00
|
|
|
|
|
|
|
set +x
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "test1.js execution failed -> unit test failed, please fix"
|
|
|
|
exit 1;
|
|
|
|
else
|
|
|
|
echo "test1.js execution seems to work! very good."
|
|
|
|
fi
|
|
|
|
echo "================= /testing json_c using node ================="
|
|
|
|
'';
|
|
|
|
});
|
2021-10-03 19:08:14 +02:00
|
|
|
|
2016-06-13 00:34:50 +02:00
|
|
|
libxml2 = (pkgs.libxml2.override {
|
|
|
|
stdenv = emscriptenStdenv;
|
2016-11-08 10:55:21 +01:00
|
|
|
pythonSupport = false;
|
2023-02-23 17:09:09 +01:00
|
|
|
}).overrideAttrs
|
2021-10-03 19:08:14 +02:00
|
|
|
(old: {
|
2018-03-18 13:34:46 +01:00
|
|
|
propagatedBuildInputs = [ zlib ];
|
2022-09-25 04:49:25 +02:00
|
|
|
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ pkg-config ];
|
2018-03-18 13:34:46 +01:00
|
|
|
|
2016-06-13 00:34:50 +02:00
|
|
|
# just override it with nothing so it does not fail
|
2021-10-03 19:08:14 +02:00
|
|
|
autoreconfPhase = "echo autoreconfPhase not used...";
|
2018-03-18 13:34:46 +01:00
|
|
|
configurePhase = ''
|
|
|
|
HOME=$TMPDIR
|
2022-05-09 16:57:18 +02:00
|
|
|
mkdir -p .emscriptencache
|
|
|
|
export EM_CACHE=$(pwd)/.emscriptencache
|
2018-03-18 13:34:46 +01:00
|
|
|
emconfigure ./configure --prefix=$out --without-python
|
|
|
|
'';
|
2016-06-13 00:34:50 +02:00
|
|
|
checkPhase = ''
|
2018-03-18 13:34:46 +01:00
|
|
|
echo "================= testing libxml2 using node ================="
|
|
|
|
|
|
|
|
echo "Compiling a custom test"
|
|
|
|
set -x
|
2016-06-13 00:34:50 +02:00
|
|
|
emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 xmllint.o \
|
2023-05-22 15:02:01 +02:00
|
|
|
./.libs/''
|
|
|
|
+ pkgs.lib.optionalString pkgs.stdenv.isDarwin "libxml2.dylib "
|
|
|
|
+ pkgs.lib.optionalString (!pkgs.stdenv.isDarwin) "libxml2.a "
|
|
|
|
+ '' `pkg-config zlib --cflags` `pkg-config zlib --libs` -o ./xmllint.test.js \
|
2021-10-03 19:08:14 +02:00
|
|
|
--embed-file ./test/xmlid/id_err1.xml
|
2018-03-18 13:34:46 +01:00
|
|
|
|
2021-10-03 19:08:14 +02:00
|
|
|
echo "Using node to execute the test which basically outputs an error on stderr which we grep for"
|
|
|
|
${pkgs.nodejs}/bin/node ./xmllint.test.js --noout test/xmlid/id_err1.xml 2>&1 | grep 0bar
|
2018-03-18 13:34:46 +01:00
|
|
|
|
|
|
|
set +x
|
2016-06-13 00:34:50 +02:00
|
|
|
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
|
2018-03-18 13:34:46 +01:00
|
|
|
echo "================= /testing libxml2 using node ================="
|
2016-06-13 00:34:50 +02:00
|
|
|
'';
|
2021-10-03 19:08:14 +02:00
|
|
|
});
|
|
|
|
|
2018-03-18 13:34:46 +01:00
|
|
|
xmlmirror = pkgs.buildEmscriptenPackage rec {
|
2019-11-06 19:59:17 +01:00
|
|
|
pname = "xmlmirror";
|
|
|
|
version = "unstable-2016-06-05";
|
2016-06-13 00:34:50 +02:00
|
|
|
|
2022-09-25 04:49:25 +02:00
|
|
|
buildInputs = [ libtool gnumake libxml2 nodejs openjdk json_c ];
|
2022-03-31 03:11:06 +02:00
|
|
|
nativeBuildInputs = [ pkg-config zlib autoconf automake ];
|
2016-06-13 00:34:50 +02:00
|
|
|
|
2018-03-18 13:34:46 +01:00
|
|
|
src = pkgs.fetchgit {
|
2016-06-13 00:34:50 +02:00
|
|
|
url = "https://gitlab.com/odfplugfest/xmlmirror.git";
|
|
|
|
rev = "4fd7e86f7c9526b8f4c1733e5c8b45175860a8fd";
|
|
|
|
sha256 = "1jasdqnbdnb83wbcnyrp32f36w3xwhwp0wq8lwwmhqagxrij1r4b";
|
|
|
|
};
|
2021-10-03 19:08:14 +02:00
|
|
|
|
2016-06-13 00:34:50 +02:00
|
|
|
configurePhase = ''
|
|
|
|
rm -f fastXmlLint.js*
|
2018-03-18 13:34:46 +01:00
|
|
|
# a fix for ERROR:root:For asm.js, TOTAL_MEMORY must be a multiple of 16MB, was 234217728
|
|
|
|
# https://gitlab.com/odfplugfest/xmlmirror/issues/8
|
|
|
|
sed -e "s/TOTAL_MEMORY=234217728/TOTAL_MEMORY=268435456/g" -i Makefile.emEnv
|
|
|
|
# https://github.com/kripken/emscripten/issues/6344
|
|
|
|
# https://gitlab.com/odfplugfest/xmlmirror/issues/9
|
|
|
|
sed -e "s/\$(JSONC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(LIBXML20_LDFLAGS)/\$(JSONC_LDFLAGS) \$(LIBXML20_LDFLAGS) \$(ZLIB_LDFLAGS) /g" -i Makefile.emEnv
|
|
|
|
# https://gitlab.com/odfplugfest/xmlmirror/issues/11
|
|
|
|
sed -e "s/-o fastXmlLint.js/-s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]' -o fastXmlLint.js/g" -i Makefile.emEnv
|
2022-05-09 16:57:18 +02:00
|
|
|
mkdir -p .emscriptencache
|
|
|
|
export EM_CACHE=$(pwd)/.emscriptencache
|
2016-06-13 00:34:50 +02:00
|
|
|
'';
|
2021-10-03 19:08:14 +02:00
|
|
|
|
2016-06-13 00:34:50 +02:00
|
|
|
buildPhase = ''
|
|
|
|
HOME=$TMPDIR
|
|
|
|
make -f Makefile.emEnv
|
|
|
|
'';
|
2021-10-03 19:08:14 +02:00
|
|
|
|
2016-06-13 00:34:50 +02:00
|
|
|
outputs = [ "out" "doc" ];
|
2021-10-03 19:08:14 +02:00
|
|
|
|
2016-06-13 00:34:50 +02:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/share
|
2019-11-06 19:59:17 +01:00
|
|
|
mkdir -p $doc/share/${pname}
|
2021-10-03 19:08:14 +02:00
|
|
|
|
2016-06-13 00:34:50 +02:00
|
|
|
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
|
2019-11-06 19:59:17 +01:00
|
|
|
cp README.md $doc/share/${pname}
|
2016-06-13 00:34:50 +02:00
|
|
|
'';
|
2018-03-18 13:34:46 +01:00
|
|
|
checkPhase = ''
|
2016-06-13 00:34:50 +02:00
|
|
|
'';
|
2021-10-03 19:08:14 +02:00
|
|
|
};
|
2016-06-13 00:34:50 +02:00
|
|
|
|
|
|
|
zlib = (pkgs.zlib.override {
|
2018-03-18 13:34:46 +01:00
|
|
|
stdenv = pkgs.emscriptenStdenv;
|
2023-02-23 17:09:09 +01:00
|
|
|
}).overrideAttrs
|
2021-10-03 19:08:14 +02:00
|
|
|
(old: {
|
2022-09-25 04:49:25 +02:00
|
|
|
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ pkg-config ];
|
2018-03-18 13:34:46 +01:00
|
|
|
# we need to reset this setting!
|
2023-02-20 16:17:34 +01:00
|
|
|
env = (old.env or { }) // { NIX_CFLAGS_COMPILE = ""; };
|
2018-03-18 13:34:46 +01:00
|
|
|
dontStrip = true;
|
|
|
|
outputs = [ "out" ];
|
|
|
|
buildPhase = ''
|
|
|
|
emmake make
|
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
emmake make install
|
|
|
|
'';
|
|
|
|
checkPhase = ''
|
|
|
|
echo "================= testing zlib using node ================="
|
|
|
|
|
|
|
|
echo "Compiling a custom test"
|
|
|
|
set -x
|
|
|
|
emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 test/example.c -DZ_SOLO \
|
2022-05-09 16:57:18 +02:00
|
|
|
-L. libz.a -I . -o example.js
|
2018-03-18 13:34:46 +01:00
|
|
|
|
|
|
|
echo "Using node to execute the test"
|
2021-10-03 19:08:14 +02:00
|
|
|
${pkgs.nodejs}/bin/node ./example.js
|
2018-03-18 13:34:46 +01:00
|
|
|
|
|
|
|
set +x
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "test failed for some reason"
|
|
|
|
exit 1;
|
|
|
|
else
|
|
|
|
echo "it seems to work! very good."
|
|
|
|
fi
|
|
|
|
echo "================= /testing zlib using node ================="
|
|
|
|
'';
|
|
|
|
|
2021-01-10 12:03:59 +01:00
|
|
|
postPatch = pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
|
2016-06-13 00:34:50 +02:00
|
|
|
substituteInPlace configure \
|
|
|
|
--replace '/usr/bin/libtool' 'ar' \
|
|
|
|
--replace 'AR="libtool"' 'AR="ar"' \
|
|
|
|
--replace 'ARFLAGS="-o"' 'ARFLAGS="-r"'
|
|
|
|
'';
|
2021-10-03 19:08:14 +02:00
|
|
|
});
|
|
|
|
|
2016-06-13 00:34:50 +02:00
|
|
|
}
|