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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
{
lib,
stdenv,
cmake,
python3,
fetchFromGitHub,
emscripten,
gtest,
lit,
nodejs,
filecheck,
writeShellApplication,
common-updater-scripts,
curl,
jq,
nix,
nix-update,
}:
let
testsuite = fetchFromGitHub {
owner = "WebAssembly";
repo = "testsuite";
rev = "4b24564c844e3d34bf46dfcb3c774ee5163e31cc";
hash = "sha256-8VirKLRro0iST58Rfg17u4tTO57KNC/7F/NB43dZ7w4=";
};
in
stdenv.mkDerivation rec {
pname = "binaryen";
version = "132";
src = fetchFromGitHub {
owner = "WebAssembly";
repo = "binaryen";
rev = "version_${version}";
hash = "sha256-di/M4QidDwa1doomy79yfN7chCng9VcDB2KgmaEunDc=";
};
nativeBuildInputs = [
cmake
python3
];
strictDeps = true;
preConfigure = ''
if [ -n "$doCheck" ]; then
sed -i -E '/g(test|mock)/d' third_party/CMakeLists.txt
rmdir test/spec/testsuite
ln -s ${testsuite} test/spec/testsuite
# scripts/test/finalize.py checks `'64' in input_path` to enable the
# memory64/bigint flags; the full Nix build path leaks digits that
# can accidentally contain "64", wrongly triggering those flags for
# non-memory64 tests (e.g. duplicate_imports.wat). Match on basename.
substituteInPlace scripts/test/finalize.py \
--replace-fail "'64' in input_path" "'64' in os.path.basename(input_path)"
else
cmakeFlagsArray=($cmakeFlagsArray -DBUILD_TESTS=0)
fi
'';
nativeCheckInputs = [
lit
nodejs
filecheck
];
checkInputs = [ gtest ];
checkPhase = ''
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib python3 ../check.py $tests
'';
# bin/binaryen-unittests is absent on cross builds which don't have doCheck,
# so delete it on non-cross builds too (thus removing gtest from the closure).
postInstall = ''
if [ -n "$doCheck" ]; then
rm "$out/bin/binaryen-unittests"
fi
'';
tests = [
"version"
"wasm-opt"
"wasm-dis"
"crash"
"dylink"
"ctor-eval"
"wasm-metadce"
"wasm-reduce"
# "spec" # fails on array_init_elem.wast
"finalize"
"wasm2js"
# "unit" # fails on test.unit.test_cluster_fuzz.ClusterFuzz
# "binaryenjs" "binaryenjs_wasm" # not building this
# "lit" # fails on d8/fuzz_shell*
"gtest"
]
++ lib.optionals stdenv.hostPlatform.isLinux [
"example"
"validator"
];
doCheck = (stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isDarwin);
meta = {
homepage = "https://github.com/WebAssembly/binaryen";
description = "Compiler infrastructure and toolchain library for WebAssembly, in C++";
platforms = lib.platforms.all;
maintainers = with lib.maintainers; [
willcohen
];
license = lib.licenses.asl20;
};
passthru = {
tests = { inherit emscripten; };
inherit testsuite; # For updateScript to use.
updateScript = lib.getExe (writeShellApplication {
name = "binaryen-update";
runtimeInputs = [
common-updater-scripts
curl
jq
nix
nix-update
];
text = ''
nix-update binaryen
# keep the testsuite pin on binaryen's submodule pointer at the new tag
tag=$(nix eval --raw --file . binaryen.src.rev)
rev=$(curl -fsSL "https://api.github.com/repos/WebAssembly/binaryen/contents/test/spec/testsuite?ref=$tag" | jq -er .sha)
if [[ $rev != "$(nix eval --raw --file . binaryen.testsuite.rev)" ]]; then
update-source-version binaryen --source-key=testsuite --rev="$rev" --ignore-same-version
fi
'';
});
};
}
|