@@ -160,6 +160,10 @@ pub(super) fn add_version_to_llvm_target(
160160pub ( super ) fn get_sdk_root ( sess : & Session ) -> Option < PathBuf > {
161161 let sdk_name = sdk_name ( & sess. target ) ;
162162
163+ // Attempt to invoke `xcrun` to find the SDK.
164+ //
165+ // Note that when cross-compiling from e.g. Linux, the `xcrun` binary may sometimes be provided
166+ // as a shim by a cross-compilation helper tool. It usually isn't, but we still try nonetheless.
163167 match xcrun_show_sdk_path ( sdk_name, sess. verbose_internals ( ) ) {
164168 Ok ( ( path, stderr) ) => {
165169 // Emit extra stderr, such as if `-verbose` was passed, or if `xcrun` emitted a warning.
@@ -169,7 +173,19 @@ pub(super) fn get_sdk_root(sess: &Session) -> Option<PathBuf> {
169173 Some ( path)
170174 }
171175 Err ( err) => {
172- let mut diag = sess. dcx ( ) . create_err ( err) ;
176+ // Failure to find the SDK is not a hard error, since the user might have specified it
177+ // in a manner unknown to us (moreso if cross-compiling):
178+ // - A compiler driver like `zig cc` which links using an internally bundled SDK.
179+ // - Extra linker arguments (`-Clink-arg=-syslibroot`).
180+ // - A custom linker or custom compiler driver.
181+ //
182+ // Though we still warn, since such cases are uncommon, and it is very hard to debug if
183+ // you do not know the details.
184+ //
185+ // FIXME(madsmtm): Make this a lint, to allow deny warnings to work.
186+ // (Or fix <https://github.com/rust-lang/rust/issues/21204>).
187+ let mut diag = sess. dcx ( ) . create_warn ( err) ;
188+ diag. note ( fluent:: codegen_ssa_xcrun_about) ;
173189
174190 // Recognize common error cases, and give more Rust-specific error messages for those.
175191 if let Some ( developer_dir) = xcode_select_developer_dir ( ) {
@@ -209,6 +225,8 @@ fn xcrun_show_sdk_path(
209225 sdk_name : & ' static str ,
210226 verbose : bool ,
211227) -> Result < ( PathBuf , String ) , XcrunError > {
228+ // Intentionally invoke the `xcrun` in PATH, since e.g. nixpkgs provide an `xcrun` shim, so we
229+ // don't want to require `/usr/bin/xcrun`.
212230 let mut cmd = Command :: new ( "xcrun" ) ;
213231 if verbose {
214232 cmd. arg ( "--verbose" ) ;
@@ -280,7 +298,7 @@ fn stdout_to_path(mut stdout: Vec<u8>) -> PathBuf {
280298 }
281299 #[ cfg( unix) ]
282300 let path = <OsString as std:: os:: unix:: ffi:: OsStringExt >:: from_vec ( stdout) ;
283- #[ cfg( not( unix) ) ] // Unimportant , this is only used on macOS
284- let path = OsString :: from ( String :: from_utf8 ( stdout) . unwrap ( ) ) ;
301+ #[ cfg( not( unix) ) ] // Not so important , this is mostly used on macOS
302+ let path = OsString :: from ( String :: from_utf8 ( stdout) . expect ( "stdout must be UTF-8" ) ) ;
285303 PathBuf :: from ( path)
286304}
0 commit comments