xref: /wasmtime-44.0.1/crates/cli-flags/src/lib.rs (revision b3636ff6)
1 //! Contains the common Wasmtime command line interface (CLI) flags.
2 
3 use anyhow::Result;
4 use clap::Parser;
5 use std::time::Duration;
6 use wasmtime::Config;
7 
8 pub mod opt;
9 
10 #[cfg(feature = "logging")]
11 fn init_file_per_thread_logger(prefix: &'static str) {
12     file_per_thread_logger::initialize(prefix);
13     file_per_thread_logger::allow_uninitialized();
14 
15     // Extending behavior of default spawner:
16     // https://docs.rs/rayon/1.1.0/rayon/struct.ThreadPoolBuilder.html#method.spawn_handler
17     // Source code says DefaultSpawner is implementation detail and
18     // shouldn't be used directly.
19     #[cfg(feature = "parallel-compilation")]
20     rayon::ThreadPoolBuilder::new()
21         .spawn_handler(move |thread| {
22             let mut b = std::thread::Builder::new();
23             if let Some(name) = thread.name() {
24                 b = b.name(name.to_owned());
25             }
26             if let Some(stack_size) = thread.stack_size() {
27                 b = b.stack_size(stack_size);
28             }
29             b.spawn(move || {
30                 file_per_thread_logger::initialize(prefix);
31                 thread.run()
32             })?;
33             Ok(())
34         })
35         .build_global()
36         .unwrap();
37 }
38 
39 wasmtime_option_group! {
40     #[derive(PartialEq, Clone)]
41     pub struct OptimizeOptions {
42         /// Optimization level of generated code (0-2, s; default: 2)
43         pub opt_level: Option<wasmtime::OptLevel>,
44 
45         /// Byte size of the guard region after dynamic memories are allocated
46         pub dynamic_memory_guard_size: Option<u64>,
47 
48         /// Force using a "static" style for all wasm memories
49         pub static_memory_forced: Option<bool>,
50 
51         /// Maximum size in bytes of wasm memory before it becomes dynamically
52         /// relocatable instead of up-front-reserved.
53         pub static_memory_maximum_size: Option<u64>,
54 
55         /// Byte size of the guard region after static memories are allocated
56         pub static_memory_guard_size: Option<u64>,
57 
58         /// Bytes to reserve at the end of linear memory for growth for dynamic
59         /// memories.
60         pub dynamic_memory_reserved_for_growth: Option<u64>,
61 
62         /// Indicates whether an unmapped region of memory is placed before all
63         /// linear memories.
64         pub guard_before_linear_memory: Option<bool>,
65 
66         /// Whether to initialize tables lazily, so that instantiation is
67         /// fast but indirect calls are a little slower. If no, tables are
68         /// initialized eagerly from any active element segments that apply to
69         /// them during instantiation. (default: yes)
70         pub table_lazy_init: Option<bool>,
71 
72         /// Enable the pooling allocator, in place of the on-demand allocator.
73         pub pooling_allocator: Option<bool>,
74 
75         /// The number of decommits to do per batch. A batch size of 1
76         /// effectively disables decommit batching. (default: 1)
77         pub pooling_decommit_batch_size: Option<u32>,
78 
79         /// How many bytes to keep resident between instantiations for the
80         /// pooling allocator in linear memories.
81         pub pooling_memory_keep_resident: Option<usize>,
82 
83         /// How many bytes to keep resident between instantiations for the
84         /// pooling allocator in tables.
85         pub pooling_table_keep_resident: Option<usize>,
86 
87         /// Enable memory protection keys for the pooling allocator; this can
88         /// optimize the size of memory slots.
89         pub memory_protection_keys: Option<bool>,
90 
91         /// Configure attempting to initialize linear memory via a
92         /// copy-on-write mapping (default: yes)
93         pub memory_init_cow: Option<bool>,
94 
95         /// The maximum number of WebAssembly instances which can be created
96         /// with the pooling allocator.
97         pub pooling_total_core_instances: Option<u32>,
98 
99         /// The maximum number of WebAssembly components which can be created
100         /// with the pooling allocator.
101         pub pooling_total_component_instances: Option<u32>,
102 
103         /// The maximum number of WebAssembly memories which can be created with
104         /// the pooling allocator.
105         pub pooling_total_memories: Option<u32>,
106 
107         /// The maximum number of WebAssembly tables which can be created with
108         /// the pooling allocator.
109         pub pooling_total_tables: Option<u32>,
110 
111         /// The maximum number of WebAssembly stacks which can be created with
112         /// the pooling allocator.
113         pub pooling_total_stacks: Option<u32>,
114 
115         /// The maximum runtime size of each linear memory in the pooling
116         /// allocator, in bytes.
117         pub pooling_max_memory_size: Option<usize>,
118 
119         /// Whether to enable call-indirect caching.
120         pub cache_call_indirects: Option<bool>,
121 
122         /// The maximum call-indirect cache slot count.
123         ///
124         /// One slot is allocated per indirect callsite; if the module
125         /// has more indirect callsites than this limit, then the
126         /// first callsites in linear order in the code section, up to
127         /// the limit, will receive a cache slot.
128         pub max_call_indirect_cache_slots: Option<usize>,
129     }
130 
131     enum Optimize {
132         ...
133     }
134 }
135 
136 wasmtime_option_group! {
137     #[derive(PartialEq, Clone)]
138     pub struct CodegenOptions {
139         /// Either `cranelift` or `winch`.
140         ///
141         /// Currently only `cranelift` and `winch` are supported, but not all
142         /// builds of Wasmtime have both built in.
143         pub compiler: Option<wasmtime::Strategy>,
144         /// Enable Cranelift's internal debug verifier (expensive)
145         pub cranelift_debug_verifier: Option<bool>,
146         /// Whether or not to enable caching of compiled modules.
147         pub cache: Option<bool>,
148         /// Configuration for compiled module caching.
149         pub cache_config: Option<String>,
150         /// Whether or not to enable parallel compilation of modules.
151         pub parallel_compilation: Option<bool>,
152         /// Whether to enable proof-carrying code (PCC)-based validation.
153         pub pcc: Option<bool>,
154 
155         #[prefixed = "cranelift"]
156         /// Set a cranelift-specific option. Use `wasmtime settings` to see
157         /// all.
158         pub cranelift: Vec<(String, Option<String>)>,
159     }
160 
161     enum Codegen {
162         ...
163     }
164 }
165 
166 wasmtime_option_group! {
167     #[derive(PartialEq, Clone)]
168     pub struct DebugOptions {
169         /// Enable generation of DWARF debug information in compiled code.
170         pub debug_info: Option<bool>,
171         /// Configure whether compiled code can map native addresses to wasm.
172         pub address_map: Option<bool>,
173         /// Configure whether logging is enabled.
174         pub logging: Option<bool>,
175         /// Configure whether logs are emitted to files
176         pub log_to_files: Option<bool>,
177         /// Enable coredump generation to this file after a WebAssembly trap.
178         pub coredump: Option<String>,
179     }
180 
181     enum Debug {
182         ...
183     }
184 }
185 
186 wasmtime_option_group! {
187     #[derive(PartialEq, Clone)]
188     pub struct WasmOptions {
189         /// Enable canonicalization of all NaN values.
190         pub nan_canonicalization: Option<bool>,
191         /// Enable execution fuel with N units fuel, trapping after running out
192         /// of fuel.
193         ///
194         /// Most WebAssembly instructions consume 1 unit of fuel. Some
195         /// instructions, such as `nop`, `drop`, `block`, and `loop`, consume 0
196         /// units, as any execution cost associated with them involves other
197         /// instructions which do consume fuel.
198         pub fuel: Option<u64>,
199         /// Yield when a global epoch counter changes, allowing for async
200         /// operation without blocking the executor.
201         pub epoch_interruption: Option<bool>,
202         /// Maximum stack size, in bytes, that wasm is allowed to consume before a
203         /// stack overflow is reported.
204         pub max_wasm_stack: Option<usize>,
205         /// Allow unknown exports when running commands.
206         pub unknown_exports_allow: Option<bool>,
207         /// Allow the main module to import unknown functions, using an
208         /// implementation that immediately traps, when running commands.
209         pub unknown_imports_trap: Option<bool>,
210         /// Allow the main module to import unknown functions, using an
211         /// implementation that returns default values, when running commands.
212         pub unknown_imports_default: Option<bool>,
213         /// Enables memory error checking. (see wmemcheck.md for more info)
214         pub wmemcheck: Option<bool>,
215         /// Maximum size, in bytes, that a linear memory is allowed to reach.
216         ///
217         /// Growth beyond this limit will cause `memory.grow` instructions in
218         /// WebAssembly modules to return -1 and fail.
219         pub max_memory_size: Option<usize>,
220         /// Maximum size, in table elements, that a table is allowed to reach.
221         pub max_table_elements: Option<u32>,
222         /// Maximum number of WebAssembly instances allowed to be created.
223         pub max_instances: Option<usize>,
224         /// Maximum number of WebAssembly tables allowed to be created.
225         pub max_tables: Option<usize>,
226         /// Maximum number of WebAssembly linear memories allowed to be created.
227         pub max_memories: Option<usize>,
228         /// Force a trap to be raised on `memory.grow` and `table.grow` failure
229         /// instead of returning -1 from these instructions.
230         ///
231         /// This is not necessarily a spec-compliant option to enable but can be
232         /// useful for tracking down a backtrace of what is requesting so much
233         /// memory, for example.
234         pub trap_on_grow_failure: Option<bool>,
235         /// Maximum execution time of wasm code before timing out (1, 2s, 100ms, etc)
236         pub timeout: Option<Duration>,
237         /// Configures support for all WebAssembly proposals implemented.
238         pub all_proposals: Option<bool>,
239         /// Configure support for the bulk memory proposal.
240         pub bulk_memory: Option<bool>,
241         /// Configure support for the multi-memory proposal.
242         pub multi_memory: Option<bool>,
243         /// Configure support for the multi-value proposal.
244         pub multi_value: Option<bool>,
245         /// Configure support for the reference-types proposal.
246         pub reference_types: Option<bool>,
247         /// Configure support for the simd proposal.
248         pub simd: Option<bool>,
249         /// Configure support for the relaxed-simd proposal.
250         pub relaxed_simd: Option<bool>,
251         /// Configure forcing deterministic and host-independent behavior of
252         /// the relaxed-simd instructions.
253         ///
254         /// By default these instructions may have architecture-specific behavior as
255         /// allowed by the specification, but this can be used to force the behavior
256         /// of these instructions to match the deterministic behavior classified in
257         /// the specification. Note that enabling this option may come at a
258         /// performance cost.
259         pub relaxed_simd_deterministic: Option<bool>,
260         /// Configure support for the tail-call proposal.
261         pub tail_call: Option<bool>,
262         /// Configure support for the threads proposal.
263         pub threads: Option<bool>,
264         /// Configure support for the memory64 proposal.
265         pub memory64: Option<bool>,
266         /// Configure support for the component-model proposal.
267         pub component_model: Option<bool>,
268         /// Configure support for the function-references proposal.
269         pub function_references: Option<bool>,
270         /// Configure support for the GC proposal.
271         pub gc: Option<bool>,
272     }
273 
274     enum Wasm {
275         ...
276     }
277 }
278 
279 wasmtime_option_group! {
280     #[derive(PartialEq, Clone)]
281     pub struct WasiOptions {
282         /// Enable support for WASI CLI APIs, including filesystems, sockets, clocks, and random.
283         pub cli: Option<bool>,
284         /// Deprecated alias for `cli`
285         pub common: Option<bool>,
286         /// Enable support for WASI neural network API (experimental)
287         pub nn: Option<bool>,
288         /// Enable support for WASI threading API (experimental)
289         pub threads: Option<bool>,
290         /// Enable support for WASI HTTP API (experimental)
291         pub http: Option<bool>,
292         /// Inherit environment variables and file descriptors following the
293         /// systemd listen fd specification (UNIX only)
294         pub listenfd: Option<bool>,
295         /// Grant access to the given TCP listen socket
296         pub tcplisten: Vec<String>,
297         /// Implement WASI CLI APIs with preview2 primitives (experimental).
298         ///
299         /// Indicates that the implementation of WASI preview1 should be backed by
300         /// the preview2 implementation for components.
301         ///
302         /// This will become the default in the future and this option will be
303         /// removed. For now this is primarily here for testing.
304         pub preview2: Option<bool>,
305         /// Pre-load machine learning graphs (i.e., models) for use by wasi-nn.
306         ///
307         /// Each use of the flag will preload a ML model from the host directory
308         /// using the given model encoding. The model will be mapped to the
309         /// directory name: e.g., `--wasi-nn-graph openvino:/foo/bar` will preload
310         /// an OpenVINO model named `bar`. Note that which model encodings are
311         /// available is dependent on the backends implemented in the
312         /// `wasmtime_wasi_nn` crate.
313         pub nn_graph: Vec<WasiNnGraph>,
314         /// Flag for WASI preview2 to inherit the host's network within the
315         /// guest so it has full access to all addresses/ports/etc.
316         pub inherit_network: Option<bool>,
317         /// Indicates whether `wasi:sockets/ip-name-lookup` is enabled or not.
318         pub allow_ip_name_lookup: Option<bool>,
319         /// Indicates whether `wasi:sockets` TCP support is enabled or not.
320         pub tcp: Option<bool>,
321         /// Indicates whether `wasi:sockets` UDP support is enabled or not.
322         pub udp: Option<bool>,
323         /// Allows imports from the `wasi_unstable` core wasm module.
324         pub preview0: Option<bool>,
325         /// Inherit all environment variables from the parent process.
326         ///
327         /// This option can be further overwritten with `--env` flags.
328         pub inherit_env: Option<bool>,
329     }
330 
331     enum Wasi {
332         ...
333     }
334 }
335 
336 #[derive(Debug, Clone, PartialEq)]
337 pub struct WasiNnGraph {
338     pub format: String,
339     pub dir: String,
340 }
341 
342 /// Common options for commands that translate WebAssembly modules
343 #[derive(Parser, Clone)]
344 pub struct CommonOptions {
345     // These options groups are used to parse `-O` and such options but aren't
346     // the raw form consumed by the CLI. Instead they're pushed into the `pub`
347     // fields below as part of the `configure` method.
348     //
349     // Ideally clap would support `pub opts: OptimizeOptions` and parse directly
350     // into that but it does not appear to do so for multiple `-O` flags for
351     // now.
352     /// Optimization and tuning related options for wasm performance, `-O help` to
353     /// see all.
354     #[arg(short = 'O', long = "optimize", value_name = "KEY[=VAL[,..]]")]
355     opts_raw: Vec<opt::CommaSeparated<Optimize>>,
356 
357     /// Codegen-related configuration options, `-C help` to see all.
358     #[arg(short = 'C', long = "codegen", value_name = "KEY[=VAL[,..]]")]
359     codegen_raw: Vec<opt::CommaSeparated<Codegen>>,
360 
361     /// Debug-related configuration options, `-D help` to see all.
362     #[arg(short = 'D', long = "debug", value_name = "KEY[=VAL[,..]]")]
363     debug_raw: Vec<opt::CommaSeparated<Debug>>,
364 
365     /// Options for configuring semantic execution of WebAssembly, `-W help` to see
366     /// all.
367     #[arg(short = 'W', long = "wasm", value_name = "KEY[=VAL[,..]]")]
368     wasm_raw: Vec<opt::CommaSeparated<Wasm>>,
369 
370     /// Options for configuring WASI and its proposals, `-S help` to see all.
371     #[arg(short = 'S', long = "wasi", value_name = "KEY[=VAL[,..]]")]
372     wasi_raw: Vec<opt::CommaSeparated<Wasi>>,
373 
374     // These fields are filled in by the `configure` method below via the
375     // options parsed from the CLI above. This is what the CLI should use.
376     #[arg(skip)]
377     configured: bool,
378     #[arg(skip)]
379     pub opts: OptimizeOptions,
380     #[arg(skip)]
381     pub codegen: CodegenOptions,
382     #[arg(skip)]
383     pub debug: DebugOptions,
384     #[arg(skip)]
385     pub wasm: WasmOptions,
386     #[arg(skip)]
387     pub wasi: WasiOptions,
388 }
389 
390 macro_rules! match_feature {
391     (
392         [$feat:tt : $config:expr]
393         $val:ident => $e:expr,
394         $p:pat => err,
395     ) => {
396         #[cfg(feature = $feat)]
397         {
398             if let Some($val) = $config {
399                 $e;
400             }
401         }
402         #[cfg(not(feature = $feat))]
403         {
404             if let Some($p) = $config {
405                 anyhow::bail!(concat!("support for ", $feat, " disabled at compile time"));
406             }
407         }
408     };
409 }
410 
411 impl CommonOptions {
412     fn configure(&mut self) {
413         if self.configured {
414             return;
415         }
416         self.configured = true;
417         self.opts.configure_with(&self.opts_raw);
418         self.codegen.configure_with(&self.codegen_raw);
419         self.debug.configure_with(&self.debug_raw);
420         self.wasm.configure_with(&self.wasm_raw);
421         self.wasi.configure_with(&self.wasi_raw);
422     }
423 
424     pub fn init_logging(&mut self) -> Result<()> {
425         self.configure();
426         if self.debug.logging == Some(false) {
427             return Ok(());
428         }
429         #[cfg(feature = "logging")]
430         if self.debug.log_to_files == Some(true) {
431             let prefix = "wasmtime.dbg.";
432             init_file_per_thread_logger(prefix);
433         } else {
434             use std::io::IsTerminal;
435             use tracing_subscriber::{EnvFilter, FmtSubscriber};
436             let b = FmtSubscriber::builder()
437                 .with_writer(std::io::stderr)
438                 .with_env_filter(EnvFilter::from_env("WASMTIME_LOG"))
439                 .with_ansi(std::io::stderr().is_terminal());
440             b.init();
441         }
442         #[cfg(not(feature = "logging"))]
443         if self.debug.log_to_files == Some(true) || self.debug.logging == Some(true) {
444             anyhow::bail!("support for logging disabled at compile time");
445         }
446         Ok(())
447     }
448 
449     pub fn config(
450         &mut self,
451         target: Option<&str>,
452         pooling_allocator_default: Option<bool>,
453     ) -> Result<Config> {
454         self.configure();
455         let mut config = Config::new();
456 
457         match_feature! {
458             ["cranelift" : self.codegen.compiler]
459             strategy => config.strategy(strategy),
460             _ => err,
461         }
462         match_feature! {
463             ["cranelift" : target]
464             target => config.target(target)?,
465             _ => err,
466         }
467         match_feature! {
468             ["cranelift" : self.codegen.cranelift_debug_verifier]
469             enable => config.cranelift_debug_verifier(enable),
470             true => err,
471         }
472         if let Some(enable) = self.debug.debug_info {
473             config.debug_info(enable);
474         }
475         if self.debug.coredump.is_some() {
476             #[cfg(feature = "coredump")]
477             config.coredump_on_trap(true);
478             #[cfg(not(feature = "coredump"))]
479             anyhow::bail!("support for coredumps disabled at compile time");
480         }
481         match_feature! {
482             ["cranelift" : self.opts.opt_level]
483             level => config.cranelift_opt_level(level),
484             _ => err,
485         }
486         match_feature! {
487             ["cranelift" : self.wasm.nan_canonicalization]
488             enable => config.cranelift_nan_canonicalization(enable),
489             true => err,
490         }
491         match_feature! {
492             ["cranelift" : self.codegen.pcc]
493             enable => config.cranelift_pcc(enable),
494             true => err,
495         }
496 
497         self.enable_wasm_features(&mut config)?;
498 
499         #[cfg(feature = "cranelift")]
500         for (name, value) in self.codegen.cranelift.iter() {
501             let name = name.replace('-', "_");
502             unsafe {
503                 match value {
504                     Some(val) => {
505                         config.cranelift_flag_set(&name, val);
506                     }
507                     None => {
508                         config.cranelift_flag_enable(&name);
509                     }
510                 }
511             }
512         }
513         #[cfg(not(feature = "cranelift"))]
514         if !self.codegen.cranelift.is_empty() {
515             anyhow::bail!("support for cranelift disabled at compile time");
516         }
517 
518         #[cfg(feature = "cache")]
519         if self.codegen.cache != Some(false) {
520             match &self.codegen.cache_config {
521                 Some(path) => {
522                     config.cache_config_load(path)?;
523                 }
524                 None => {
525                     config.cache_config_load_default()?;
526                 }
527             }
528         }
529         #[cfg(not(feature = "cache"))]
530         if self.codegen.cache == Some(true) {
531             anyhow::bail!("support for caching disabled at compile time");
532         }
533 
534         match_feature! {
535             ["parallel-compilation" : self.codegen.parallel_compilation]
536             enable => config.parallel_compilation(enable),
537             true => err,
538         }
539 
540         if let Some(max) = self.opts.static_memory_maximum_size {
541             config.static_memory_maximum_size(max);
542         }
543 
544         if let Some(enable) = self.opts.static_memory_forced {
545             config.static_memory_forced(enable);
546         }
547 
548         if let Some(size) = self.opts.static_memory_guard_size {
549             config.static_memory_guard_size(size);
550         }
551 
552         if let Some(size) = self.opts.dynamic_memory_guard_size {
553             config.dynamic_memory_guard_size(size);
554         }
555         if let Some(size) = self.opts.dynamic_memory_reserved_for_growth {
556             config.dynamic_memory_reserved_for_growth(size);
557         }
558         if let Some(enable) = self.opts.guard_before_linear_memory {
559             config.guard_before_linear_memory(enable);
560         }
561         if let Some(enable) = self.opts.table_lazy_init {
562             config.table_lazy_init(enable);
563         }
564 
565         // If fuel has been configured, set the `consume fuel` flag on the config.
566         if self.wasm.fuel.is_some() {
567             config.consume_fuel(true);
568         }
569 
570         if let Some(enable) = self.wasm.epoch_interruption {
571             config.epoch_interruption(enable);
572         }
573         if let Some(enable) = self.debug.address_map {
574             config.generate_address_map(enable);
575         }
576         if let Some(enable) = self.opts.memory_init_cow {
577             config.memory_init_cow(enable);
578         }
579         if let Some(enable) = self.opts.cache_call_indirects {
580             config.cache_call_indirects(enable);
581         }
582         if let Some(max) = self.opts.max_call_indirect_cache_slots {
583             config.max_call_indirect_cache_slots(max);
584         }
585 
586         match_feature! {
587             ["pooling-allocator" : self.opts.pooling_allocator.or(pooling_allocator_default)]
588             enable => {
589                 if enable {
590                     let mut cfg = wasmtime::PoolingAllocationConfig::default();
591                     if let Some(size) = self.opts.pooling_memory_keep_resident {
592                         cfg.linear_memory_keep_resident(size);
593                     }
594                     if let Some(size) = self.opts.pooling_table_keep_resident {
595                         cfg.table_keep_resident(size);
596                     }
597                     if let Some(limit) = self.opts.pooling_total_core_instances {
598                         cfg.total_core_instances(limit);
599                     }
600                     if let Some(limit) = self.opts.pooling_total_component_instances {
601                         cfg.total_component_instances(limit);
602                     }
603                     if let Some(limit) = self.opts.pooling_total_memories {
604                         cfg.total_memories(limit);
605                     }
606                     if let Some(limit) = self.opts.pooling_total_tables {
607                         cfg.total_tables(limit);
608                     }
609                     if let Some(limit) = self.opts.pooling_total_stacks {
610                         cfg.total_stacks(limit);
611                     }
612                     if let Some(limit) = self.opts.pooling_max_memory_size {
613                         cfg.max_memory_size(limit);
614                     }
615                     match_feature! {
616                         ["memory-protection-keys" : self.opts.memory_protection_keys]
617                         enable => cfg.memory_protection_keys(if enable {
618                             wasmtime::MpkEnabled::Enable
619                         } else {
620                             wasmtime::MpkEnabled::Disable
621                         }),
622                         _ => err,
623                     }
624                     config.allocation_strategy(wasmtime::InstanceAllocationStrategy::Pooling(cfg));
625                 }
626             },
627             true => err,
628         }
629 
630         if self.opts.memory_protection_keys.unwrap_or(false)
631             && !self.opts.pooling_allocator.unwrap_or(false)
632         {
633             anyhow::bail!("memory protection keys require the pooling allocator");
634         }
635 
636         if let Some(max) = self.wasm.max_wasm_stack {
637             config.max_wasm_stack(max);
638         }
639 
640         if let Some(enable) = self.wasm.relaxed_simd_deterministic {
641             config.relaxed_simd_deterministic(enable);
642         }
643         match_feature! {
644             ["cranelift" : self.wasm.wmemcheck]
645             enable => config.wmemcheck(enable),
646             true => err,
647         }
648 
649         Ok(config)
650     }
651 
652     pub fn enable_wasm_features(&self, config: &mut Config) -> Result<()> {
653         let all = self.wasm.all_proposals;
654 
655         if let Some(enable) = self.wasm.simd.or(all) {
656             config.wasm_simd(enable);
657         }
658         if let Some(enable) = self.wasm.relaxed_simd.or(all) {
659             config.wasm_relaxed_simd(enable);
660         }
661         if let Some(enable) = self.wasm.bulk_memory.or(all) {
662             config.wasm_bulk_memory(enable);
663         }
664         if let Some(enable) = self.wasm.multi_value.or(all) {
665             config.wasm_multi_value(enable);
666         }
667         if let Some(enable) = self.wasm.tail_call.or(all) {
668             config.wasm_tail_call(enable);
669         }
670         if let Some(enable) = self.wasm.multi_memory.or(all) {
671             config.wasm_multi_memory(enable);
672         }
673         if let Some(enable) = self.wasm.memory64.or(all) {
674             config.wasm_memory64(enable);
675         }
676 
677         macro_rules! handle_conditionally_compiled {
678             ($(($feature:tt, $field:tt, $method:tt))*) => ($(
679                 if let Some(enable) = self.wasm.$field.or(all) {
680                     #[cfg(feature = $feature)]
681                     config.$method(enable);
682                     #[cfg(not(feature = $feature))]
683                     if enable && all.is_none() {
684                         anyhow::bail!("support for {} was disabled at compile-time", $feature);
685                     }
686                 }
687             )*)
688         }
689 
690         handle_conditionally_compiled! {
691             ("component-model", component_model, wasm_component_model)
692             ("threads", threads, wasm_threads)
693             ("gc", gc, wasm_gc)
694             ("gc", reference_types, wasm_reference_types)
695             ("gc", function_references, wasm_function_references)
696         }
697         Ok(())
698     }
699 }
700 
701 impl PartialEq for CommonOptions {
702     fn eq(&self, other: &CommonOptions) -> bool {
703         let mut me = self.clone();
704         me.configure();
705         let mut other = other.clone();
706         other.configure();
707         let CommonOptions {
708             opts_raw: _,
709             codegen_raw: _,
710             debug_raw: _,
711             wasm_raw: _,
712             wasi_raw: _,
713             configured: _,
714 
715             opts,
716             codegen,
717             debug,
718             wasm,
719             wasi,
720         } = me;
721         opts == other.opts
722             && codegen == other.codegen
723             && debug == other.debug
724             && wasm == other.wasm
725             && wasi == other.wasi
726     }
727 }
728