@@ -828,19 +828,40 @@ fn current_install_opts(opts: &InstallOpts<'_>, process: &Process) -> String {
828828
829829#[ cfg( unix) ]
830830fn warn_if_default_linker_missing ( process : & Process ) {
831- // Search for `cc` in PATH
831+ // Search for linker in PATH
832832 if let Some ( path) = process. var_os ( "PATH" ) {
833- let cc_binary = format ! ( "cc{}" , EXE_SUFFIX ) ;
834-
833+ // If we have the host triple, attempt to determine the CC/linker path that
834+ // `cc-rs` would use, as this is *usually* why we need a linker to invoke.
835+ //
836+ // Doing it this way allows us to correctly diagnose quirky systems like
837+ // solaris and illumos that use `gcc` rather than `cc` for historical reasons.
838+ let cc_binary_opt = TargetTriple :: from_host ( process) . and_then ( |triple| {
839+ // Fill in some dummy settings for `Build`/`Tool` to be able to properly
840+ // give us the metadata we want
841+ cc:: Build :: new ( )
842+ . opt_level ( 0 )
843+ . target ( & triple)
844+ . host ( & triple)
845+ . try_get_compiler ( )
846+ . ok ( )
847+ . and_then ( |tool| tool. path ( ) . to_str ( ) . map ( str:: to_string) )
848+ } ) ;
849+
850+ // If we don't get info from cc-rs, fall back to just looking for the literal `cc`.
851+ let cc_binary = cc_binary_opt. unwrap_or_else ( || format ! ( "cc{}" , EXE_SUFFIX ) ) ;
852+
853+ // Search the path for the selected binary
835854 for mut p in env:: split_paths ( & path) {
836855 p. push ( & cc_binary) ;
837856 if p. is_file ( ) {
838857 return ;
839858 }
840859 }
860+
861+ warn ! ( "no default linker (`{cc_binary}`) was found in your PATH" ) ;
841862 }
842863
843- warn ! ( "no default linker (`cc`) was found in your PATH " ) ;
864+ warn ! ( "unable to search PATH for a default linker " ) ;
844865 warn ! ( "many Rust crates require a system C toolchain to build" ) ;
845866}
846867
0 commit comments