diff --git a/docs/cli-options.md b/docs/cli-options.md index 5701cb48a6..be78272a78 100644 --- a/docs/cli-options.md +++ b/docs/cli-options.md @@ -95,3 +95,14 @@ $ wasmtime foo.cwasm AOT-compiled modules can be run from hosts that are compatible with the target environment of the AOT-completed module. + +## `settings` + +This subcommand is used to print the available Cranelift settings for a given target. + +When run without options, it will print the settings for the host target and also +display what Cranelift settings are inferred for the host: + +```sh +$ wasmtime settings +``` diff --git a/src/commands/settings.rs b/src/commands/settings.rs index e791c7ae72..63a7beff92 100644 --- a/src/commands/settings.rs +++ b/src/commands/settings.rs @@ -25,13 +25,13 @@ impl SettingsCommand { None => native::builder(), }; - let mut enums = (Vec::new(), 0); - let mut nums = (Vec::new(), 0); - let mut bools = (Vec::new(), 0); - let mut presets = (Vec::new(), 0); + let mut enums = (Vec::new(), 0, "Enum settings:"); + let mut nums = (Vec::new(), 0, "Numerical settings:"); + let mut bools = (Vec::new(), 0, "Boolean settings:"); + let mut presets = (Vec::new(), 0, "Presets:"); for setting in settings.iter() { - let (collection, max) = match setting.kind { + let (collection, max, _) = match setting.kind { SettingKind::Enum => &mut enums, SettingKind::Num => &mut nums, SettingKind::Bool => &mut bools, @@ -52,40 +52,33 @@ impl SettingsCommand { println!("Cranelift settings for target '{}':", settings.triple()); - if !enums.0.is_empty() { - println!(); - Self::print_settings("Enum settings:", enums.0, enums.1); - } - - if !nums.0.is_empty() { - println!(); - Self::print_settings("Numerical settings:", nums.0, nums.1); - } - - if !bools.0.is_empty() { - println!(); - Self::print_settings("Boolean settings:", bools.0, bools.1); - } + for (collection, max, header) in &mut [enums, nums, bools, presets] { + if collection.is_empty() { + continue; + } - if !presets.0.is_empty() { + collection.sort_by_key(|k| k.name); println!(); - Self::print_settings("Presets:", presets.0, presets.1); + Self::print_settings(header, collection, *max); } if self.target.is_none() { let isa = settings.finish(settings::Flags::new(settings::builder())); println!(); - println!("Settings enabled for this host:"); + println!("Settings inferred for the current host:"); + + let mut enabled = isa.enabled_isa_flags(); + enabled.sort(); - for flag in isa.enabled_isa_flags() { - println!(" - {}", flag); + for flag in enabled { + println!(" {}", flag); } } Ok(()) } - fn print_settings(header: &str, settings: impl IntoIterator, width: usize) { + fn print_settings(header: &str, settings: &[Setting], width: usize) { println!("{}", header); for setting in settings { println!(