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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
use clap::Parser as ClapParser;
#[path = "main/cli.rs"]
mod cli;
#[path = "main/commands.rs"]
mod commands;
#[path = "main/context_cmd.rs"]
mod context_cmd;
#[path = "main/context_data.rs"]
mod context_data;
#[path = "main/context_format.rs"]
mod context_format;
#[path = "main/diagnostic.rs"]
#[allow(dead_code)]
mod diagnostic;
#[path = "main/format_cmd.rs"]
mod format_cmd;
#[path = "main/repl.rs"]
mod repl;
#[path = "main/replay_cmd.rs"]
mod replay_cmd;
#[cfg(feature = "wasip2")]
#[path = "main/run_wasip2.rs"]
mod run_wasip2;
#[path = "main/run_wasm_gc.rs"]
mod run_wasm_gc;
#[path = "main/shared.rs"]
mod shared;
#[path = "main/why_cmd.rs"]
mod why_cmd;
use cli::{Cli, Commands, CompilePolicyMode};
#[allow(unused_imports)]
use cli::{CompileTarget, DeployPack, DeployPreset};
fn main() {
let cli = Cli::parse();
match &cli.command {
Commands::Run {
file,
module_root,
record,
expr,
input_file,
self_host,
profile,
wasm_gc,
wasip2,
program_args,
} => {
let expressions = match shared::collect_entry_expressions(expr, input_file.as_deref()) {
Ok(list) => list,
Err(e) => {
use colored::Colorize;
eprintln!("{}", e.red());
std::process::exit(1);
}
};
if !expressions.is_empty() && *self_host {
use colored::Colorize;
eprintln!(
"{}",
"--expr / --input-file are not supported with --self-host in this release"
.red()
);
std::process::exit(1);
}
if *wasip2 {
if !expressions.is_empty() {
use colored::Colorize;
eprintln!(
"{}",
"--expr / --input-file are not supported with --wasip2 yet (Phase 1.7 \
minimal scope — extends in a follow-up)"
.red()
);
std::process::exit(1);
}
#[cfg(feature = "wasip2")]
run_wasip2::cmd_run_wasip2(
file,
module_root.as_deref(),
record.as_deref(),
program_args.clone(),
);
#[cfg(not(feature = "wasip2"))]
{
use colored::Colorize;
eprintln!(
"{}",
"--wasip2 requires --features wasip2 (rebuild with: \
cargo build --features wasip2)"
.red()
);
std::process::exit(1);
}
} else if *wasm_gc {
if expressions.is_empty() {
run_wasm_gc::cmd_run_wasm_gc(
file,
module_root.as_deref(),
program_args.clone(),
record.as_deref(),
None,
);
} else {
// Batch: each --expr gets its own fresh wasmtime
// instance so recording state / module globals
// start clean per expression.
for expr_src in &expressions {
run_wasm_gc::cmd_run_wasm_gc(
file,
module_root.as_deref(),
program_args.clone(),
record.as_deref(),
Some(expr_src.as_str()),
);
}
}
} else if *self_host {
commands::cmd_run_self_hosted(
file,
module_root.as_deref(),
record.as_deref(),
program_args.clone(),
);
} else if expressions.is_empty() {
commands::cmd_run_vm(
file,
module_root.as_deref(),
record.as_deref(),
program_args.clone(),
*profile,
None,
);
} else {
// Batch: run each expression as its own invocation so that
// recording state and VM globals start fresh each time.
for expr_src in &expressions {
commands::cmd_run_vm(
file,
module_root.as_deref(),
record.as_deref(),
program_args.clone(),
*profile,
Some(expr_src.as_str()),
);
}
}
}
Commands::Check {
file,
module_root,
deps,
verbose,
json,
} => {
commands::cmd_check(file, module_root.as_deref(), *deps, *verbose, *json);
}
Commands::Verify {
file,
module_root,
deps,
verbose,
json,
hostile,
wasm_gc,
} => {
commands::cmd_verify(
file,
module_root.as_deref(),
*deps,
*verbose,
*json,
*hostile,
*wasm_gc,
);
}
Commands::Audit {
path,
module_root,
json,
hostile,
} => {
commands::cmd_audit(path, module_root.as_deref(), *json, *hostile);
}
Commands::Format { path, check, json } => {
format_cmd::cmd_format(path, *check, *json);
}
Commands::Replay {
recording,
diff,
test,
check_args,
self_host,
wasm_gc,
json,
} => {
replay_cmd::cmd_replay(
recording,
*diff,
*test,
*check_args,
*self_host,
*wasm_gc,
*json,
);
}
Commands::Repl => {
repl::cmd_repl();
}
Commands::Context {
file,
module_root,
output,
json,
decisions_only,
focus,
depth,
budget,
} => {
context_cmd::cmd_context(
file,
module_root.as_deref(),
output.as_deref(),
*json,
*decisions_only,
focus.as_deref(),
*depth,
*budget,
);
}
Commands::Compile {
file,
output,
name,
module_root,
target,
with_replay,
policy,
guest_entry,
with_self_host_support,
pack,
preset,
handler,
world,
optimize,
emit_ir_after,
explain_passes,
json,
} => {
let policy_mode = (*policy).unwrap_or(if *with_replay {
CompilePolicyMode::Runtime
} else {
CompilePolicyMode::Embed
});
// Expand --preset into the (target, pack) pair it stands for.
// Clap's `conflicts_with_all` already rejects mixing --preset
// with explicit axes.
let (effective_target, effective_pack) = match preset {
// wasm-gc + the synthesised `aver_http_handle` wrapper is
// the production shape on Cloudflare Workers: workerd
// ships a stable wasm-gc + tail-call V8, the runtime is
// inlined as per-instantiation `__rt_*` helpers (no
// `WebAssembly.instantiate(bytes, …)` from runtime-fetched
// bytes — that's the path Workers reject). User must
// pass `--handler <fn>` (validated below).
Some(cli::DeployPreset::Cloudflare) => (
cli::CompileTarget::WasmGc,
Some(cli::DeployPack::Cloudflare),
),
None => (*target, *pack),
};
if matches!(preset, Some(cli::DeployPreset::Cloudflare)) && handler.is_none() {
use colored::Colorize;
eprintln!(
"{}",
"--preset cloudflare requires --handler <fn> (the Aver fn with signature \
`Fn(HttpRequest) -> HttpResponse` to expose as the request handler)"
.red()
);
std::process::exit(1);
}
// `--emit-ir-after=PASS` short-circuits before codegen — print
// the IR snapshot for the named stage and exit. Drives observability
// in 0.15.1 without touching the compile path otherwise.
if let Some(stage) = emit_ir_after.as_deref() {
commands::cmd_emit_ir_after(file, module_root.as_deref(), stage);
return;
}
// `--explain-passes` runs the full pipeline (no codegen) and
// prints a per-pass diagnostic report. Same short-circuit
// shape as `--emit-ir-after`. `--json` switches to a stable
// machine-readable shape for CI consumption.
if *explain_passes {
commands::cmd_explain_passes(file, module_root.as_deref(), *json);
return;
}
commands::cmd_compile(commands::CompileOptions {
file,
output_dir: output,
project_name: name.as_deref(),
module_root_override: module_root.as_deref(),
target: effective_target,
with_replay: *with_replay,
policy_mode: &policy_mode,
guest_entry: guest_entry.as_deref(),
with_self_host_support: *with_self_host_support,
pack: effective_pack,
handler: handler.as_deref(),
world: *world,
optimize: *optimize,
});
}
Commands::Why {
file,
module_root,
verbose,
json,
} => {
why_cmd::cmd_why(file, module_root.as_deref(), *verbose, *json);
}
Commands::Bench {
scenario,
target,
iterations,
warmup,
json,
save_baseline,
compare,
baseline_dir,
fail_on_regression,
} => {
commands::cmd_bench(commands::BenchOptions {
scenario_path: scenario,
target,
iterations: *iterations,
warmup: *warmup,
json: *json,
save_baseline: save_baseline.as_deref(),
compare: compare.as_deref(),
baseline_dir: baseline_dir.as_deref(),
fail_on_regression: *fail_on_regression,
});
}
Commands::Proof {
file,
output,
name,
module_root,
backend,
verify_mode,
} => {
commands::cmd_proof(
file,
output,
name.as_deref(),
module_root.as_deref(),
backend,
verify_mode,
);
}
}
}