1{
2 lib,
3 stdenv,
4 cmake,
5 python3,
6 fetchFromGitHub,
7 emscripten,
8 gtest,
9 lit,
10 nodejs,
11 filecheck,
12}:
13let
14 testsuite = fetchFromGitHub {
15 owner = "WebAssembly";
16 repo = "testsuite";
17 rev = "e05365077e13a1d86ffe77acfb1a835b7aa78422";
18 hash = "sha256-yvZ5AZTPUA6nsD3xpFC0VLthiu2CxVto66RTXBXXeJM=";
19 };
20in
21stdenv.mkDerivation rec {
22 pname = "binaryen";
23 version = "123";
24
25 src = fetchFromGitHub {
26 owner = "WebAssembly";
27 repo = "binaryen";
28 rev = "version_${version}";
29 hash = "sha256-SFruWOJVxO3Ll1HwjK3DYSPY2IprnDly7QjxrECTrzE=";
30 };
31
32 nativeBuildInputs = [
33 cmake
34 python3
35 ];
36
37 strictDeps = true;
38
39 preConfigure = ''
40 if [ $doCheck -eq 1 ]; then
41 sed -i '/gtest/d' third_party/CMakeLists.txt
42 rmdir test/spec/testsuite
43 ln -s ${testsuite} test/spec/testsuite
44 else
45 cmakeFlagsArray=($cmakeFlagsArray -DBUILD_TESTS=0)
46 fi
47 '';
48
49 nativeCheckInputs = [
50 lit
51 nodejs
52 filecheck
53 ];
54 checkInputs = [ gtest ];
55 checkPhase = ''
56 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib python3 ../check.py $tests
57 '';
58
59 tests =
60 [
61 "version"
62 "wasm-opt"
63 "wasm-dis"
64 "crash"
65 "dylink"
66 "ctor-eval"
67 "wasm-metadce"
68 "wasm-reduce"
69 "spec"
70 "lld"
71 "wasm2js"
72 # "unit" # fails on test.unit.test_cluster_fuzz.ClusterFuzz
73 # "binaryenjs" "binaryenjs_wasm" # not building this
74 # "lit" # fails on d8/fuzz_shell*
75 "gtest"
76 ]
77 ++ lib.optionals stdenv.hostPlatform.isLinux [
78 "example"
79 "validator"
80 ];
81
82 doCheck = (stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isDarwin);
83
84 meta = with lib; {
85 homepage = "https://github.com/WebAssembly/binaryen";
86 description = "Compiler infrastructure and toolchain library for WebAssembly, in C++";
87 platforms = platforms.all;
88 maintainers = with maintainers; [
89 asppsa
90 willcohen
91 ];
92 license = licenses.asl20;
93 };
94 passthru.tests = { inherit emscripten; };
95}