diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index a4b1f60cd11..44172ae31c5 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -120,8 +120,8 @@ pub fn build_app() -> Command { let flag_prebuilt = Arg::new(FLAG_PREBUILT) .long(FLAG_PREBUILT) - .help("Assume the platform has been prebuilt and skip rebuilding the platform\n(This is enabled by default when using `roc build` with a --target other than `--target `.)") - .value_parser(["true", "false"]) + .help("Assume the platform has been prebuilt and skip rebuilding the platform\n(This is enabled implicitly when using `roc build` with a --target other than `--target `, unless the target is wasm.)") + .action(ArgAction::SetTrue) .required(false); let flag_wasm_stack_size_kb = Arg::new(FLAG_WASM_STACK_SIZE_KB) @@ -648,13 +648,16 @@ pub fn build( LinkingStrategy::Surgical }; - let prebuilt = if matches.contains_id(FLAG_PREBUILT) { - matches.get_one::(FLAG_PREBUILT).map(|s| s.as_str()) == Some("true") - } else { - // When compiling for a different target, default to assuming a prebuilt platform. - // Otherwise compilation would most likely fail because many toolchains assume you're compiling for the current machine. - // We make an exception for Wasm, because cross-compiling is the norm in that case. - triple != Triple::host() && !matches!(triple.architecture, Architecture::Wasm32) + let prebuilt = { + let cross_compile = triple != Triple::host(); + let targeting_wasm = matches!(triple.architecture, Architecture::Wasm32); + + matches.get_flag(FLAG_PREBUILT) || + // When compiling for a different target, assume a prebuilt platform. + // Otherwise compilation would most likely fail because many toolchains + // assume you're compiling for the current machine. We make an exception + // for Wasm, because cross-compiling is the norm in that case. + (cross_compile && !targeting_wasm) }; let wasm_dev_stack_bytes: Option = matches diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index f7b798fff60..e7b4472afc0 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -51,7 +51,7 @@ mod cli_run { const OPTIMIZE_FLAG: &str = concatcp!("--", roc_cli::FLAG_OPTIMIZE); const LINKER_FLAG: &str = concatcp!("--", roc_cli::FLAG_LINKER); const CHECK_FLAG: &str = concatcp!("--", roc_cli::FLAG_CHECK); - const PREBUILT_PLATFORM: &str = concatcp!("--", roc_cli::FLAG_PREBUILT, "=true"); + const PREBUILT_PLATFORM: &str = concatcp!("--", roc_cli::FLAG_PREBUILT); #[allow(dead_code)] const TARGET_FLAG: &str = concatcp!("--", roc_cli::FLAG_TARGET);