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

Make std::os::darwin public #123723

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Apr 10, 2024

I'm not sure of the reasoning behind them not being public before, but I think they should be, just like std::os::ios and std::os::macos are public.

Additionally, I've merged their source code, as it was otherwise just a bunch of unnecessary duplication.

Ultimately, I've done this PR to fix ./x build library --target=aarch64-apple-tvos,aarch64-apple-watchos,aarch64-apple-visionos, as that currently fails because of dead code warnings.

Since you reviewed #121419
r? davidtwco

Fixes #121640.

@rustbot label O-tvos O-watchos O-visionos

@rustbot
Copy link
Collaborator

rustbot commented Apr 10, 2024

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot
Copy link
Collaborator

rustbot commented Apr 10, 2024

Unknown labels: O-visionos

@rustbot
Copy link
Collaborator

rustbot commented Apr 10, 2024

Unknown labels: O-visionos

@rustbot
Copy link
Collaborator

rustbot commented Apr 10, 2024

triagebot.toml has been modified, there may have been changes to the review queue.

cc @davidtwco, @wesleywiser

@davidtwco
Copy link
Member

r? libs

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Apr 16, 2024
@rustbot rustbot assigned m-ou-se and unassigned davidtwco Apr 16, 2024
@madsmtm madsmtm closed this Apr 16, 2024
@madsmtm madsmtm deleted the apple-std-os branch April 16, 2024 16:59
@madsmtm madsmtm restored the apple-std-os branch April 16, 2024 16:59
@madsmtm madsmtm reopened this Apr 16, 2024
@madsmtm
Copy link
Contributor Author

madsmtm commented Apr 16, 2024

Sorry, accidentally deleted the branch

library/std/src/os/mod.rs Outdated Show resolved Hide resolved
@madsmtm
Copy link
Contributor Author

madsmtm commented May 3, 2024

r? libs-api

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label May 3, 2024
@rustbot rustbot assigned dtolnay and unassigned m-ou-se May 3, 2024
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I am open to adding these modules, but not the deprecated contents being exposed by this PR. std::os::macos::raw has been deprecated since more than 8 years ago and I don't think we should be adding more of that API for new targets.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. O-tvos Operating system: tvOS (including simulator) O-visionos Apple visionOS O-watchos Operating System: watchOS labels May 4, 2024
@rustbot rustbot added the A-meta Area: Issues & PRs about the rust-lang/rust repository itself label May 4, 2024
@madsmtm
Copy link
Contributor Author

madsmtm commented May 8, 2024

There could be an umbrella namespace for these common stuffs, e.g. apple like cfg(target_vendor="apple").

I think std::os::apple is a good idea, but I think it's somewhat separate from this proposal; even if we have std::os::apple, I think I'd still want std::os::tvos/std::os::watchos/std::os::visionos for consistency with std::os::macos/std::os::ios (unless we fully deprecate the latter).

Implementation-wise, it could just be pub use apple as ios;.

@Amanieu
Copy link
Member

Amanieu commented May 9, 2024

I would rather avoid having to include a new submodule every time apple designs a new device and instead centralize everything under a single submodule. For backwards-compatibility, std::os::macos can be a re-export of std::os::apple, but I don't think we should add more.

@workingjubilee
Copy link
Member

Hello,

I was there for some of the discussion of this nature because I reviewed the tvos PR and a few others. It basically went exactly like this discussion. There is no point in having all these different APIs exposed when they introduce a somewhat-pointless risk for additional variance.

It may be prudent to use the kernel name... i.e. mod darwin... that AIUI they all share, because there is The Other MacOS from long ago. Apple is clearly willing to have epochal breaking changes that risk redefining what mod apple would mean. Rosetta 2 implies its own sequel, a Rosetta III: Translator's Revenge.

@dtolnay dtolnay added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 1, 2024
@madsmtm
Copy link
Contributor Author

madsmtm commented Jun 3, 2024

I opened #125935 to do the refactor and fixing the compilation errors separately, so that this PR can be focused on the public API. Will rebase once that lands.

It may be prudent to use the kernel name... i.e. mod darwin

