soiz1 commited on
Commit
516909f
·
verified ·
1 Parent(s): 5a70a9a

Update rewriter/wasm/build.sh

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