@@ -88,6 +88,9 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
8888}
8989
9090pub fn find ( build : & mut Build ) {
91+ let host_target = build. build ;
92+ let default_cc = new_cc_build ( build, host_target) . get_compiler ( ) ;
93+
9194 // For all targets we're going to need a C compiler for building some shims
9295 // and such as well as for being a linker for Rust code.
9396 let targets = build
@@ -107,6 +110,34 @@ pub fn find(build: &mut Build) {
107110 }
108111
109112 let compiler = cfg. get_compiler ( ) ;
113+ if target != host_target
114+ && !compiler. is_like_clang ( )
115+ && compiler. path ( ) == default_cc. path ( )
116+ {
117+ // See https://github.com/rust-lang/rust/issues/111142 for why this was added.
118+
119+ let underscore_target = target. triple . replace ( '-' , "_" ) ;
120+ eprintln ! (
121+ "Error: the automatic detection of the C compiler for target {target} \
122+ returned the same compiler as the currnet host target:"
123+ ) ;
124+ eprintln ! (
125+ "This is likely wrong. Please specify the correct compiler for that target, \
126+ either with environment variables:"
127+ ) ;
128+ eprintln ! ( ) ;
129+ eprintln ! ( " CC_{underscore_target}=path/to/target" ) ;
130+ eprintln ! ( " CXX_{underscore_target}=path/to/target" ) ;
131+ eprintln ! ( ) ;
132+ eprintln ! ( "...or in config.toml:" ) ;
133+ eprintln ! ( ) ;
134+ eprintln ! ( " [target.\" {target}\" ]" ) ;
135+ eprintln ! ( " cc = \" path/to/target\" " ) ;
136+ eprintln ! ( " cxx = \" path/to/target\" " ) ;
137+ eprintln ! ( ) ;
138+ crate :: detail_exit ( 1 ) ;
139+ }
140+
110141 let ar = if let ar @ Some ( ..) = config. and_then ( |c| c. ar . clone ( ) ) {
111142 ar
112143 } else {
0 commit comments