@@ -685,8 +685,8 @@ fn link_natively(
685685 codegen_backend : & ' static str ,
686686) {
687687 info ! ( "preparing {:?} to {:?}" , crate_type, out_filename) ;
688- let self_contained_components = self_contained_components ( sess, crate_type ) ;
689- let ( linker_path , flavor ) = linker_and_flavor ( sess, & self_contained_components ) ;
688+ let ( linker_path , flavor ) = linker_and_flavor ( sess) ;
689+ let self_contained_components = self_contained_components ( sess, crate_type , & linker_path ) ;
690690
691691 // On AIX, we ship all libraries as .a big_af archive
692692 // the expected format is lib<name>.a(libname.so) for the actual
@@ -1318,10 +1318,7 @@ pub fn ignored_for_lto(sess: &Session, info: &CrateInfo, cnum: CrateNum) -> bool
13181318}
13191319
13201320/// This functions tries to determine the appropriate linker (and corresponding LinkerFlavor) to use
1321- pub fn linker_and_flavor (
1322- sess : & Session ,
1323- self_contained_components : & LinkSelfContainedComponents ,
1324- ) -> ( PathBuf , LinkerFlavor ) {
1321+ pub fn linker_and_flavor ( sess : & Session ) -> ( PathBuf , LinkerFlavor ) {
13251322 fn infer_from (
13261323 sess : & Session ,
13271324 linker : Option < PathBuf > ,
@@ -1418,18 +1415,6 @@ pub fn linker_and_flavor(
14181415 return ret;
14191416 }
14201417
1421- // When using a supported target in self-contained linker mode, we want to use rust-lld directly.
1422- let self_contained_target = sess. target . os == Os :: Windows
1423- && sess. target . env == Env :: Gnu
1424- && sess. target . abi == Abi :: Llvm
1425- && self_contained_components. is_linker_enabled ( ) ;
1426- if self_contained_target
1427- && let Some ( ret) =
1428- infer_from ( sess, None , Some ( LinkerFlavor :: Gnu ( Cc :: No , Lld :: Yes ) ) , features)
1429- {
1430- return ret;
1431- }
1432-
14331418 if let Some ( ret) = infer_from (
14341419 sess,
14351420 sess. target . linker . as_deref ( ) . map ( PathBuf :: from) ,
@@ -1776,25 +1761,20 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
17761761 }
17771762}
17781763
1779- /// Returns true if linker is shipped by Rust.
1780- // There are currently two different solutions for self-contained mode with mingw-w64:
1781- // using rust-lld directly (`-gnullvm`) or using shipped cc to call the linker (`-gnu`).
1782- // Eventually, `-gnu` toolchains might be moved to calling the linker directly.
1783- fn detect_self_contained_mingw ( sess : & Session ) -> bool {
1784- // Passing explicit linker other than `rust-lld` means non-self-contained mode.
1785- if let Some ( linker) = & sess. opts . cg . linker {
1786- return linker == Path :: new ( "rust-lld" ) ;
1764+ // Returns true if linker is located within sysroot
1765+ fn detect_self_contained_mingw ( sess : & Session , linker : & Path ) -> bool {
1766+ // Assume `-C linker=rust-lld` as self-contained mode
1767+ if linker == Path :: new ( "rust-lld" ) {
1768+ return true ;
17871769 }
1788-
1789- // If no explicit linker was given, proceed with implicit one (if present);
1790- let linker_with_extension = if let Some ( linker) = sess. target . linker . as_deref ( ) . map ( Path :: new) {
1770+ let linker_with_extension = if cfg ! ( windows) && linker. extension ( ) . is_none ( ) {
17911771 linker. with_extension ( "exe" )
17921772 } else {
1793- return false ;
1773+ linker . to_path_buf ( )
17941774 } ;
17951775 for dir in env:: split_paths ( & env:: var_os ( "PATH" ) . unwrap_or_default ( ) ) {
17961776 let full_path = dir. join ( & linker_with_extension) ;
1797- // If linker doesn't come from sysroot assume non- self-contained mode
1777+ // If linker comes from sysroot assume self-contained mode
17981778 if full_path. is_file ( ) && !full_path. starts_with ( sess. opts . sysroot . path ( ) ) {
17991779 return false ;
18001780 }
@@ -1805,7 +1785,11 @@ fn detect_self_contained_mingw(sess: &Session) -> bool {
18051785/// Various toolchain components used during linking are used from rustc distribution
18061786/// instead of being found somewhere on the host system.
18071787/// We only provide such support for a very limited number of targets.
1808- fn self_contained_components ( sess : & Session , crate_type : CrateType ) -> LinkSelfContainedComponents {
1788+ fn self_contained_components (
1789+ sess : & Session ,
1790+ crate_type : CrateType ,
1791+ linker : & Path ,
1792+ ) -> LinkSelfContainedComponents {
18091793 // Turn the backwards compatible bool values for `self_contained` into fully inferred
18101794 // `LinkSelfContainedComponents`.
18111795 let self_contained =
@@ -1834,7 +1818,7 @@ fn self_contained_components(sess: &Session, crate_type: CrateType) -> LinkSelfC
18341818 LinkSelfContainedDefault :: InferredForMingw => {
18351819 sess. host == sess. target
18361820 && sess. target . abi != Abi :: Uwp
1837- && detect_self_contained_mingw ( sess)
1821+ && detect_self_contained_mingw ( sess, linker )
18381822 }
18391823 }
18401824 } ;
0 commit comments