Repository navigation
Conversation
|
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. |
|
Tagging subscribers to this area: @dotnet/area-system-runtime |
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>
IsApplePlatforms publicly in OperatingSystemIsApplePlatform publicly in OperatingSystem
|
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 |
…Pal.Unix.cs Co-authored-by: Jan Kotas <jkotas@microsoft.com>
|
|
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. |
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 Let's assume the platform compatibility analyzer supports I wanted to avoid this situation. After all, new APIs won't explicitly include |
Sure, I'll follow up on this, thanks! |
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 |
@jkotas Thanks for the clear explanation! I hadn’t realized that the analyzer’s platform checks are scoped by Given that, how would you prefer to handle watchOS in |
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. |
I prefer option 2 - to do a deeper cleanup of watchOS. |
IsApplePlatform publicly in OperatingSystemOperatingSystem.IsApplePlatform publicly and Clean up watchOS
There was a problem hiding this comment.
🟡 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
| [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; } |
|
@makazeu Could you please address copilot feedback? |


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:
IsWatchOSnow always returns false and is documented as unsupported), in version checks, and in native code. [1] [2] [3] [4]Test updates:
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.