@@ -160,6 +160,10 @@ pub(super) fn add_version_to_llvm_target(
160
160
pub ( super ) fn get_sdk_root ( sess : & Session ) -> Option < PathBuf > {
161
161
let sdk_name = sdk_name ( & sess. target ) ;
162
162
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.
163
167
match xcrun_show_sdk_path ( sdk_name, sess. verbose_internals ( ) ) {
164
168
Ok ( ( path, stderr) ) => {
165
169
// 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> {
169
173
Some ( path)
170
174
}
171
175
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) ;
173
189
174
190
// Recognize common error cases, and give more Rust-specific error messages for those.
175
191
if let Some ( developer_dir) = xcode_select_developer_dir ( ) {
@@ -209,6 +225,8 @@ fn xcrun_show_sdk_path(
209
225
sdk_name : & ' static str ,
210
226
verbose : bool ,
211
227
) -> 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`.
212
230
let mut cmd = Command :: new ( "xcrun" ) ;
213
231
if verbose {
214
232
cmd. arg ( "--verbose" ) ;
@@ -280,7 +298,7 @@ fn stdout_to_path(mut stdout: Vec<u8>) -> PathBuf {
280
298
}
281
299
#[ cfg( unix) ]
282
300
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" ) ) ;
285
303
PathBuf :: from ( path)
286
304
}
0 commit comments