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

Use target_vendor = "apple" instead of target_os = "..." #124491

Merged
merged 6 commits into from May 1, 2024

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Apr 28, 2024

Use target_vendor = "apple" instead of all(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos").

The apple targets are quite close to being identical, with iOS, tvOS, watchOS and visionOS being even closer, so using target_vendor when possible makes it clearer when something is actually OS-specific, or just Apple-specific.
Note that target_vendor will be deprecated in the future, but not before an alternative (like target_family = "apple") is available.

While doing this, I found various inconsistencies and small mistakes in the standard library, see the commits for details. Will follow-up with an extra PR for a similar issue that need a bit more discussion. EDIT: #124494

Since you've talked about using target_vendor = "apple" in the past:
r? workingjubilee

CC @simlay, @thomcc
@rustbot label O-macos O-ios O-tvos O-watchos O-visionos

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc O-unix Operating system: Unix-like 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-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 28, 2024
@rustbot
Copy link
Collaborator

rustbot commented Apr 28, 2024

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@rustbot rustbot added O-ios Operating system: iOS O-macos Operating system: macOS O-tvos Operating system: tvOS (including simulator) O-visionos Apple visionOS O-watchos Operating System: watchOS labels Apr 28, 2024
`man posix_spawn` documents it to be able to return `ENOENT`, and there
should be nothing preventing this. Tested in the iOS simulator and on
Mac Catalyst.
@QuentinPerez
Copy link

Is target_vendor deprecated ? see rust-lang/lang-team#102

@madsmtm
Copy link
Contributor Author

madsmtm commented Apr 28, 2024

Is target_vendor deprecated ? see rust-lang/lang-team#102

It isn't yet, I linked the tracking issue in the PR description, it's here, we expect an alternative like target_family = "apple" to be available before it is though, once that does happen it should be easy to find/replace target_vendor = "apple" with that.

@workingjubilee
Copy link
Contributor

...honestly I had a suspicion that this might uncover some bugs but this is impressive.

@workingjubilee
Copy link
Contributor

@madsmtm So, I can r+ this without knowing the answer to this question, but for full transparency: Do the Rust stdlib tests pass on the simulators? Are there any current gaps? It would be good to know what the "current situation" seems to be.

@madsmtm
Copy link
Contributor Author

madsmtm commented Apr 30, 2024

Do the Rust stdlib tests pass on the simulators? Are there any current gaps? It would be good to know what the "current situation" seems to be.

It is quite difficult to run a test suite on the simulators, and I'm not experienced enough in Rust's bootstrapping setup to tell you exactly how to do it for this repo (though @simlay probably has some more or less cursed solution using Dinghy), so I'll admit I don't know the answer to your question.

But I'll try to run the test suite under Mac Catalyst, that might reveal some issues.

@workingjubilee
Copy link
Contributor

Ah, I had mostly asked because you had mentioned running some tests in the last commit! I'm happy with that answer, at the moment, and any fixes can be addressed as followups.

@bors r+

@bors
Copy link
Contributor

bors commented Apr 30, 2024

📌 Commit f9f3573 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 30, 2024
@thomcc
Copy link
Member

thomcc commented Apr 30, 2024

Apple has a non-standard varargs calling convention for aarch64, I don't know if they follow it for arm64_32.

@workingjubilee
Copy link
Contributor

workingjubilee commented Apr 30, 2024

It seems to be the same principle but with a different slot size? llvm/llvm-project@44e5879#diff-355c1d9d3832a837c9e90bb1b51fdbdcbbb36deff64c545644b96f6692baceaf

@workingjubilee
Copy link
Contributor

workingjubilee commented Apr 30, 2024

Yeah, it seems both are basically just stack pointers, and the rest of the implementation is calls into compiler intrinsics so it is unlikely there is anything that libstd changes can do to make this more or less incorrect.

@thomcc
Copy link
Member

thomcc commented Apr 30, 2024

I see. Does our va_list type match the declaration in C too? I guess I could check this...

@workingjubilee
Copy link
Contributor

The advantage of merging the libstd changes is that it makes it much easier to test if these implementations are incorrect. :^)

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented May 1, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 1, 2024
@madsmtm
Copy link
Contributor Author

