Debian Codegraph @

wasm/src/plugin_example_cxx.nix

raw
1 ## To see the source code used in this example
2 ## visit https://github.com/ketchupok/half-physler
3
4 { pkgs ? import <nixpkgs> { } }:
5
6 let
7 wasi-sdk = pkgs.callPackage ./wasi-sdk.nix { };
8 csound-wasm = pkgs.callPackage ./csound.nix {};
9
10 in pkgs.stdenv.mkDerivation {
11
12 name = "csound-wasm-cxx-plugin-example";
13
14 buildInputs = [ csound-wasm ];
15
16 src = pkgs.fetchFromGitHub {
17 owner = "ketchupok";
18 repo = "half-physler";
19 rev = "3dc1dfa9f40a2246c96babeee242e2458f56a6ac";
20 sha256 = "0k9av2aw64jc4l1hg08jvc1gn57knqp92ca29k2ra5mk2mwhm78q";
21 };
22
23 dontStrip = true;
24
25 # wasm currently doesn't support atomics
26 # here we just remove the import statement.
27 patchPhase = ''
28 find ./ -type f -exec sed -i -e 's/#include <atomic>//g' {} \;
29 '';
30
31 buildPhase = ''
32 echo "Compile plugin_example_cxx.wasm"
33 ${wasi-sdk}/bin/clang \
34 -fPIC -fno-exceptions -fno-rtti \
35 --target=wasm32-unknown-emscripten \
36 --sysroot=${wasi-sdk}/share/wasi-sysroot \
37 -D__wasi__=1 \
38 -D__wasm32__=1 \
39 -D_WASI_EMULATED_SIGNAL \
40 -D_WASI_EMULATED_MMAN \
41 -DUSE_DOUBLE=1 \
42 -I${csound-wasm}/include \
43 -I${wasi-sdk}/share/wasi-sysroot/include \
44 -I${wasi-sdk}/share/wasi-sysroot/include/c++/v1 \
45 -I./src \
46 -c src/const.cpp \
47 src/tube.cpp \
48 src/opcode_registers.cpp \
49 resonators/resontube.cpp
50
51 echo "Link together plugin_example_cxx.wasm"
52 ${wasi-sdk}/bin/wasm-ld \
53 -z stack-size=128 \
54 -pie --no-entry \
55 --experimental-pic \
56 --import-table \
57 --import-memory \
58 --export=__wasm_call_ctors \
59 --export=csoundModuleInit \
60 --export-if-defined=csoundModuleCreate \
61 --export-if-defined=csoundModuleDestroy \
62 -L${wasi-sdk}/share/wasi-sysroot/lib/wasm32-unknown-emscripten \
63 -L${csound-wasm}/lib -lcsound-wasm \
64 -lc -lc++ -lc++abi -lrt -lutil -lxnet -lresolv -lc-printscan-long-double \
65 -lwasi-emulated-getpid -lwasi-emulated-signal -lwasi-emulated-mman -lwasi-emulated-process-clocks \
66 *.o -o plugin_example_cxx.wasm
67 '';
68
69 installPhase = ''
70 mkdir -p $out/lib
71 cp ./plugin_example_cxx.wasm $out/lib
72 '';
73 }