soiz1 commited on
Commit
ae82a1f
·
verified ·
1 Parent(s): 9fe3b33

Update rewriter/wasm/build.sh

Browse files
Files changed (1) hide show
  1. rewriter/wasm/build.sh +123 -115
rewriter/wasm/build.sh CHANGED
@@ -1,115 +1,123 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- shopt -s inherit_errexit
4
-
5
- which cargo wasm-bindgen wasm-opt wasm-snip &> /dev/null || {
6
- echo "Please install cargo, wasm-bindgen, wasm-opt from https://github.com/WebAssembly/binaryen, and wasm-snip from https://github.com/r58playz/wasm-snip!"
7
- exit 1
8
- }
9
-
10
- WBG="wasm-bindgen 0.2.100"
11
- if ! [[ "$(wasm-bindgen -V)" =~ ^"$WBG" ]]; then
12
- echo "Incorrect wasm-bindgen-cli version: '$(wasm-bindgen -V)' != '$WBG'"
13
- exit 1
14
- fi
15
-
16
- if ! [ "${RELEASE:-0}" = "1" ]; then
17
- WASMOPTFLAGS="${WASMOPTFLAGS:-} -g"
18
- FEATURES="debug,${FEATURES:-}"
19
- else
20
- : "${WASMOPTFLAGS:=}"
21
- : "${FEATURES:=}"
22
- fi
23
-
24
- (
25
- export RUSTFLAGS='-Zlocation-detail=none -Zfmt-debug=none'
26
- if [ "${OPTIMIZE_FOR_SIZE:-0}" = "1" ]; then
27
- export RUSTFLAGS="${RUSTFLAGS} -C opt-level=z"
28
- fi
29
- STD_FEATURES="panic_immediate_abort"
30
- if [ "${OPTIMIZE_FOR_SPEED:-0}" = "0" ]; then
31
- STD_FEATURES="${STD_FEATURES},optimize_for_size"
32
- fi
33
- cargo build --release --target wasm32-unknown-unknown \
34
- -Z build-std=panic_abort,std -Z build-std-features=${STD_FEATURES} \
35
- --no-default-features --features "$FEATURES"
36
- )
37
- wasm-bindgen --target web --out-dir out/ ../target/wasm32-unknown-unknown/release/wasm.wasm
38
-
39
- if [[ "$OSTYPE" == "darwin"* ]] || [[ "$OSTYPE" == "freebsd"* ]] || [[ "$OSTYPE" == "dragonfly"* ]]; then
40
- sed -i '' 's/import.meta.url/""/g' out/wasm.js
41
- else
42
- sed -i 's/import.meta.url/""/g' out/wasm.js
43
- fi
44
-
45
- cd ../../
46
-
47
- wasm-snip rewriter/wasm/out/wasm_bg.wasm -o rewriter/wasm/out/wasm_snipped.wasm \
48
- -p 'oxc_regular_expression::.*' \
49
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_non_array_type' \
50
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_import_type' \
51
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_operator_or_higher' \
52
- 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_interface_declaration' \
53
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_mapped_type' \
54
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_index_signature_declaration' \
55
- 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_import_equals_declaration' \
56
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_or_type_predicate' \
57
- 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_namespace_or_module_declaration_body' \
58
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_implements_clause' \
59
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_intersection_type_or_higher' \
60
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_type_name' \
61
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_literal_type_node' \
62
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_asserts_type_predicate' \
63
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_tuple_element_type' \
64
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_arguments_of_type_reference' \
65
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_call_signature_member' \
66
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::is_start_of_type' \
67
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_this_type_predicate' \
68
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_query' \
69
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_reference' \
70
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_operator' \
71
- 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_literal' \
72
- 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::is_at_enum_declaration' \
73
- 'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_element' \
74
- 'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_identifier' \
75
- 'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_element_name' \
76
- 'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_children' \
77
- 'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_fragment' \
78
- 'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_expression_container' \
79
- 'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_expression'
80
- #
81
- # these are confirmed to break oxc
82
- # 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_declaration' \
83
- # 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_type' \
84
- # 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_arguments_in_expression' \
85
- # 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_type_parameters' \
86
- # 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_class_element_modifiers' \
87
- # 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::eat_decorators' \
88
- # 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::is_nth_at_modifier' \
89
- # 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::try_parse_type_arguments' \
90
- # 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::is_at_ts_index_signature_member' \
91
- # 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_return_type_annotation' \
92
- # 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_type_annotation' \
93
-
94
-
95
- if [ "${RELEASE:-0}" = "1" ]; then
96
- (
97
- G="--generate-global-effects"
98
- # shellcheck disable=SC2086
99
- time wasm-opt $WASMOPTFLAGS \
100
- rewriter/wasm/out/wasm_snipped.wasm -o rewriter/wasm/out/optimized.wasm \
101
- --converge -tnh --vacuum \
102
- $G -O4 $G --flatten $G --rereloop $G -O4 $G -O4 $G -O4 \
103
- $G -Oz $G --flatten $G --rereloop $G -Oz $G -Oz $G -Oz \
104
- $G --code-folding $G --const-hoisting $G --dae $G --flatten $G --merge-locals \
105
- $G -O4 $G --flatten $G --rereloop $G -O4 $G -O4 $G -O4 \
106
- $G -Oz $G --flatten $G --rereloop $G -Oz $G -Oz $G -Oz
107
- )
108
- else
109
- cp rewriter/wasm/out/wasm_snipped.wasm rewriter/wasm/out/optimized.wasm
110
- fi
111
-
112
- mkdir -p dist/
113
-
114
- cp rewriter/wasm/out/optimized.wasm dist/scramjet.wasm.wasm
115
- echo "Rewriter Build Complete!"
 
 
 
 
 
 
 
 
 