madsmtm commented May 1, 2024

Modifying Cargo.toml and src/bootstrap/Cargo.toml to depend on a newer version of cc, and running:

./x test --target=aarch64-apple-ios-macabi library/std
./x test --target=aarch64-apple-ios-macabi --no-fail-fast --skip=tests/rustdoc-js --skip=tests/rustdoc-js-std --skip=tests/debuginfo tests

Produces errors in the following tests:

    [codegen] tests/codegen/gdb_debug_script_load.rs
    [run-make] tests/run-make/emit-stack-sizes
    [ui] tests/ui/abi/stack-probes.rs
    [ui] tests/ui/abi/stack-probes-lto.rs
    [ui] tests/ui/command/command-argv0.rs
    [ui] tests/ui/env-funky-keys.rs
    [ui] tests/ui/intrinsics/intrinsic-alignment.rs
    [ui] tests/ui/issues/issue-18804/main.rs
    [ui] tests/ui/link-section.rs
    [ui] tests/ui/linkage-attr/linkage1.rs
    [ui] tests/ui/osx-frameworks.rs
    [ui] tests/ui/runtime/out-of-stack.rs
    [ui] tests/ui/structs-enums/enum-rec/issue-17431-6.rs
    [ui] tests/ui/structs-enums/rec-align-u64.rs

Both before and after this PR. I suspect the stack probing, environment and argv0 to be real issues, and the rest to be under-specified tests that were only tweaked for macOS and not Apple in general. Will likely fix this in another PR at some point.

@madsmtm
Copy link
Contributor Author

madsmtm commented May 1, 2024

Seems to me like the va_list implementation should use *mut c_void on Apple AArch64 targets, see https://github.com/llvm/llvm-project/blob/llvmorg-18.1.4/clang/lib/Basic/Targets/AArch64.cpp#L1617.

Also, I think CI failed because it was cancelled, or something? Can't really tell from the logs :/

@workingjubilee
Copy link
Contributor

It looks like we do in fact use the right one for the appleOS platforms:

/// Basic implementation of a `va_list`.
// The name is WIP, using `VaListImpl` for now.
#[cfg(any(
all(
not(target_arch = "aarch64"),
not(target_arch = "powerpc"),
not(target_arch = "s390x"),
not(target_arch = "x86_64")
),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
target_family = "wasm",
target_os = "uefi",
windows,
))]
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
#[unstable(
feature = "c_variadic",
reason = "the `c_variadic` feature has not been properly tested on \
all supported platforms",
issue = "44930"
)]
#[lang = "va_list"]
pub struct VaListImpl<'f> {
ptr: *mut c_void,
// Invariant over `'f`, so each `VaListImpl<'f>` object is tied to
// the region of the function it's defined in
_marker: PhantomData<&'f mut &'f c_void>,
}

Yeah I think it was just a timeout.

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 1, 2024
@bors
Copy link
Contributor

bors commented May 1, 2024

⌛ Testing commit f9f3573 with merge 2e88e9e...

@bors
Copy link
Contributor

bors commented May 1, 2024

