-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzstd-wasm.nix
67 lines (50 loc) · 1.62 KB
/
zstd-wasm.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{ lib, buildEmscriptenPackage, stdenv, fetchFromGitHub, bash, emscripten }:
buildEmscriptenPackage rec {
pname = "zstd-wasm";
version = "1.5.0";
src = fetchFromGitHub {
owner = "facebook";
repo = "zstd";
rev = "v${version}";
sha256 = "sha256-R+Y10gd3GE17AJ5zIXGI4tuOdyCikdZXwbkMllAHjEU=";
};
NIX_CFLAGS_COMPILE = "-Os -g0 -flto -DNDEBUG=1"; #-Wall -Wextra -Werror";
EM_FLAGS = "-s WASM=1 -s EXPORT_ES6=1 -s ENVIRONMENT=web -s ALLOW_MEMORY_GROWTH=1 -s FILESYSTEM=0";
exportedFunctions = [ "_ZSTD_isError" "_ZSTD_getFrameContentSize" "_ZSTD_decompress" "_ZSTD_compress" "_ZSTD_compressBound" "_ZSTD_getErrorString" "_ZSTD_getErrorCode" "_malloc" "_free" ];
dontConfigure = 1;
dontFixup = 1;
postPatch = ''
patchShebangs build/single_file_libs
'';
preBuild = ''
t=$PWD
# Create amalgamated source
pushd build/single_file_libs >/dev/null
./create_single_file_library.sh
cp zstd.c $t/zstd.c
popd >/dev/null
'';
buildPhase = ''
runHook preBuild
emcc zstd.c -flto -o zstd.js -Oz --memory-init-file 0 \
$NIX_CFLAGS_COMPILE $EM_FLAGS \
-s EXPORTED_RUNTIME_METHODS='["ccall","cwrap"]' \
-s EXPORTED_FUNCTIONS='${builtins.toJSON exportedFunctions}'
runHook postBuild
'';
checkPhase = ''
runHook preCheck
# TODO
runHook postCheck
'';
installPhase = ''
runHook preInstall
install -D -m 644 zstd.js $out/zstd.js
install -D -m 644 zstd.wasm $out/zstd.wasm
runHook postInstall
'';
meta = with lib; {
platforms = platforms.unix;
badPlatforms = platforms.darwin; # wasm-ld gets passed broken arguments
};
}