Skip to content

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

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

makazeu wants to merge 14 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

@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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

IsApplePlatform lacks platform-guard annotations in both its implementation and reference declaration, so the compatibility analyzer cannot infer Apple-platform exclusions and consumers may still receive CA1416 warnings.

2 open issues
What changed in this PR

This PR exposes OperatingSystem.IsApplePlatform() publicly, as proposed in #113262, and adopts it across library code and tests. It also removes obsolete watchOS detection paths while retaining the public watchOS helpers as always-false checks.

Changes:

  • Adds the public Apple-platform helper and test assertions.
  • Consolidates repeated Apple OS checks across file-system and networking code.
  • Removes watchOS-specific detection branches and updates related documentation.
File Description
src/​native/​libs/​System.Security.Cryptography.Native.Apple/​pal_ssl.c Removes watchOS from a comment.
src/​native/​libs/​System.Native/​pal_time.c Removes watchOS from a fallback comment.
src/​native/​eventpipe/​ep-event-source.c Removes watchOS event-source identification.
src/​libraries/​System.Runtime/​tests/​System.Runtime.Extensions.Tests/​System/​OperatingSystemTests.cs Adds Apple-platform assertions and removes watchOS cases.
src/​libraries/​System.Runtime/​ref/​System.Runtime.cs Declares the new public helper.
src/​libraries/​System.Private.CoreLib/​src/​System/​Runtime/​InteropServices/​RuntimeInformation.Unix.cs Removes the watchOS description branch.
src/​libraries/​System.Private.CoreLib/​src/​System/​OperatingSystem.cs Exposes the helper and makes watchOS checks always false.
src/​libraries/​System.Net.Sockets/​src/​System/​Net/​Sockets/​SocketPal.Unix.cs Simplifies the Apple-specific select workaround check.
src/​libraries/​System.Net.Quic/​src/​System/​Net/​Quic/​Interop/​msquic.cs Consolidates Apple socket-address layout checks.
src/​libraries/​System.Net.Ping/​tests/​FunctionalTests/​PingTest.cs Simplifies ping-utility platform detection.
src/​libraries/​System.Net.NetworkInformation/​tests/​FunctionalTests/​IPGlobalPropertiesTest.cs Consolidates Apple exclusions for IPv6 statistics.
src/​libraries/​System.IO.MemoryMappedFiles/​tests/​MemoryMappedViewStream.Tests.cs Simplifies Apple executable-memory permission handling.
src/​libraries/​System.IO.MemoryMappedFiles/​tests/​MemoryMappedViewAccessor.Tests.cs Simplifies Apple executable-memory permission handling.
src/​libraries/​Common/​src/​System/​IO/​PathInternal.CaseSensitivity.cs Uses the helper for file-system case-sensitivity detection.

Review effort: Balanced

Comment on lines +293 to +294
[NonVersionable]
public static bool IsApplePlatform() =>
public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) { throw null; }
public static bool IsMacOS() { throw null; }
public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) { throw null; }
public static bool IsApplePlatform() { throw null; }
@jkotas

jkotas commented Nov 4, 2026

Copy link
Copy Markdown
Member

@makazeu Could you please address copilot feedback?

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

4 participants