☀️ Test successful - checks-actions
Approved by: workingjubilee
Pushing 2e88e9e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 1, 2024
@bors bors merged commit 2e88e9e into rust-lang:master May 1, 2024
11 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 1, 2024
@madsmtm madsmtm deleted the target_vendor-apple branch May 1, 2024 04:32
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2e88e9e): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.5% [-0.5%, -0.5%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 672.879s -> 672.43s (-0.07%)
Artifact size: 315.99 MiB -> 315.99 MiB (0.00%)

bors added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2024
…Mark-Simulacrum

Fix unwinding on 32-bit watchOS ARM

Found while doing rust-lang#124491, I wanted to unify the code under `target_vendor = "apple"`, and found that [Clang actually specifies that watchOS ARM 32-bit does not use SjLj](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.4/clang/lib/Driver/ToolChains/Darwin.cpp#L3107-L3119).

I don't have an Apple Watch from that generation at hand to test this myself (series 1 to 3), and I don't think it will be sufficient to test it in the simulator (as it's architecture-specific), so maybe someone else could do so?

N.B. The code is written in a way to support 32-bit iOS and tvOS ARM devices (which do use SjLj) for future compatibility even though we currently only have a target for 32-bit iOS ARM (if you think that's excessive, then I'll change it).

CC target maintainers `@deg4uss3r,` `@vladimir-ea,` `@leohowell.`
CC `@simlay,` `@thomcc` whom might have more insight into this than I.

`@rustbot` label O-watchos
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 5, 2024
…r=Mark-Simulacrum

Fix unwinding on 32-bit watchOS ARM (v2)

This PR is identical to rust-lang#124494, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F).

r? Mark-Simulacrum

Original PR description:

---

Found while doing rust-lang#124491, I wanted to unify the code under `target_vendor = "apple"`, and found that [Clang actually specifies that watchOS ARM 32-bit does not use SjLj](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.4/clang/lib/Driver/ToolChains/Darwin.cpp#L3107-L3119).

I don't have an Apple Watch from that generation at hand to test this myself (series 1 to 3), and I don't think it will be sufficient to test it in the simulator (as it's architecture-specific), so maybe someone else could do so?

N.B. The code is written in a way to support 32-bit iOS and tvOS ARM devices (which do use SjLj) for future compatibility even though we currently only have a target for 32-bit iOS ARM (if you think that's excessive, then I'll change it).

`@rustbot` label O-watchos
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2024
Rollup merge of rust-lang#124748 - madsmtm:fix-32bit-watchos-unwind, r=Mark-Simulacrum

Fix unwinding on 32-bit watchOS ARM (v2)

This PR is identical to rust-lang#124494, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F).

r? Mark-Simulacrum

Original PR description:

---

Found while doing rust-lang#124491, I wanted to unify the code under `target_vendor = "apple"`, and found that [Clang actually specifies that watchOS ARM 32-bit does not use SjLj](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.4/clang/lib/Driver/ToolChains/Darwin.cpp#L3107-L3119).

I don't have an Apple Watch from that generation at hand to test this myself (series 1 to 3), and I don't think it will be sufficient to test it in the simulator (as it's architecture-specific), so maybe someone else could do so?

N.B. The code is written in a way to support 32-bit iOS and tvOS ARM devices (which do use SjLj) for future compatibility even though we currently only have a target for 32-bit iOS ARM (if you think that's excessive, then I'll change it).

`@rustbot` label O-watchos
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request May 8, 2024
…workingjubilee

Convert instances of `target_os = "macos"` to `target_vendor = "apple"`

rust-lang#124491 migrated towards using `target_vendor = "apple"` more, as there's very little difference between iOS, tvOS, watchOS and visionOS. In that PR, I only did the changes where the standard library already had fixes for iOS, that I could confidently apply to the other targets.

However, there's actually also not that big of a gap between macOS and the aforementioned platforms - so in this PR, I've gone through a few of the instances of `target_os = "macos"` and replaced it with `target_vendor = "apple"` to improve support on those platforms, see the commits for details.

r? workingjubilee

CC `@thomcc` `@simlay` (do tell me if I should stop pinging you on these Apple PRs)

`@rustbot` label O-apple
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 8, 2024
Rollup merge of rust-lang#124788 - madsmtm:reduce-target_os-macos, r=workingjubilee

Convert instances of `target_os = "macos"` to `target_vendor = "apple"`

rust-lang#124491 migrated towards using `target_vendor = "apple"` more, as there's very little difference between iOS, tvOS, watchOS and visionOS. In that PR, I only did the changes where the standard library already had fixes for iOS, that I could confidently apply to the other targets.

However, there's actually also not that big of a gap between macOS and the aforementioned platforms - so in this PR, I've gone through a few of the instances of `target_os = "macos"` and replaced it with `target_vendor = "apple"` to improve support on those platforms, see the commits for details.

r? workingjubilee

CC `@thomcc` `@simlay` (do tell me if I should stop pinging you on these Apple PRs)

`@rustbot` label O-apple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. O-ios Operating system: iOS O-macos Operating system: macOS O-tvos Operating system: tvOS (including simulator) O-unix Operating system: Unix-like O-visionos Apple visionOS O-watchos Operating System: watchOS S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants