Skip to content

Provide cross-compiling guidance when Apple SDK is missing #139053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
27 changes: 20 additions & 7 deletions compiler/rustc_codegen_ssa/src/back/apple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,29 @@ pub(super) fn get_sdk_root(sess: &Session) -> Option<PathBuf> {
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();
Expand Down
Loading