Skip to content
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

WIP: Parse Apple SDK versions #131478

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3478,6 +3478,7 @@ dependencies = [
"rustc_target",
"rustc_trait_selection",
"rustc_type_ir",
"serde",
"serde_json",
"smallvec",
"tempfile",
Expand Down Expand Up @@ -4450,6 +4451,7 @@ dependencies = [
"rustc_macros",
"rustc_serialize",
"rustc_span",
"serde",
"serde_json",
"tracing",
]
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use std::sync::Arc;
use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::settings::{self, Configurable};
use rustc_codegen_ssa::CodegenResults;
use rustc_codegen_ssa::apple::versioned_llvm_target;
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_errors::ErrorGuaranteed;
Expand Down Expand Up @@ -259,7 +260,9 @@ impl CodegenBackend for CraneliftCodegenBackend {
}

fn target_triple(sess: &Session) -> target_lexicon::Triple {
match sess.target.llvm_target.parse() {
// FIXME(madsmtm): Use `sess.target.llvm_target` once target-lexicon supports unversioned macOS.
// See <https://github.com/bytecodealliance/target-lexicon/pull/113>
match versioned_llvm_target(sess).parse() {
Ok(triple) => triple,
Err(err) => sess.dcx().fatal(format!("target not recognized: {}", err)),
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use libc::{c_char, c_int, c_void, size_t};
use llvm::{
LLVMRustLLVMHasZlibCompressionForDebugSymbols, LLVMRustLLVMHasZstdCompressionForDebugSymbols,
};
use rustc_codegen_ssa::apple::versioned_llvm_target;
use rustc_codegen_ssa::back::link::ensure_removed;
use rustc_codegen_ssa::back::write::{
BitcodeSection, CodegenContext, EmitObj, ModuleConfig, TargetMachineFactoryConfig,
Expand Down Expand Up @@ -210,7 +211,7 @@ pub(crate) fn target_machine_factory(
singlethread = false;
}

let triple = SmallCStr::new(&sess.target.llvm_target);
let triple = SmallCStr::new(&versioned_llvm_target(sess));
let cpu = SmallCStr::new(llvm_util::target_cpu(sess));
let features = CString::new(target_features.join(",")).unwrap();
let abi = SmallCStr::new(&sess.target.llvm_abiname);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::cell::{Cell, RefCell};
use std::ffi::{CStr, c_uint};
use std::str;

use rustc_codegen_ssa::apple::versioned_llvm_target;
use rustc_codegen_ssa::base::{wants_msvc_seh, wants_wasm_eh};
use rustc_codegen_ssa::errors as ssa_errors;
use rustc_codegen_ssa::traits::*;
Expand Down Expand Up @@ -165,7 +166,7 @@ pub(crate) unsafe fn create_module<'ll>(
llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
}

let llvm_target = SmallCStr::new(&sess.target.llvm_target);
let llvm_target = SmallCStr::new(&versioned_llvm_target(sess));
unsafe {
llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_type_ir = { path = "../rustc_type_ir" }
serde_json = "1.0.59"
serde = { version = "1", features = [ "derive" ]}
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tempfile = "3.2"
thin-vec = "0.2.12"
Expand Down
113 changes: 110 additions & 3 deletions compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,116 @@ codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not imp

codegen_ssa_add_native_library = failed to add native library {$library_path}: {$error}

codegen_ssa_apple_sdk_error_sdk_path = failed to get {$sdk_name} SDK path: {$error}
codegen_ssa_apple_deployment_target_invalid =
failed to parse deployment target specified in {$env_var}: {$error}

codegen_ssa_apple_deployment_target_too_low =
deployment target in {$env_var} was set to {$version}, but the minimum supported by `rustc` is {$os_min}

codegen_ssa_apple_deployment_target_too_high =
deployment target was set to {$version}, but the maximum supported by the current SDK is {$sdk_max}

Use the {$env_var} environment variable to set it to something lower.

codegen_ssa_apple_sdk_error_failed_reading =
failed reading `{$path}` while looking for SDK root: {$error}

codegen_ssa_apple_sdk_error_invalid_sdk_settings_json =
failed parsing SDK settings from `{$path}`: {$error}

codegen_ssa_apple_sdk_error_missing =
failed finding SDK for platform `{$sdk_name}`. It looks like you have not installed Xcode?

You should install Xcode via the App Store, or run `xcode-select --install` if you only intend on developing for macOS.

codegen_ssa_apple_sdk_error_missing_commandline_tools =
failed finding SDK at `{$sdkroot}` from Command Line Tools installation.

If cross-compiling for iOS, tvOS, visionOS or watchOS, you will likely need a full installation of Xcode.

codegen_ssa_apple_sdk_error_missing_cross_compile_non_macos =
failed finding Apple SDK with name `{$sdk_name}`.

The SDK is needed by the linker to know where to find symbols in system libraries.

The SDK can be downloaded and extracted from https://developer.apple.com/download/all/?q=xcode (requires an Apple ID).

You will then need to tell `rustc` about it using the `SDKROOT` environment variables.

Furthermore, you might need to install a linker capable of linking Mach-O files, or at least ensure that your linker is configured as `lld`.

codegen_ssa_apple_sdk_error_missing_developer_dir =
failed finding SDK inside active developer path `{$dir}` set by the DEVELOPER_DIR environment variable. Looked in:
- `{$sdkroot}`
- `{$sdkroot_bare}`

codegen_ssa_apple_sdk_error_missing_mac_catalyst_version =
failed to find {$version} in SDK version map key `macOS_iOSMac`.

This is probably a bug in your SDK.

codegen_ssa_apple_sdk_error_missing_sdk_settings =
failed finding `SDKSettings.json` or `SDKSettings.plist` in `{$sdkroot}`.

Are you sure this is a valid SDK?

codegen_ssa_apple_sdk_error_missing_xcode =
failed finding SDK at `{$sdkroot}` in Xcode installation.

Perhaps you need a newer version of Xcode?

codegen_ssa_apple_sdk_error_missing_xcode_select =
failed finding SDK inside active developer path `{$dir}` set by `xcode-select`. Looked in:
- `{$sdkroot}`
- `{$sdkroot_bare}`

Consider using `sudo xcode-select --switch path/to/Xcode.app` or `sudo xcode-select --reset` to select a valid path.

codegen_ssa_apple_sdk_error_must_have_when_using_ld64 =
must know the SDK when linking with ld64

codegen_ssa_apple_sdk_error_not_sdk_path =
failed parsing SDK at `{$path}`.

The SDK did not seem to contain `SDKSettings.json`, and hence `rustc` falled back to parsing required SDK details from the SDK name itself.

This name must be of the form `[SDKName][major].[minor].[patch].sdk`, for example `MacOSX10.13.sdk` or `iPhoneOS11.0.sdk`.

codegen_ssa_apple_sdk_error_sdk_does_not_support_arch =
the SDK at `{$sdkroot}` does not support the {$arch} architecture.

codegen_ssa_apple_sdk_error_sdk_does_not_support_os =
the SDK at `{$sdkroot}` does not support { $abi ->
[macabi] Mac Catalyst
[sim] the {$os} simulator
*[normal] {$os}
}.

Use `xcode-select --switch` or one of the `SDKROOT` and `DEVELOPER_DIR` environment variables to select { $abi ->
[macabi] a newer version of Xcode that has support for it
*[others] another SDK that has support for it
}.

{ $abi ->
[macabi] Also remember that it is the macOS SDK that supports Mac Catalyst, not the iOS SDK.
*[others] {""}
}

codegen_ssa_apple_sdk_error_sdk_root_ignored =
the SDKROOT environment variable has been ignored, and `rustc` will attempt to find a suitable SDK

codegen_ssa_apple_sdk_error_sdk_root_is_root_path =
the path SDKROOT was set to the root path `/`.

This will work poorly with other tooling, and as such the value has been ignored.

codegen_ssa_apple_sdk_error_sdk_root_missing =
the path `{$sdkroot}` specified in SDKROOT did not exist, so it has been ignored

codegen_ssa_apple_sdk_error_sdk_root_not_absolute =
the path `{$sdkroot}` specified in SDKROOT was not an absolute path.

This will work poorly with other tooling, and as such the value has been ignored.

codegen_ssa_archive_build_failure = failed to build archive at `{$path}`: {$error}

Expand Down Expand Up @@ -337,8 +446,6 @@ codegen_ssa_unknown_atomic_ordering = unknown ordering in atomic intrinsic

codegen_ssa_unknown_reuse_kind = unknown cgu-reuse-kind `{$kind}` specified

codegen_ssa_unsupported_arch = unsupported arch `{$arch}` for os `{$os}`

codegen_ssa_unsupported_link_self_contained = option `-C link-self-contained` is not supported on this target

codegen_ssa_use_cargo_directive = use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)
Expand Down
Loading
Loading