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