diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index 3ca070acc9de5..40de69e2b5d32 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -404,6 +404,23 @@ codegen_ssa_visual_studio_not_installed = you may need to install Visual Studio codegen_ssa_xcrun_command_line_tools_insufficient = when compiling for iOS, tvOS, visionOS or watchOS, you need a full installation of Xcode +codegen_ssa_xcrun_cross_download_sdk = + the SDK can be downloaded and extracted from https://developer.apple.com/download/all/?q=xcode (requires an Apple ID). + + The full Xcode bundle should contain the SDK in Xcode.app/Contents/Developer/Platforms/{$sdk_name}.platform/Developer/SDKs/{$sdk_name}.sdk{ $sdk_name -> + [MacOSX] , but downloading just the "Command Line Tools for Xcode" should also be sufficient to obtain the macOS SDK. + *[other] . + } + +codegen_ssa_xcrun_cross_env_var = + pass the path to the SDK using the SDKROOT environment variable + +codegen_ssa_xcrun_cross_ill_supported_target = + cross-compiling to iOS, tvOS, visionOS or watchOS (in particular the linking step) is ill supported on non-macOS hosts + +codegen_ssa_xcrun_cross_linker_not_explicitly_set = + you will also need to use a linker capable of linking Mach-O files, consider using the bundled `lld` with `-Clinker=rust-lld` + codegen_ssa_xcrun_failed_invoking = invoking `{$command_formatted}` to find {$sdk_name}.sdk failed: {$error} codegen_ssa_xcrun_found_developer_dir = found active developer directory at "{$developer_dir}" diff --git a/compiler/rustc_codegen_ssa/src/back/apple.rs b/compiler/rustc_codegen_ssa/src/back/apple.rs index 2f68bad1695b5..811dbed2e1e98 100644 --- a/compiler/rustc_codegen_ssa/src/back/apple.rs +++ b/compiler/rustc_codegen_ssa/src/back/apple.rs @@ -172,16 +172,29 @@ pub(super) fn get_sdk_root(sess: &Session) -> Option { let mut diag = sess.dcx().create_err(err); // Recognize common error cases, and give more Rust-specific error messages for those. - if let Some(developer_dir) = xcode_select_developer_dir() { - diag.arg("developer_dir", &developer_dir); - diag.note(fluent::codegen_ssa_xcrun_found_developer_dir); - if developer_dir.as_os_str().to_string_lossy().contains("CommandLineTools") { - if sdk_name != "MacOSX" { - diag.help(fluent::codegen_ssa_xcrun_command_line_tools_insufficient); + if sess.host.os == "macos" { + if let Some(developer_dir) = xcode_select_developer_dir() { + diag.arg("developer_dir", &developer_dir); + diag.note(fluent::codegen_ssa_xcrun_found_developer_dir); + if developer_dir.as_os_str().to_string_lossy().contains("CommandLineTools") { + if sdk_name != "MacOSX" { + diag.help(fluent::codegen_ssa_xcrun_command_line_tools_insufficient); + } } + } else { + diag.help(fluent::codegen_ssa_xcrun_no_developer_dir); } } else { - diag.help(fluent::codegen_ssa_xcrun_no_developer_dir); + diag.help(fluent::codegen_ssa_xcrun_cross_env_var); + diag.help(fluent::codegen_ssa_xcrun_cross_download_sdk); + + if sess.opts.cg.linker.is_none() { + diag.warn(fluent::codegen_ssa_xcrun_cross_linker_not_explicitly_set); + } + + if sess.target.os != "macos" { + diag.warn(fluent::codegen_ssa_xcrun_cross_ill_supported_target); + } } diag.emit();