Well, the kernel name is technically XNU, it's the broader core OS that's named Darwin, but your point still stands. I think it could be a pretty good name to use, were it not for the fact that the macOS targets use it in their names as well (e.g. aarch64-apple-darwin), which might be confusing?

A bit of prior art:

  • Swift has import Darwin for Apple-specific stuff, and #if os(Darwin) ... #endif for Apple-specific configs.
  • C/Objective-C has TargetConditionals.h which defines TARGET_OS_MAC for this purpose (TARGET_OS_OSX is the one for macOS-specific code).
  • Python's platform.system() returns Darwin on macOS and iOS on iOS, while os.uname() returns Darwin on both.

In an ideal world, I think I'd want:

  1. cfg(target_family = "darwin") (or just cfg(darwin)).
  2. The macOS targets to be named *-apple-macos.
  3. std::os::darwin.

So if we can agree that plan is to move in this direction (i.e. at some point slowly rename the targets, and at some point add target_family = "darwin"), then I think std::os::darwin makes sense; if not, then we should probably go with std::os::apple.

@workingjubilee
Copy link
Member

workingjubilee commented Jun 3, 2024

In an ideal world, I think I'd want:

  1. cfg(target_family = "darwin") (or just cfg(darwin)).
  2. The macOS targets to be named *-apple-macos.
  3. std::os::darwin.

So if we can agree that plan is to move in this direction (i.e. at some point slowly rename the targets, and at some point add target_family = "darwin"), then I think std::os::darwin makes sense; if not, then we should probably go with std::os::apple.

Yes, I was in particular thinking that the target_family cfg proposed for the phase out of target_vendor should be named thus in accord with this. Ideally we would get aarch64-apple-macos as a target tuple (since the target_os is "macos" anyways), but that may prove the harder part.

@joshtriplett
Copy link
Member

We discussed this in today's @rust-lang/libs-api meeting. Our consensus was that we don't want to provide a different module for every Apple OS, and that we should only provide distinct modules if they have distinct functions that don't exist on the other OSes. Please just provide the std::os::apple module with the common functionality across all Apple OSes.

macos should re-export apple and also provide the deprecated items; apple shouldn't have the deprecated items.

@Amanieu Amanieu added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Jun 18, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 14, 2024
…ilee

Merge Apple `std::os` extensions modules into `std::os::darwin`

The functionality available on Apple platforms are very similar, and were (basically) duplicated for each platform.

This PR rectifies that by merging the code into one module.

Ultimately, I've done this to fix `./x build library --target=aarch64-apple-tvos,aarch64-apple-watchos,aarch64-apple-visionos`, as that currently fails because of dead code warnings.

Publically exposing these to tvOS/watchOS/visionOS targets is considered in rust-lang#123723, but that seems to be dragging out, and in any case I think it makes sense to do the refactor separately from stabilization.

r? libs

Fixes rust-lang#121640 and rust-lang#124825.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jul 16, 2024
Merge Apple `std::os` extensions modules into `std::os::darwin`

The functionality available on Apple platforms are very similar, and were (basically) duplicated for each platform.

This PR rectifies that by merging the code into one module.

Ultimately, I've done this to fix `./x build library --target=aarch64-apple-tvos,aarch64-apple-watchos,aarch64-apple-visionos`, as that currently fails because of dead code warnings.

Publically exposing these to tvOS/watchOS/visionOS targets is considered in rust-lang/rust#123723, but that seems to be dragging out, and in any case I think it makes sense to do the refactor separately from stabilization.

r? libs

Fixes rust-lang/rust#121640 and rust-lang/rust#124825.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Jul 16, 2024
Merge Apple `std::os` extensions modules into `std::os::darwin`

The functionality available on Apple platforms are very similar, and were (basically) duplicated for each platform.

This PR rectifies that by merging the code into one module.

Ultimately, I've done this to fix `./x build library --target=aarch64-apple-tvos,aarch64-apple-watchos,aarch64-apple-visionos`, as that currently fails because of dead code warnings.

Publically exposing these to tvOS/watchOS/visionOS targets is considered in rust-lang/rust#123723, but that seems to be dragging out, and in any case I think it makes sense to do the refactor separately from stabilization.

