diff --git a/crates/compiler/build/src/link.rs b/crates/compiler/build/src/link.rs index 2cf46f530c..05cff98f77 100644 --- a/crates/compiler/build/src/link.rs +++ b/crates/compiler/build/src/link.rs @@ -3,8 +3,8 @@ use libloading::{Error, Library}; use roc_builtins::bitcode; use roc_error_macros::internal_error; use roc_mono::ir::OptLevel; -use roc_utils::get_lib_path; use roc_utils::{cargo, clang, zig}; +use roc_utils::{get_lib_path, rustup}; use std::collections::HashMap; use std::env; use std::io; @@ -632,11 +632,11 @@ pub fn rebuild_host( }, ); - let mut cargo_cmd = cargo(); + let mut cargo_cmd = if cfg!(windows) { rustup() } else { cargo() }; if cfg!(windows) { // on windows, we need the `+nightly` toolchain so we can use `-Z export-executable-symbols` - cargo_cmd.arg("+nightly"); + cargo_cmd.args(["run", "nightly", "cargo"]); } cargo_cmd.arg("build").current_dir(cargo_dir); diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index d3ade29a14..ec071be226 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -127,9 +127,6 @@ pub fn get_lib_path() -> Option { /// Also makes it easy to track where we use cargo in the codebase. pub fn cargo() -> Command { let command_str = if cfg!(windows) { - // on windows, we need the version of cargo installed by rustup. The meaning of `cargo` is - // different within a process that runs rust. So we need to explicitly refer to where - // rustup put the binary r"%HOMEPATH%\.cargo\bin\cargo.exe" } else { "cargo" @@ -142,6 +139,21 @@ pub fn cargo() -> Command { } } +/// Gives a friendly error if cargo is not installed. +/// Also makes it easy to track where we use cargo in the codebase. +pub fn rustup() -> Command { + // on windows, we need the version of cargo installed by rustup. The meaning of `cargo` is + // different within a process that runs rust. So we need to explicitly refer to where + // rustup put the binary + let command_str = "rustup"; + + if check_command_available(command_str) { + Command::new(command_str) + } else { + panic!("I could not find the rustup command.\nVisit https://rustup.rs/ to install cargo.",) + } +} + /// Gives a friendly error if clang is not installed. /// Also makes it easy to track where we use clang in the codebase. pub fn clang() -> Command {