Skip to content

Expose OperatingSystem.IsApplePlatform publicly and Clean up watchOS - #135475

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

makazeu wants to merge 12 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 checks throughout the codebase to consolidate Apple-related OS checks into a single method, OperatingSystem.IsApplePlatform(). It also removes support for watchOS, updating both implementation and tests accordingly. This streamlines platform detection logic, reduces duplication, and clarifies current platform support.

Platform detection refactoring:

  • Introduced and made public OperatingSystem.IsApplePlatform(), replacing multiple checks for individual Apple platforms (IsMacOS, IsIOS, IsTvOS, IsMacCatalyst) in both product and test code. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

  • Updated comments and documentation to reflect the consolidated Apple platform detection, and removed references to watchOS where appropriate. [1] [2] [3] [4]

watchOS deprecation/removal:

  • Removed support for watchOS in platform detection APIs (IsWatchOS now always returns false and is documented as unsupported), in version checks, and in native code. [1] [2] [3] [4]

Test updates:

  • Updated and simplified tests to use the new IsApplePlatform() method and removed watchOS from test cases and assertions. [1] [2] [3]

These changes improve maintainability by centralizing Apple platform logic and clarify that watchOS is no longer a supported target.

@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.

@jkotas

jkotas commented Oct 10, 2026

Copy link
Copy Markdown
Member

how would you prefer to handle watchOS in IsApplePlatform()?

Option 1: Add TARGET_WATCHOS to the ifdef in IsApplePlatform

Option 2: Delete TARGET_WATCHOS ifdef in IsWatchOS() and replace with a comment that says watchOS is no longer supported. Also, delete watchOS references in src\libraries\System.Private.CoreLib\src\System\Runtime\InteropServices\RuntimeInformation.Unix.cs, src\libraries\System.Runtime\tests\System.Runtime.Extensions.Tests\System\OperatingSystemTests.cs, src\native\eventpipe\ep-event-source.c, src\native\libs\System.Native\pal_time.c, src\native\libs\System.Security.Cryptography.Native.Apple\pal_ssl.c.

Pick the one you like better - either one is fine with me.

@makazeu

makazeu commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Pick the one you like better - either one is fine with me.

I prefer option 2 - to do a deeper cleanup of watchOS.

@makazeu makazeu changed the title Expose IsApplePlatform publicly in OperatingSystem Expose OperatingSystem.IsApplePlatform publicly and Clean up watchOS Oct 11, 2026

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