-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathMakefile.toml
308 lines (254 loc) · 9.29 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
[env]
# Reset rustup recursion limit because otherwise `cargo make clippy_all` fails.
# https://github.com/rust-lang/rustup.rs/blob/d35f94183601a81489bce025c2abc35cd395c909/src/toolchain.rs#L296
RUST_RECURSION_COUNT = "0"
# ---- SCRIPTS ----
[tasks.populate_all]
description = "Populate styles, tags, attributes, etc."
workspace = false
dependencies = ["populate_styles"]
[tasks.populate_styles]
description = "Populate styles"
workspace = false
command = "cargo"
args = ["script", "./scripts/populate_styles.rs"]
# ---- GENERAL ----
[tasks.verify]
description = "Format, lint with Clippy, build, run tests, simulate publish"
workspace = false
dependencies = ["fmt_all", "clippy_all", "all", "test_h_firefox", "publish_dry_run"]
[tasks.verify_only]
description = "Like `verify`, but fails if the code isn't formatted. Primarily for CI."
workspace = false
dependencies = ["fmt_all_check", "clippy_all", "all", "test_h_firefox", "publish_dry_run"]
# ---- BUILD ----
[tasks.build]
description = "Build only Seed"
clear = true
workspace = false
command = "cargo"
args = ["build"]
[tasks.build_release]
extend = "build"
description = "Build only Seed in relase mode"
args = ["build", "--release"]
[tasks.all]
description = "Build Seed and examples"
workspace = false
dependencies = ["build", "build_examples"]
[tasks.all_release]
extend = "all"
description = "Build Seed and examples in release mode"
dependencies = ["build_release", "build_examples_release"]
[tasks.one]
description = "Build Seed and chosen example. Ex: 'cargo make one counter'"
workspace = false
command = "cargo"
args = ["make", "--cwd", "./examples/${@}", "build"]
dependencies = ["build"]
[tasks.one_release]
extend = "one"
description = "Build Seed and chosen example in release mode. Ex: 'cargo make one counter'"
args = ["make", "--cwd", "./examples/${@}", "build_release"]
dependencies = ["build_release"]
# ---- LINT ----
[tasks.fmt_all]
description = "Format Seed and all examples with rustfmt"
workspace = false
dependencies = ["fmt", "fmt_examples"]
[tasks.fmt_all_check]
description = "Check format of Seed and all examples with rustfmt"
workspace = false
dependencies = ["fmt_check", "fmt_examples_check"]
[tasks.clippy]
description = "Lint only Seed with Clippy"
clear = true
workspace = false
install_crate = { rustup_component_name = "clippy", binary = "cargo-clippy", test_arg = "--help" }
command = "cargo"
args = ["clippy", "--all-features", "--", "--deny", "warnings", "--deny", "clippy::pedantic", "--deny", "clippy::nursery"]
[tasks.clippy_one]
description = "Lint Seed and chosen example with Clippy. Ex: 'cargo make clippy_one counter'"
workspace = false
command = "cargo"
args = ["make", "--cwd", "./examples/${@}", "clippy"]
dependencies = ["clippy"]
[tasks.clippy_all]
description = "Lint Seed and all examples with Clippy"
workspace = false
dependencies = ["clippy", "clippy_examples"]
[tasks.publish_dry_run]
description = "Check the crate can be published"
workspace = false
command = "cargo"
args = ["publish", "--dry-run", "--allow-dirty"]
# ---- TEST ----
# wasm-pack test docs:
# https://rustwasm.github.io/wasm-pack/book/commands/test.html
[tasks.test]
description = "Run Seed's tests. Ex: 'cargo make test firefox'. Test envs: [chrome, firefox, safari]"
clear = true
workspace = false
install_crate = { crate_name = "wasm-pack", binary = "wasm-pack", test_arg = "-V" }
command = "wasm-pack"
args = ["test", "--${@}"]
[tasks.test_release]
extend = "test"
description = "Run Seed's tests in release mode. Ex: 'cargo make test firefox'. Test envs: [chrome, firefox, safari]"
args = ["test", "--${@}", "--release"]
[tasks.test_h]
description = "Run headless Seed's tests. Ex: 'cargo make test_h firefox'. Test envs: [chrome, firefox, safari]"
extend = "test"
args = ["test", "--headless", "--${@}"]
[tasks.test_h_firefox]
description = "Run headless Seed's tests with Firefox."
extend = "test"
args = ["test", "--headless", "--firefox"]
[tasks.test_h_release]
extend = "test_h"
description = "Run headless Seed's tests in release mode. Ex: 'cargo make test_h firefox'. Test envs: [chrome, firefox, safari]"
args = ["test", "--headless", "--${@}", "--release"]
[tasks.test_one]
description = "Run a single test in Firefox. Ex 'cargo make test_one my_test'"
clear = true
workspace = false
install_crate = { crate_name = "wasm-pack", binary = "wasm-pack", test_arg = "-V" }
command = "wasm-pack"
args = ["test", "--firefox", "--", "--lib", "${@}"]
[tasks.test_one_h]
description = "Run a single test in headless Firefox. Ex 'cargo make test_one_h my_test'"
clear = true
workspace = false
install_crate = { crate_name = "wasm-pack", binary = "wasm-pack", test_arg = "-V" }
command = "wasm-pack"
args = ["test", "--firefox", "--headless", "--", "--lib", "${@}"]
# ---- START ----
[tasks.start]
description = "Start chosen example. Ex: 'cargo make start counter'"
workspace = false
command = "cargo"
args = ["make", "--cwd", "./examples/${@}", "start"]
[tasks.start_release]
extend = "start"
description = "Start chosen example in release mode. Ex: 'cargo make start counter'"
args = ["make", "--cwd", "./examples/${@}", "start_release"]
[tasks.start_server]
description = "Start server of chosen example (only a few have one). Ex: 'cargo make start_server websocket'"
workspace = false
command = "cargo"
args = ["make", "--cwd", "./examples/${@}", "start_server"]
[tasks.start_server_release]
extend = "start_server"
description = "Start server of chosen example (only a few have one) in release mode. Ex: 'cargo make start_server websocket'"
args = ["make", "--cwd", "./examples/${@}", "start_server_release"]
# ---- DEFAULT TASKS FOR EXAMPLES ----
# These tasks should be run only from the example root
# and example's Makefile.toml should override all tasks in dependencies.
[tasks.default_build]
description = "Build with wasm-pack"
workspace = false
install_crate = { crate_name = "wasm-pack", binary = "wasm-pack", test_arg = "-V" }
command = "wasm-pack"
args = ["build", "--target", "web", "--out-name", "package", "--dev"]
[tasks.default_build_release]
extend = "default_build"
description = "Build with wasm-pack in release mode"
args = ["build", "--target", "web", "--out-name", "package", "--release"]
[tasks.default_start]
description = "Build and start microserver"
workspace = false
install_crate = { crate_name = "microserver", binary = "microserver", test_arg = "-h" }
command = "microserver"
args = ["--port", "8000"]
dependencies = ["build"]
[tasks.default_start_release]
extend = "default_start"
description = "Build and start microserver in release mode"
dependencies = ["build_release"]
[tasks.default_clippy]
description = "Lint with Clippy"
workspace = false
install_crate = { rustup_component_name = "clippy", binary = "cargo-clippy", test_arg = "--help" }
command = "cargo"
args = ["clippy", "--all-features", "--", "--deny", "warnings", "--deny", "clippy::pedantic", "--deny", "clippy::nursery"]
# ---- HELPERS -----
[tasks.build_examples]
description = "Build examples"
workspace = false
command = "cargo"
args = ["make", "for_each", "build"]
[tasks.build_examples_release]
extend = "build_examples"
description = "Build examples in release mode"
args = ["make", "for_each", "build_release"]
[tasks.fmt]
description = "Format with rustfmt"
workspace = false
install_crate = { crate_name = "rustfmt-nightly", rustup_component_name = "rustfmt", binary = "rustfmt", test_arg = "--help" }
command = "cargo"
args = ["fmt", "--all"]
[tasks.fmt_check]
extend = "fmt"
description = "Check format with rustfmt"
args = ["fmt", "--all", "--", "--check"]
[tasks.fmt_examples]
description = "Format all examples with rustfmt"
workspace = false
command = "cargo"
args = ["make", "for_each", "fmt"]
[tasks.fmt_examples_check]
description = "Check format of all examples with rustfmt"
workspace = false
command = "cargo"
args = ["make", "for_each", "fmt_check"]
[tasks.clippy_examples]
description = "Lint examples with Clippy"
workspace = false
command = "cargo"
args = ["make", "for_each", "clippy"]
[tasks.for_each]
description = "Run chosen task for each example in its root. Ex: 'cargo make for_each build'"
workspace = false
script_runner = "@rust"
script = [
'''
//! ```cargo
//! [dependencies]
//! glob = "*"
//! ```
extern crate glob;
use std::process::{Command, exit, Stdio};
use std::env;
use glob::glob;
fn main() {
let args: Vec<String> = env::args().collect();
// args[0] is a script name, args[1] is the given task
if args.len() != 2 {
eprintln!("Wrong number of arguments! Correct example: 'cargo make for_each build'");
exit(1);
}
let task = &args[1];
let mut exit_code = 0;
for entry in glob("examples/*/Makefile.toml").unwrap() {
if let Ok(path) = entry {
let example_root = path.parent().unwrap().to_str().unwrap();
if !run_task_in_example_root(example_root, task) {
exit_code = 1;
}
}
}
exit(exit_code);
}
fn run_task_in_example_root(example_root: &str, task: &str) -> bool {
println!("Example root: '{}'", example_root);
Command::new("cargo")
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.args(&["make", "--cwd", example_root, task])
.output()
.unwrap()
.status
.success()
}
'''
]