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