-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbuild-wasm.sh
executable file
·50 lines (41 loc) · 1.55 KB
/
build-wasm.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
export RES_PATH=learn-wgpu-zh
#
cargo build --no-default-features --profile wasm-release --target wasm32-unknown-unknown --features webgl \
--bin tutorial1-window \
--bin tutorial2-surface \
--bin tutorial3-pipeline \
--bin tutorial4-buffer \
--bin tutorial5-textures \
--bin tutorial6-uniforms \
--bin tutorial7-instancing \
--bin tutorial8-depth \
--bin tutorial9-models \
--bin tutorial10-lighting \
--bin tutorial11-normals \
--bin tutorial12-camera
# 只能使用 WebGPU 的示例程序
cargo build --no-default-features --profile wasm-release --target wasm32-unknown-unknown \
--bin compute-pipeline \
--bin vertex-animation \
--bin hilbert-curve \
--bin hdr
# 使用 raw window handle 的示例程序
cargo build --no-default-features --features web_rwh --profile wasm-release --target wasm32-unknown-unknown \
--bin wgpu-in-web
# 创建 wasm 目录
mkdir -p "docs/public/wasm"
# Generate bindings
for i in target/wasm32-unknown-unknown/wasm-release/*.wasm;
do
wasm-bindgen --no-typescript --out-dir wasm --web "$i";
# 优化 wasm 包大小
filename=$(basename "$i");
# Remove the .wasm extension from filename
name_no_extension="${filename%.wasm}";
wasm-opt -Oz wasm/"$name_no_extension"_bg.wasm --output docs/public/wasm/"$name_no_extension"_bg.wasm;
cp wasm/"$name_no_extension".js docs/public/wasm/"$name_no_extension".js
done
# 创建 assets 目标目录(如果不存在)
mkdir -p docs/public/assets
# 拷贝 wgpu-in-web 的 assets 目录下的所有文件
cp -r code/integration-and-debugging/wgpu_in_web/assets/* docs/public/assets/