1
+ # ベースイメージ
2
+ FROM node:20
3
+
4
+ # bash をインストール(多くの場合不要だが念のため)
5
+ RUN apt-get update && apt-get install -y bash
6
+
7
+ # Rustツールチェーンや wasm-bindgen などがインストール済である必要あり
8
+ # (必要ならここに rustup/cargo/wasm-opt/wasm-snip などのインストールを追加)
9
+
10
+ # 作業ディレクトリ
11
+ WORKDIR /app
12
+ COPY . .
13
+
14
+ # build.shの中身をそのまま埋め込む("RUN bash -c"で囲む)
15
+ RUN bash -c '
16
+ set -euo pipefail
17
+ shopt -s inherit_errexit
18
+
19
+ which cargo wasm-bindgen wasm-opt wasm-snip &> /dev/null || {
20
+ echo "Please install cargo, wasm-bindgen, wasm-opt from https://github.com/WebAssembly/binaryen, and wasm-snip from https://github.com/r58playz/wasm-snip!"
21
+ exit 1
22
+ }
23
+
24
+ WBG="wasm-bindgen 0.2.100"
25
+ if ! [[ "$(wasm-bindgen -V)" =~ ^"$WBG" ]]; then
26
+ echo "Incorrect wasm-bindgen-cli version: '\''$(wasm-bindgen -V)'\'' != '\''$WBG'\''"
27
+ exit 1
28
+ fi
29
+
30
+ if ! [ "${RELEASE:-0}" = "1" ]; then
31
+ WASMOPTFLAGS="${WASMOPTFLAGS:-} -g"
32
+ FEATURES="debug,${FEATURES:-}"
33
+ else
34
+ : "${WASMOPTFLAGS:=}"
35
+ : "${FEATURES:=}"
36
+ fi
37
+
38
+ cd rewriter/wasm
39
+ export RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none"
40
+ if [ "${OPTIMIZE_FOR_SIZE:-0}" = "1" ]; then
41
+ export RUSTFLAGS="${RUSTFLAGS} -C opt-level=z"
42
+ fi
43
+
44
+ STD_FEATURES="panic_immediate_abort"
45
+ if [ "${OPTIMIZE_FOR_SPEED:-0}" = "0" ]; then
46
+ STD_FEATURES="${STD_FEATURES},optimize_for_size"
47
+ fi
48
+
49
+ cargo build --release --target wasm32-unknown-unknown \
50
+ -Z build-std=panic_abort,std -Z build-std-features=${STD_FEATURES} \
51
+ --no-default-features --features "$FEATURES"
52
+
53
+ wasm-bindgen --target web --out-dir out/ ../target/wasm32-unknown-unknown/release/wasm.wasm
54
+
55
+ if [[ "$OSTYPE" == "darwin"* || "$OSTYPE" == "freebsd"* || "$OSTYPE" == "dragonfly"* ]]; then
56
+ sed -i "" "s/import.meta.url/\"\"/g" out/wasm.js
57
+ else
58
+ sed -i "s/import.meta.url/\"\"/g" out/wasm.js
59
+ fi
60
+
61
+ cd ../../
62
+
63
+ wasm-snip rewriter/wasm/out/wasm_bg.wasm -o rewriter/wasm/out/wasm_snipped.wasm \
64
+ -p '\''oxc_regular_expression::.*'\'' \
65
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_non_array_type'\'' \
66
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_import_type'\'' \
67
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_operator_or_higher'\'' \
68
+ '\''oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_interface_declaration'\'' \
69
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_mapped_type'\'' \
70
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_index_signature_declaration'\'' \
71
+ '\''oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_import_equals_declaration'\'' \
72
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_or_type_predicate'\'' \
73
+ '\''oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_namespace_or_module_declaration_body'\'' \
74
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_implements_clause'\'' \
75
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_intersection_type_or_higher'\'' \
76
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_type_name'\'' \
77
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_literal_type_node'\'' \
78
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_asserts_type_predicate'\'' \
79
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_tuple_element_type'\'' \
80
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_arguments_of_type_reference'\'' \
81
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_call_signature_member'\'' \
82
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::is_start_of_type'\'' \
83
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_this_type_predicate'\'' \
84
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_query'\'' \
85
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_reference'\'' \
86
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_operator'\'' \
87
+ '\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_literal'\'' \
88
+ '\''oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::is_at_enum_declaration'\'' \
89
+ '\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_element'\'' \
90
+ '\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_identifier'\'' \
91
+ '\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_element_name'\'' \
92
+ '\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_children'\'' \
93
+ '\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_fragment'\'' \
94
+ '\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_expression_container'\'' \
95
+ '\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_expression'\''
96
+
97
+ if [ "${RELEASE:-0}" = "1" ]; then
98
+ G="--generate-global-effects"
99
+ time wasm-opt $WASMOPTFLAGS \
100
+ rewriter/wasm/out/wasm_snipped.wasm -o rewriter/wasm/out/optimized.wasm \
101
+ --converge -tnh --vacuum \
102
+ $G -O4 $G --flatten $G --rereloop $G -O4 $G -O4 $G -O4 \
103
+ $G -Oz $G --flatten $G --rereloop $G -Oz $G -Oz $G -Oz \
104
+ $G --code-folding $G --const-hoisting $G --dae $G --flatten $G --merge-locals \
105
+ $G -O4 $G --flatten $G --rereloop $G -O4 $G -O4 $G -O4 \
106
+ $G -Oz $G --flatten $G --rereloop $G -Oz $G -Oz $G -Oz
107
+ else
108
+ cp rewriter/wasm/out/wasm_snipped.wasm rewriter/wasm/out/optimized.wasm
109
+ fi
110
+
111
+ mkdir -p dist
112
+ cp rewriter/wasm/out/optimized.wasm dist/scramjet.wasm.wasm
113
+
114
+ echo "Rewriter Build Complete!"
115
+ '
116
+
117
+ RUN npm install -g pnpm
118
+ RUN pnpm install
119
+ RUN pnpm build
120
+
121
+ EXPOSE 1337
122
+
123
+ CMD ["pnpm", "dev"]