-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathcomponentize.sh.in
More file actions
executable file
·130 lines (117 loc) · 3.93 KB
/
componentize.sh.in
File metadata and controls
executable file
·130 lines (117 loc) · 3.93 KB
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
#!/usr/bin/env bash
#set -euo pipefail
wizer="${WIZER:-@WASMTIME_DIR@/wasmtime wizer}"
wasm_tools="${WASM_TOOLS:-@WASM_TOOLS_BIN@}"
weval="${WEVAL:-@WEVAL_BIN@}"
aot=@AOT@
preopen_dir="${PREOPEN_DIR:-}"
usage() {
echo "Usage: $(basename "$0") [--verbose] [-i,--initializer-script-path path] [--strip-path-prefix prefix] [--legacy-script] [input.js] [-o output.wasm]"
echo " Providing an input file but no output uses the input base name with a .wasm extension"
echo " Providing an output file but no input creates a component without running any top-level script"
echo " Specifying '--verbose' causes the detailed output during initialization and execution"
echo " Specifying '-i' or '--initializer-script-path' allows specifying an initializer script"
echo " Specifying '--strip-path-prefix' will cause the provided prefix to be stripped from paths in stack traces and the debugger"
echo " Specifying '--legacy-script' causes evaluation as a legacy JS script instead of a module"
echo " Specifying '--wpt-mode' enables WPT compatibility mode"
echo " Specifying '--init-location url' allows setting the URL to use for 'globalThis.location' during initialization"
exit 1
}
if [ $# -lt 1 ]
then
usage
fi
IN_FILE=""
OUT_FILE=""
LEGACY_SCRIPT_PARAM=""
STARLING_ARGS=""
VERBOSE=0
while [ $# -gt 0 ]
do
case "$1" in
--legacy-script)
LEGACY_SCRIPT_PARAM="$1 "
IN_FILE="$2"
shift 2
;;
-o|--output)
OUT_FILE="$2"
shift 2
;;
-i|--initializer-script-path)
STARLING_ARGS="$STARLING_ARGS $1 $2"
shift 2
;;
--strip-path-prefix)
STARLING_ARGS="$STARLING_ARGS $1 $2"
shift 2
;;
--wpt-mode)
STARLING_ARGS="$STARLING_ARGS $1 $2"
shift 2
;;
--init-location)
STARLING_ARGS="$STARLING_ARGS $1 $2"
shift 2
;;
-v|--verbose)
STARLING_ARGS="$1 $STARLING_ARGS"
VERBOSE=1
shift
;;
*)
if [ -n "$IN_FILE" ] && [ -z "$OUT_FILE" ] && [ $# -eq 1 ]
then
OUT_FILE="$1"
else
IN_FILE="$1"
fi
shift
;;
esac
done
# Exit if neither input file nor output file is provided.
if [ -z "$IN_FILE" ] && [ -z "$OUT_FILE" ]
then
usage
fi
# Use the -o param as output file if provided, otherwise use the input base name with a .wasm
# extension.
if [ -z "$OUT_FILE" ]
then
BASENAME="$(basename "$IN_FILE")"
OUT_FILE="${BASENAME%.*}.wasm"
fi
if [[ -n "$IN_FILE" ]]; then
if [[ -n $preopen_dir ]]; then
preopen_dir="--dir "$preopen_dir""
else
preopen_dir="--dir "$(dirname "$IN_FILE")""
fi
echo "Componentizing $IN_FILE into $OUT_FILE"
STARLING_ARGS="$STARLING_ARGS $LEGACY_SCRIPT_PARAM$IN_FILE"
if [[ $VERBOSE -ne 0 ]]; then
echo "Componentizing with args $STARLING_ARGS"
fi
if [[ $aot -ne 0 ]]; then
WEVAL_VERBOSE=""
if [[ $VERBOSE -ne 0 ]]; then
WEVAL_VERBOSE="--verbose --show-stats"
echo "Using AOT compilation"
fi
echo "$STARLING_ARGS" | WASMTIME_BACKTRACE_DETAILS=1 $weval weval -w $preopen_dir \
--cache-ro "$(dirname "$0")/starling-ics.wevalcache" \
$WEVAL_VERBOSE \
-o "$OUT_FILE" \
-i "$(dirname "$0")/starling-raw.wasm"
else
echo "$STARLING_ARGS" | WASMTIME_BACKTRACE_DETAILS=1 $wizer -S cli -S inherit-env \
-W bulk-memory -W unknown-imports-trap \
$preopen_dir -o "$OUT_FILE" \
"$(dirname "$0")/starling-raw.wasm"
fi
else
echo "Creating runtime-eval component $OUT_FILE"
cp "$(dirname "$0")/starling-raw.wasm" "$OUT_FILE"
fi
$wasm_tools component new -v --adapt "wasi_snapshot_preview1=$(dirname "$0")/preview1-adapter.wasm" --output "$OUT_FILE" "$OUT_FILE"