-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.toml
111 lines (94 loc) · 2.6 KB
/
Makefile.toml
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
[env]
PROJECT_NAME = "rust_xlsx_wasm_example"
BIN_NAME = "bin_example"
WASM_UNKNOWN = "wasm32-unknown-unknown"
WASM_WASI = "wasm32-wasi"
PROFILE_NAME = "debug"
PROFILE_FLAG = "dev"
IS_RELEASE = false
[env.release]
PROFILE_NAME = "release"
PROFILE_FLAG = "release"
IS_RELEASE = true
[tasks.all]
dependencies = ["browser", "nodejs", "deno", "wasi"]
[tasks.browser]
env = { "CARGO_FEATURE" = "browser", "WASM_DIRECTORY" = "browser", "BINDGEN_TARGET" = "no-modules" }
run_task = { name = "javascript" }
[tasks.nodejs]
env = { "CARGO_FEATURE" = "nodejs", "WASM_DIRECTORY" = "nodejs", "BINDGEN_TARGET" = "nodejs" }
run_task = { name = "javascript" }
[tasks.deno]
env = { "CARGO_FEATURE" = "deno", "WASM_DIRECTORY" = "deno", "BINDGEN_TARGET" = "deno" }
run_task = { name = "javascript" }
[tasks.javascript]
env = { "JAVASCRIPT" = true, "CARGO_TARGET" = "--lib", "WASM_TARGET" = "${WASM_UNKNOWN}", "FILE_NAME" = "${PROJECT_NAME}" }
extend = "build_and_process"
[tasks.wasi]
private = false
env = { "JAVASCRIPT" = false, "CARGO_TARGET" = "--bins", "WASM_TARGET" = "${WASM_WASI}", "FILE_NAME" = "${BIN_NAME}", "CARGO_FEATURE" = "default", "WASM_DIRECTORY" = "wasi" }
extend = "build_and_process"
[tasks.build_and_process]
private = true
run_task = { name = [
"build",
"bindgen",
"optimize",
"copy_wasm_to_pkg",
"copy_static_files",
] }
[tasks.build]
private = true
args = [
"build",
"--features",
"${CARGO_FEATURE}",
"--profile",
"${PROFILE_FLAG}",
"--target",
"${WASM_TARGET}",
"${CARGO_TARGET}",
]
[tasks.bindgen]
condition = { env_true = ["JAVASCRIPT"] }
private = true
command = "wasm-bindgen"
args = [
"target/${WASM_TARGET}/${PROFILE_NAME}/${FILE_NAME}.wasm",
"--out-dir",
"pkg/${WASM_DIRECTORY}",
"--no-typescript",
"--target",
"${BINDGEN_TARGET}",
]
[tasks.optimize]
condition = { env_true = ["JAVASCRIPT", "IS_RELEASE"] }
command = "wasm-opt"
args = [
"pkg/${WASM_DIRECTORY}/${FILE_NAME}_bg.wasm",
"-o",
"pkg/${WASM_DIRECTORY}/${FILE_NAME}_bg.wasm",
"-O4",
]
[tasks.copy_wasm_to_pkg]
condition = { env_false = ["JAVASCRIPT"] }
private = true
script_runner = "@duckscript"
script = '''
# Copy from `target/[...]/${FILE_NAME}.wasm` to `pkg/[...]/${PROJECT_NAME}.wasm`
# so that the final output has a similar filename as the other targets
cp target/${WASM_TARGET}/${PROFILE_NAME}/${FILE_NAME}.wasm pkg/${WASM_DIRECTORY}/${PROJECT_NAME}.wasm
'''
[tasks.copy_static_files]
private = true
script_runner = "@duckscript"
script = '''
glob_cp static_data/${WASM_DIRECTORY}/**/* pkg/${WASM_DIRECTORY}/
'''
[tasks.clean]
clear = true
script_runner = "@duckscript"
script = '''
rm -r pkg
exec --fail-on-error cargo clean
'''