Skip to content

Commit 29785a5

Browse files
cachebagrami3l
authored andcommitted
feat(install): warn if default linker (cc) is missing; add respective test case
1 parent 6dd9f5d commit 29785a5

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/cli/self_update.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ pub(crate) async fn install(
610610
};
611611
md(&mut term, msg);
612612

613+
#[cfg(unix)]
614+
warn_if_default_linker_missing(process);
615+
613616
#[cfg(windows)]
614617
if !no_prompt {
615618
// On windows, where installation happens in a console
@@ -742,6 +745,24 @@ fn current_install_opts(opts: &InstallOpts<'_>, process: &Process) -> String {
742745
)
743746
}
744747

748+
#[cfg(unix)]
749+
fn warn_if_default_linker_missing(process: &Process) {
750+
// Search for `cc` in PATH
751+
if let Some(path) = process.var_os("PATH") {
752+
let cc_binary = format!("cc{}", env::consts::EXE_SUFFIX);
753+
754+
for mut p in env::split_paths(&path) {
755+
p.push(&cc_binary);
756+
if p.is_file() {
757+
return;
758+
}
759+
}
760+
}
761+
762+
warn!("no default linker (`cc`) was found in your PATH");
763+
warn!("many Rust crates require a system C toolchain to build");
764+
}
765+
745766
fn install_bins(process: &Process) -> Result<()> {
746767
let bin_path = process.cargo_home()?.join("bin");
747768
let this_exe_path = utils::current_exe()?;

tests/suite/cli_inst_interactive.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,29 @@ warn: It looks like you have an existing rustup settings file at:
626626
...
627627
"#]]);
628628
}
629+
630+
#[cfg(unix)]
631+
#[tokio::test]
632+
async fn install_warns_if_default_linker_missing() {
633+
// Fake PATH pointing to an empty directory so `cc` cannot be found
634+
let temp_dir = tempfile::Builder::new()
635+
.prefix("emptybin")
636+
.tempdir()
637+
.unwrap();
638+
let temp_dir_path = temp_dir.path().to_str().unwrap();
639+
640+
let cx = CliTestContext::new(Scenario::SimpleV2).await;
641+
cx.config
642+
.expect_with_env(
643+
["rustup-init", "-y", "--no-modify-path"],
644+
[("PATH", temp_dir_path)], // override PATH to hide system `cc`
645+
)
646+
.await
647+
.is_ok()
648+
.with_stderr(snapbox::str![[r#"
649+
...
650+
warn: no default linker (`cc`) was found in your PATH
651+
warn: many Rust crates require a system C toolchain to build
652+
...
653+
"#]]);
654+
}

0 commit comments

Comments
 (0)