Skip to content

Commit 97632ad

Browse files
committed
Parse SDK settings
Previously, we did a simplistic check against the SDKROOT path to try to figure out whether we should use the environment variable, or try to find a better matching SDK instead. This is brittle since the user might want their SDK to be in a different place in the file system (that's kinda the whole idea of the SDKROOT variable), and also didn't work properly with SDKs in the Xcode Command Line Tools. Instead, we now: 1. Parse the SDKSettings.json file under the SDKROOT, to determine whether it is suitable for the target we're compiling for (which it might not be when using Cargo, and targetting iOS but compiling build scripts on macOS). 2. If it's not, attempt to find another SDK. This allows us to give much more detailed error messages, to better support cross-compile scenarios, and allows using parameters from the SDK (such as the SDK version) elsewhere in the future.
1 parent 05457b9 commit 97632ad

16 files changed

+1792
-64
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3478,6 +3478,7 @@ dependencies = [
34783478
"rustc_target",
34793479
"rustc_trait_selection",
34803480
"rustc_type_ir",
3481+
"serde",
34813482
"serde_json",
34823483
"smallvec",
34833484
"tempfile",

compiler/rustc_codegen_ssa/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ rustc_target = { path = "../rustc_target" }
3737
rustc_trait_selection = { path = "../rustc_trait_selection" }
3838
rustc_type_ir = { path = "../rustc_type_ir" }
3939
serde_json = "1.0.59"
40+
serde = { version = "1", features = [ "derive" ]}
4041
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
4142
tempfile = "3.2"
4243
thin-vec = "0.2.12"

compiler/rustc_codegen_ssa/messages.ftl

+56
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ codegen_ssa_apple_deployment_target_invalid =
88
codegen_ssa_apple_deployment_target_too_low =
99
deployment target in {$env_var} was set to {$version}, but the minimum supported by `rustc` is {$os_min}
1010
11+
codegen_ssa_apple_deployment_target_too_high =
12+
deployment target was set to {$version}, but the maximum supported by the current SDK is {$sdk_max}
13+
14+
Use the {$env_var} environment variable to set it to something lower.
15+
1116
codegen_ssa_apple_sdk_error_failed_reading =
1217
failed reading `{$path}` while looking for SDK root: {$error}
1318
19+
codegen_ssa_apple_sdk_error_invalid_sdk_settings_json =
20+
failed parsing SDK settings from `{$path}`: {$error}
21+
1422
codegen_ssa_apple_sdk_error_missing =
1523
failed finding SDK for platform `{$sdk_name}`. It looks like you have not installed Xcode?
1624
@@ -37,6 +45,11 @@ codegen_ssa_apple_sdk_error_missing_developer_dir =
3745
- `{$sdkroot}`
3846
- `{$sdkroot_bare}`
3947
48+
codegen_ssa_apple_sdk_error_missing_sdk_settings =
49+
failed finding `SDKSettings.json` or `SDKSettings.plist` in `{$sdkroot}`.
50+
51+
Are you sure this is a valid SDK?
52+
4053
codegen_ssa_apple_sdk_error_missing_xcode =
4154
failed finding SDK at `{$sdkroot}` in Xcode installation.
4255
@@ -49,6 +62,49 @@ codegen_ssa_apple_sdk_error_missing_xcode_select =
4962
5063
Consider using `sudo xcode-select --switch path/to/Xcode.app` or `sudo xcode-select --reset` to select a valid path.
5164
65+
codegen_ssa_apple_sdk_error_not_sdk_path =
66+
failed parsing SDK at `{$path}`.
67+
68+
The SDK did not seem to contain `SDKSettings.json`, and hence `rustc` falled back to parsing required SDK details from the SDK name itself.
69+
70+
This name must be of the form `[SDKName][major].[minor].[patch].sdk`, for example `MacOSX10.13.sdk` or `iPhoneOS11.0.sdk`.
71+
72+
codegen_ssa_apple_sdk_error_sdk_does_not_support_arch =
73+
the SDK at `{$sdkroot}` does not support the {$arch} architecture.
74+
75+
codegen_ssa_apple_sdk_error_sdk_does_not_support_os =
76+
the SDK at `{$sdkroot}` does not support { $abi ->
77+
[macabi] Mac Catalyst
78+
[sim] the {$os} simulator
79+
*[normal] {$os}
80+
}.
81+
82+
Use `xcode-select --switch` or one of the `SDKROOT` and `DEVELOPER_DIR` environment variables to select { $abi ->
83+
[macabi] a newer version of Xcode that has support for it
84+
*[others] another SDK that has support for it
85+
}.
86+
87+
{ $abi ->
88+
[macabi] Also remember that it is the macOS SDK that supports Mac Catalyst, not the iOS SDK.
89+
*[others] {""}
90+
}
91+
92+
codegen_ssa_apple_sdk_error_sdk_root_ignored =
93+
the SDKROOT environment variable has been ignored, and `rustc` will attempt to find a suitable SDK
94+
95+
codegen_ssa_apple_sdk_error_sdk_root_is_root_path =
96+
the path SDKROOT was set to the root path `/`.
97+
98+
This will work poorly with other tooling, and as such the value has been ignored.
99+
100+
codegen_ssa_apple_sdk_error_sdk_root_missing =
101+
the path `{$sdkroot}` specified in SDKROOT did not exist, so it has been ignored
102+
103+
codegen_ssa_apple_sdk_error_sdk_root_not_absolute =
104+
the path `{$sdkroot}` specified in SDKROOT was not an absolute path.
105+
106+
This will work poorly with other tooling, and as such the value has been ignored.
107+
52108
codegen_ssa_archive_build_failure = failed to build archive at `{$path}`: {$error}
53109
54110
codegen_ssa_atomic_compare_exchange = Atomic compare-exchange intrinsic missing failure memory ordering

0 commit comments

Comments
 (0)