Skip to content

Add target_env = "macabi" and target_env = "sim" #139451

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

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Apr 6, 2025

RFC 2992 (tracking issue) introduced cfg(target_abi = ...) with the original motivation being Mac Catalyst and Apple Simulator targets. These do not actually have a changed calling convention in the same sense that e.g. cfg(target_abi = "eabihf") or pointer authentication (arm64e) does, see #133331.

Specifically, for Apple Simulator targets, the binary runs under the following conditions:

  • Runs with the host macOS kernel (but in a mode configured for iOS/tvOS/...).
  • Uses frameworks for the specific simulator version being targetted.
  • System file accesses need to be made relative to the IPHONE_SIMULATOR_ROOT environment variable.
  • Uses host GPUs directly.

And for Mac Catalyst:

  • Runs with the host macOS kernel (but in a mode configured for iOS).
  • Uses mostly host macOS frameworks (though with a few things changed, e.g. the NSImageResizingModeStretch enum has a different value).
  • Uses host GPUs, camera and other peripherals directly.

As can be seen, these seem better suited as target_envs, since it really is the environment that the binary is running under that's changed (regardless of the Mac Catalyst "macabi" having "abi" in the name). So this PR adds target_env = "sim" and target_env = "macabi", with the idea of possibly deprecating target_abi = "sim" and target_abi = "macabi" in the far future.

This is affects iOS Tier 2 targets (aarch64-apple-ios-sim, x86_64-apple-ios, aarch64-apple-ios-macabi and x86_64-apple-ios-macabi), and probably needs a compiler FCP.

Fixes #133331.
Reference PR: rust-lang/reference#1781.
Cargo doc PR: rust-lang/cargo#15404.

r? compiler
CC @workingjubilee
CC target maintainers @deg4uss3r @thomcc @badboy @BlackHoleFox @madsmtm @agg23

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 6, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 6, 2025

These commits modify compiler targets.
(See the Target Tier Policy.)

Some changes occurred in src/doc/rustc/src/platform-support

cc @Noratrieb

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@madsmtm madsmtm force-pushed the apple-target-env-abi branch from b42ca5f to 0245efb Compare April 6, 2025 14:29
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@madsmtm madsmtm force-pushed the apple-target-env-abi branch from 8a2104f to 8ab20f3 Compare April 6, 2025 15:41
@madsmtm madsmtm force-pushed the apple-target-env-abi branch from 8ab20f3 to bb4d1b1 Compare April 6, 2025 23:43
github-merge-queue bot pushed a commit to rust-lang/cargo that referenced this pull request Apr 6, 2025
`target_abi = "sim"` may be deprecated in the future. See
rust-lang/rust#139451.
Copy link
Member

@SparrowLii SparrowLii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks fine, but I'm not familar with target options so
r? @workingjubilee since this is from #133331

@rustbot rustbot assigned workingjubilee and unassigned SparrowLii Apr 7, 2025
@workingjubilee
Copy link
Member

workingjubilee commented Apr 8, 2025

Hm. Reviewing https://github.com/rust-lang/rust-forge/blob/master/src/compiler/proposals-and-stabilization.md#targets this is an unspecified case for approving changes to targets, cc @davidtwco and @wesleywiser

But it is user-facing, I suppose, so an FCP does make sense. Tentatively applying labels assuming that is correct.

@workingjubilee workingjubilee added I-compiler-nominated Nominated for discussion during a compiler team meeting. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. and removed T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Apr 8, 2025
@apiraino
Copy link
Contributor

apiraino commented Apr 10, 2025

I'm also not very familiar with target options but I feel that target_env = "sim" is a bit generic. Would it make sense something that says more explicitly that this is an Apple thing? Example target_env = "ios-sim" or something along this line?

@wesleywiser
Copy link
Member

Yes, I think an FCP is appropriate for this change.

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Apr 10, 2025

Team member @wesleywiser has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Apr 10, 2025
@wesleywiser wesleywiser removed the I-compiler-nominated Nominated for discussion during a compiler team meeting. label Apr 10, 2025
@madsmtm
Copy link
Contributor Author

madsmtm commented Apr 10, 2025

I'm also not very familiar with target options but I feel that target_env = "sim" is a bit generic. Would it make sense something that says more explicitly that this is an Apple thing? Example target_env = "ios-sim" or something along this line?

I'm very against other naming here, reasoning outlined in rust-lang/compiler-team#850.

@workingjubilee
Copy link
Member

We already have the "the same cfg name can be present for two targets" problem, unfortunately, due to target_feature.

Rust CURRENT_RUSTC_VERSION).

```rust
if cfg!(target_env = "sim") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we recommend something like cfg!(all(target_vendor = "apple", target_env = "sim")) here to avoid overlap bugs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps? Or maybe the example should be:

#![cfg(target_vendor = "apple")]

if cfg!(target_env = "sim") {
    // ...
}

As I expect that kind of pattern to be the most common (e.g. you need to differentiate the simulator while you're already in the context of iOS / Apple).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if the module cfg makes sense; I've seen uses where in the simulator might just need a branch skipped, or a different branch taken, but the same block of code is being ran for multiple OSes instead of just Apple ones so you see this pattern:

if cfg!(all(target_vendor = "apple", target_env = "sim")) {
    // Do easier, simulator specific thing that still has cross-platform abstraction
    ...
} {
    // Everything else, like Windows and non-simulator iOS via cross-platform abstraction.
    ...
}

@jieyouxu jieyouxu added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"macabi" is not an "ABI" in the same sense as e.g. "gnueabihf"