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

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +109 -15
Dockerfile CHANGED
@@ -1,29 +1,123 @@
1
- # ベースイメージ(Node.jsとpnpmを含む)
2
  FROM node:20
3
 
4
- # 作業ディレクトリを設定
 
 
 
 
 
 
5
  WORKDIR /app
6
  COPY . .
7
 
8
- # bash をインストール
9
- RUN apt-get update && apt-get install -y bash
 
 
10
 
11
- RUN chmod +x rewriter/wasm/build.sh
 
 
 
12
 
13
- SHELL ["/bin/bash", "-c"]
14
- # pnpm をグローバルにインストール
15
- RUN npm install -g pnpm
 
 
16
 
17
- # 依存関係をインストール
18
- RUN pnpm install
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- RUN set -eo pipefail 2>/dev/null || set -eo && bash rewriter/wasm/build.sh
21
 
22
- # Scramjet 全体をビルド
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  RUN pnpm build
24
 
25
- # ポート1337を開放
26
  EXPOSE 1337
27
 
28
- # 開発サーバーを起動(ファイル変更に追従)
29
- CMD ["pnpm", "dev"]
 
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"]