Skip to content

Expose IsApplePlatform publicly in OperatingSystem - #135475

Open
makazeu wants to merge 11 commits into
dotnet:mainfrom
makazeu:patch-1
Open

makazeu wants to merge 11 commits into
dotnet:mainfrom
makazeu:patch-1

Conversation

@makazeu

@makazeu makazeu commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Closes #113262.

As discussed in #113262 and the video, we're good to make this helper exposed publicly in OperatingSystem.

cc @bartonjs


This pull request refactors platform detection logic across the codebase to use the new OperatingSystem.IsApplePlatform() API, replacing multiple checks for individual Apple platforms (macOS, iOS, tvOS, MacCatalyst). It also makes IsApplePlatform() a public API, updates related tests, and ensures consistent platform checks throughout the libraries.

Platform detection improvements:

  • Replaced multiple checks for individual Apple platforms with a single call to OperatingSystem.IsApplePlatform() in various files, simplifying and centralizing Apple platform detection. [1] [2] [3] [4] [5] [6] [7]

API changes:

  • Made OperatingSystem.IsApplePlatform() a public API, added documentation, and updated the reference assembly to include the new method. [1] [2]

Test updates:

  • Updated and expanded tests in OperatingSystemTests to validate the new IsApplePlatform() logic, including a new set of supported Apple platform names and corresponding assertions. [1] [2]

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 9, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

makazeu and others added 4 commits October 9, 2026 17:07
Added a HashSet for all Apple platform names and updated tests to verify Apple platform detection.
Add Ref and tests for public IsApplePlatform API
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@makazeu makazeu changed the title Expose IsApplePlatforms publicly in OperatingSystem Expose IsApplePlatform publicly in OperatingSystem Oct 9, 2026
@vcsjones

vcsjones commented Oct 9, 2026

Copy link
Copy Markdown
Member

I assume we are going to need a corresponding pull request from someone for the compatibility analyzer? I don't know if the analyzer will handle this without changes. https://github.com/dotnet/dotnet/blob/4fd6fbb479abbacd43b32fdc0ef6f68414cc028d/src/sdk/src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.NetAnalyzers/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs

Comment thread src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs
Comment thread src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs Outdated
@makazeu

makazeu commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

watchOS will NOT be added to IsApplePlatform since modern .NET doesn't support it, and all previous isWatchOS checks had been removed. #117653

@jkotas

jkotas commented Oct 9, 2026

Copy link
Copy Markdown
Member

Revert isWatchOS change

I think it was a fine change - for consistency.

We do not currently build and test for watch OS, but the code for it still there.

@jkotas

jkotas commented Oct 9, 2026

Copy link
Copy Markdown
Member

all previous isWatchOS checks had been removed

It looks odd when one place in the same file assumes that watchOS does not exist, but other place treats it as a thing.

@makazeu

makazeu commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

all previous isWatchOS checks had been removed

It looks odd when one place in the same file assumes that watchOS does not exist, but other place treats it as a thing.

Yeah, exactly. That’s why I initially added watchOS.

However, after thinking about @vcsjones 's comment on the compatibility analyzer, I decided to remove watchOS for now.

Let's assume the platform compatibility analyzer supports IsApplePlatform() and checks all five platforms, including watchOS:
Consider an API annotated as supported on the other 4 platforms. Even if the call site is guarded by OperatingSystem.IsApplePlatform(), the analyzer would still report a compatibility issue.

I wanted to avoid this situation. After all, new APIs won't explicitly include [SupportedOSPlatform("watchos")] anymore. @jkotas What do you think?

@makazeu

makazeu commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

I assume we are going to need a corresponding pull request from someone for the compatibility analyzer? I don't know if the analyzer will handle this without changes. https://github.com/dotnet/dotnet/blob/4fd6fbb479abbacd43b32fdc0ef6f68414cc028d/src/sdk/src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.NetAnalyzers/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs

Sure, I'll follow up on this, thanks!

@jkotas

jkotas commented Oct 10, 2026

Copy link
Copy Markdown
Member

Let's assume the platform compatibility analyzer supports IsApplePlatform() and checks all five platforms, including watchOS

I do not think that this has any impact on platform compatibility analyzer user experience.

The platform compatibility analyzer only checks compatibly for platforms specified via <SupportedPlatform> item group. This set is Windows/macOS/Linux by default - https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.SupportedPlatforms.props . It means that you can be calling APIs that are unsupported on SomeOtherOS and it won't warn by default. You have to opt-in your project into checking compatibility with SomeOtherOS.

@makazeu

makazeu commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Let's assume the platform compatibility analyzer supports IsApplePlatform() and checks all five platforms, including watchOS

I do not think that this has any impact on platform compatibility analyzer user experience.

The platform compatibility analyzer only checks compatibly for platforms specified via <SupportedPlatform> item group. This set is Windows/macOS/Linux by default - https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.SupportedPlatforms.props . It means that you can be calling APIs that are unsupported on SomeOtherOS and it won't warn by default. You have to opt-in your project into checking compatibility with SomeOtherOS.

@jkotas Thanks for the clear explanation! I hadn’t realized that the analyzer’s platform checks are scoped by <SupportedPlatform>— I learned something new here.

Given that, how would you prefer to handle watchOS in IsApplePlatform()? Should we keep it excluded for consistency with #117653, or include it for consistency with the remaining watchOS detection code? Including it would effectively reintroduce watchOS checks at the call sites converted to IsApplePlatform(), partially undoing that earlier cleanup.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Runtime community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Make IsApplePlatform public

3 participants