r? libs

Fixes rust-lang/rust#121640 and rust-lang/rust#124825.
@joshtriplett
Copy link
Member

joshtriplett commented Aug 6, 2024

It looks like #125935 performed the merge we asked for; thank you!

Is there anything else that needs to happen here? Is the new std::os::darwin available on tvOS/visionOS/watchOS?

@rustbot rustbot added the O-unix Operating system: Unix-like label Aug 13, 2024
@madsmtm madsmtm changed the title Make std::os::tvos, std::os::visionos and std::os::watchos public Make std::os::darwin public Aug 13, 2024
@rust-log-analyzer

This comment has been minimized.

This includes `std::os::darwin::fs`, which is re-exported under
`std::os::macos::fs` and `std::os::ios::fs`.

`std::os::darwin::raw` is not exposed, which means that
`MetadataExt::as_raw_stat` isn't available on tvOS, visionOS and
watchOS.
@madsmtm madsmtm force-pushed the apple-std-os branch 2 times, most recently from e61d428 to 858d6d1 Compare August 13, 2024 22:32
@madsmtm
Copy link
Contributor Author

madsmtm commented Aug 13, 2024

I have updated this PR to instead make std::os::darwin::fs public. Since the exposed API surface here isn't really new, I propose to just make this insta-stable 1.

Summary

std::os::darwin is available on cfg(target_vendor = "apple") (macOS, iOS, tvOS, visionOS and watchOS), and contains functionality specific to those operating systems. It is named "Darwin" because that's the name of the underlying operating system that all of these are built upon. This follows the naming convention in Swift (import Darwin), so while it's a little bit unknown, it should be fairly familiar to developers for Apple platforms.

The API for std::os::darwin is:

darwin darwin_fs darwin_fs_MetadataExt darwin_fs_FileTimesExt

The API for std::os::macos and std::os::ios is now:

macos_raw macos_fs

Note: The images here doesn't show it, but MetadataExt::as_raw_stat is only available on macOS and iOS.

In the future, we can consider deprecating std::os::macos and std::os::ios, but this PR does not propose that.

@rustbot ready

Footnotes

  1. I considered going through the normal feature gate lifecycle, and making a tracking issue and whatnot, but from what I read in here, it seems like re-exporting std::os::darwin::fs::* under std::os::macos::fs::* with the old stability attributes might still end up making it stably accessible under std::os::darwin::fs::* anyhow.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 13, 2024
@madsmtm
Copy link
Contributor Author

madsmtm commented Aug 13, 2024

Responding to #123723 (comment):

  • Do not expose std::os::{tvos, visionos, watchos}::raw — those modules will be changed to pub(crate). For macos, raw has been deprecated since more than 8 years ago and I think it's worth avoiding adding that deprecated API in yet another place. Note that the 9 type aliases will continue to be accessible as re-exports in std::os::unix::raw, where they have been stably accessible on tvos, visionos, and watchos since the original introduction of these targets. For future unix targets, we may wish to avoid re-exporting raw deprecated types for them in std::os::unix::raw in the first place.

Only std::os::darwin::fs is exposed, std::os::darwin::raw is pub(crate) and instead exposed publicly in std::os::unix::raw, std::os::macos::raw and std::os::ios::raw.

  • Do not include as_raw_stat in the MetadataExt trait of the new targets. On macos this trait method has been deprecated since Rust 1.8.

This is cfg-gated to only be available on macOS and iOS.

  • Seal the MetadataExt trait of the new targets.

I'm not entirely sure of a good way to do this without complex macros? trait MetadataExt: #[cfg(...)] Sealed doesn't work.

@madsmtm
Copy link
Contributor Author

madsmtm commented Sep 14, 2024

r? libs-api

@rustbot rustbot assigned BurntSushi and unassigned dtolnay Sep 14, 2024
@workingjubilee
Copy link
Member

FCP checkboxes are back in this now-hidden comment, in case you're wondering why you can't find them: #123723 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-meta Area: Issues & PRs about the rust-lang/rust repository itself 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) 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 proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to build aarch64-apple-tvos target