-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathcompile.sh
executable file
·103 lines (90 loc) · 2.18 KB
/
compile.sh
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
#!/bin/bash
set -e
compileWat() {
filename=$(basename "$1")
(set -x; wat2wasm $1 -o "./compiled/$filename.wasm")
}
compileRust() {
filename=$(basename "$1")
# we can use the wasi targets for any file that end in -wasi.rs
if [[ "$filename" =~ wasi.rs$ ]]; then
target="wasm32-wasi"
crate_type="bin"
else
target="wasm32-unknown-unknown"
crate_type="cdylib"
fi
(set -x; rustc $1 --target=$target --crate-type=$crate_type -o "./compiled/$filename.wasm")
}
ENV_WASI_SDK_PATH="${WASK_SDK_PATH:-/opt/wasi-sdk}"
compileC() {
filename=$(basename "$1")
(set -x; ${ENV_WASI_SDK_PATH}/bin/clang -g -o "./compiled/$filename.wasm" $1 -nostartfiles -Wl,--no-entry -Wl,--export=run)
}
compileJavy() {
filename=$(basename "$1")
(set -x; javy compile $1 -o "./compiled/$filename.javy.wasm")
}
compileJavyDynamic() {
filename=$(basename "$1")
(set -x; javy emit-provider -o "./compiled/quickjs-provider.javy-dynamic.wasm" && \
javy compile -d $1 -o "./compiled/$filename.javy-dynamic.wasm")
}
compileTinyGo() {
filename=$(basename "$1")
(set -x; tinygo build -o "./compiled/$filename.tiny.wasm" -target=wasi $1)
}
compileGo() {
filename=$(basename "$1")
(set -x; GOOS=wasip1 GOARCH=wasm go build -o "./compiled/$filename.wasm" $1)
}
compileDotnet() {
filename=$(basename "$1")
(set -x; cd $1 && dotnet publish -c Release && cp ./bin/Release/net8.0/wasi-wasm/AppBundle/*.wasm "../../compiled/$filename.dotnet.wasm")
}
compile() {
lang=$1
case "$lang" in
wat)
compileWat $2
;;
rust)
compileRust $2
;;
c)
compileC $2
;;
javy)
compileJavy $2
;;
javy-dynamic)
compileJavyDynamic $2
;;
tinygo)
compileTinyGo $2
;;
go)
compileGo $2
;;
dotnet)
compileDotnet $2
;;
*)
echo "Don't know how to compile language $lang"
exit 1
;;
esac
}
lang="${1:-all}"
path="${2:-all}"
if [[ "$lang" == "all" ]]; then
langs=("wat" "rust" "c" "javy" "javy-dynamic" "tinygo", "go", "dotnet")
else
langs=("$lang")
fi
for lang in "${langs[@]}"; do
echo "Compiling all modules in ./$lang/*"
for file in ./$lang/*; do
compile $lang $file
done
done