Skip to content

[src] Add [Un]SupportedSimulator attributes.#25347

Open
rolfbjarne wants to merge 6 commits intomainfrom
dev/rolf/supportedsimulatorattribute
Open

[src] Add [Un]SupportedSimulator attributes.#25347
rolfbjarne wants to merge 6 commits intomainfrom
dev/rolf/supportedsimulatorattribute

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

Add two attributes to specify whether an API is available in the simulator:

  • [UnsupportedSimulator ("")]: API is not available.
  • [SupportedSimulator ("[osversion]")]: API is available, optionally
    only in the specified OS version or not.

If no attribute is found, then the API is available in the simulator.

Unlike the normal availability attributes, specifying simulator availability for
one platform does not mean anything for any other platforms.

Add two attributes to specify whether an API is available in the simulator:

* [UnsupportedSimulator ("<platform>")]: API is not available.
* [SupportedSimulator ("<platform>[osversion]")]: API is available, optionally
  only in the specified OS version or not.

If no attribute is found, then the API is available in the simulator.

Unlike the normal availability attributes, specifying simulator availability for
one platform does not mean anything for any other platforms.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces two new attributes ([SupportedSimulator] / [UnsupportedSimulator]) to describe simulator-only availability for APIs, wires the logic into both the binding generator (bgen) and introspection tests, and replaces a number of simulator-specific skip-lists with attribute-driven behavior (notably for newer Metal/MetalFX/VideoToolbox APIs).

Changes:

  • Added SupportedSimulatorAttribute / UnsupportedSimulatorAttribute to ObjCRuntime, and trimmed them during linking.
  • Updated bgen to emit simulator-availability attributes for iOS/tvOS only, with new bgen unit tests to validate emission behavior.
  • Updated introspection tests to honor simulator-availability attributes, and annotated relevant Metal/MetalFX/VideoToolbox APIs as unsupported in iOS/tvOS simulators.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/introspection/ApiCtorInitTest.cs Removes hardcoded simulator skip cases now handled via simulator-availability attributes.
tests/introspection/ApiBaseTest.cs Extends skip logic to consider simulator availability (IsAvailableInSimulator).
tests/common/PlatformInfo.cs Adds reflection-based evaluation of [SupportedSimulator] / [UnsupportedSimulator] during simulator runs.
tests/bgen/tests/simulator-availability-attributes.cs Adds a dedicated bgen fixture file exercising simulator availability attributes.
tests/bgen/BGenTests.cs Adds tests verifying simulator attributes are emitted for iOS/tvOS and not emitted for macOS/Mac Catalyst.
src/videotoolbox.cs Marks specific new VideoToolbox APIs as unsupported on iOS/tvOS simulators.
src/TrimAttributes.LinkDescription.xml Ensures simulator-availability attributes are removed by the linker (attribute-instance trimming).
src/ObjCRuntime/SupportedSimulatorAttribute.cs Introduces the new public attributes in ObjCRuntime.
src/metalfx.cs Marks MetalFX descriptor APIs as unsupported on iOS/tvOS simulators.
src/Metal/MTLEnums.cs Marks selected Metal enums as unsupported on iOS/tvOS simulators.
src/metal.cs Marks many Metal (incl. Metal 4) APIs as unsupported on iOS/tvOS simulators.
src/frameworks.sources Adds the new attribute source file to the shared core sources list.
src/bgen/Generator.cs Adds emission of simulator-availability attributes (filtered to current platform; ignored on Mac platforms).
src/bgen/Enums.cs Ensures simulator-availability attributes are printed for enum extension generation as well.
src/bgen/bgen.csproj Includes the new attribute definitions in the bgen build.
src/bgen/AttributeManager.cs Teaches attribute loading to resolve the new attribute types.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
Copy link
Copy Markdown
Member Author

/review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

.NET for Apple Platforms PR Reviewer completed successfully!

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Review Summary

This PR introduces two new attributes ([SupportedSimulator] and [UnsupportedSimulator]) to specify whether APIs are available in iOS/tvOS simulators. The implementation is well-structured and follows the repository's patterns.

✅ What's Good

  • Clear architecture: The attributes are properly integrated into bgen, with filtering logic that only emits attributes relevant to the current platform
  • Comprehensive testing: Includes bgen tests, introspection test integration, and proper handling in PlatformInfo.IsAvailableInSimulator()
  • Proper trimming configuration: The attributes are correctly configured for removal during app trimming in TrimAttributes.LinkDescription.xml
  • Consistent usage: Applied systematically to MLCompute, Metal, MetalFX, and VideoToolbox APIs that aren't available in simulators
  • Test cleanup: Removes numerous simulator-specific workarounds from introspection tests now that the framework properly tracks simulator availability

📊 Issues Found

  • ⚠️ 1 warning: Performance issue with string allocations in IsAvailableInSimulator() hot path
  • 💡 4 suggestions: Code duplication, error handling, documentation clarity, and immutability patterns

Verdict

No blocking issues. The warnings and suggestions are optional improvements that would enhance code quality but aren't required for merge.

CI status: Some test failures present (monotouch_tvos, xcframework, interdependent-binding-projects), but these appear unrelated to this change since the core simulator and introspection tests pass.

Generated by .NET for Apple Platforms PR Reviewer for issue #25347 · ● 875K

Comment thread src/bgen/Generator.cs
Comment thread tests/common/PlatformInfo.cs Outdated
Comment thread tests/common/PlatformInfo.cs Outdated
Comment thread src/ObjCRuntime/SupportedSimulatorAttribute.cs Outdated
Comment thread src/ObjCRuntime/SupportedSimulatorAttribute.cs Outdated
…rove docs

- Extract IsSimulatorAvailabilityRelevantPlatform() helper in Generator.cs
  to reduce duplicated platform switch logic.
- Use AsSpan() instead of Substring() in PlatformInfo.IsAvailableInSimulator
  to avoid string allocations in the hot path.
- Throw InvalidOperationException on malformed version strings instead of
  silently continuing.
- Improve XML doc for platformName param with format examples.
- Make PlatformName properties init-only for immutability.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 2 commits May 7, 2026 09:24
Adds ApiSimulatorAvailabilityTest which verifies that:
- P/Invokes and [Field] properties marked with [UnsupportedSimulator]
  truly have unavailable native symbols in the simulator.
- P/Invokes and [Field] properties NOT marked as unsupported don't have
  missing symbols (detecting cases where [UnsupportedSimulator] is needed).

The test only runs in the simulator and is ignored on device/desktop.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🔥 [CI Build #fc0a48a] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 24 tests failed, 145 tests passed.

Failures

❌ interdependent-binding-projects tests

2 tests failed, 2 tests passed.

Failed tests

  • interdependent-binding-projects/iOS - simulator/Debug: LaunchTimedOut
  • interdependent-binding-projects/tvOS - simulator/Debug: LaunchTimedOut

Html Report (VSDrops) Download

❌ linker tests

22 tests failed, 22 tests passed.

Failed tests

  • dont link/iOS - simulator/Debug: LaunchTimedOut
  • dont link/iOS - simulator/Release: LaunchTimedOut
  • dont link/tvOS - simulator/Debug: LaunchTimedOut
  • dont link/tvOS - simulator/Release: LaunchTimedOut
  • link sdk/iOS - simulator/Debug: LaunchTimedOut
  • link sdk/iOS - simulator/Release: LaunchTimedOut
  • link sdk/tvOS - simulator/Debug: LaunchTimedOut
  • link sdk/tvOS - simulator/Release: LaunchTimedOut
  • link all/iOS - simulator/Debug: LaunchTimedOut
  • link all/iOS - simulator/Release: LaunchTimedOut
  • link all/iOS - simulator/Debug (don't bundle original resources): LaunchTimedOut
  • link all/tvOS - simulator/Debug: LaunchTimedOut
  • link all/tvOS - simulator/Release: LaunchTimedOut
  • link all/tvOS - simulator/Debug (don't bundle original resources): LaunchTimedOut
  • trimmode copy/iOS - simulator/Debug: LaunchTimedOut
  • trimmode copy/iOS - simulator/Release: LaunchTimedOut
  • trimmode copy/tvOS - simulator/Debug: LaunchTimedOut
  • trimmode copy/tvOS - simulator/Release: LaunchTimedOut
  • trimmode link/iOS - simulator/Debug: LaunchTimedOut
  • trimmode link/iOS - simulator/Release: LaunchTimedOut
  • trimmode link/tvOS - simulator/Debug: LaunchTimedOut
  • trimmode link/tvOS - simulator/Release: LaunchTimedOut

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 13 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 13 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. (⚠️ Html Report Publish failed ⚠️) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: fc0a48a92bc47f50670aa993d758c39b644f6a2d [PR build]

@rolfbjarne
Copy link
Copy Markdown
Member Author

/review

@rolfbjarne rolfbjarne marked this pull request as ready for review May 7, 2026 21:11
@rolfbjarne rolfbjarne requested a review from dalexsoto as a code owner May 7, 2026 21:11
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

.NET for Apple Platforms PR Reviewer completed successfully!

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Review Summary

Clean implementation — This PR introduces simulator availability attributes with excellent attention to detail.

What's Good

  • Complete feature implementation: Both [SupportedSimulator] and [UnsupportedSimulator] attributes are properly designed with platform name + optional version support
  • Proper trimming configuration: Attributes correctly marked for trimming in TrimAttributes.LinkDescription.xml
  • Platform-aware code generation: bgen correctly filters attributes to only emit those relevant to the current platform (iOS/tvOS get simulator attributes, macOS/Catalyst do not)
  • Comprehensive test coverage:
    • BGen unit tests verify attribute emission for iOS/tvOS and absence for Mac platforms
    • Introspection tests validate P/Invoke and Field symbol availability at runtime
    • Test helper IsAvailableInSimulator() properly checks attributes with version constraints
  • Consistent usage: Applied systematically across MLCompute, Metal, VideoToolbox, and MetalFX bindings
  • Good documentation: XML docs clearly explain the semantics and the independence from standard availability attributes

Findings

  • 💡 1 suggestion for nullable pattern consistency (see inline comment)

Recommendation

This is high-quality work from a senior maintainer. The single suggestion is optional and does not block merge. CI checks are still running — once green, this should be good to go.


Total: 1 suggestion

Generated by .NET for Apple Platforms PR Reviewer for issue #25347 · ● 1.1M

Comment thread src/bgen/Generator.cs
PrintUnsupportedSimulatorAttribute (provider, platformName);
}

bool TryGetSimulatorAvailabilityPlatformName ([NotNullWhen (true)] out string? platformName)
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.

🤖 💡 Nullable pattern — Consider adding a null check for consistency, even though it's unlikely to be null in practice.

The TryGetSimulatorAvailabilityPlatformName method uses [NotNullWhen (true)] but the subsequent helper methods (PrintSupportedSimulatorAttribute and PrintUnsupportedSimulatorAttribute) accept string platformName without nullable annotation. While the current usage is safe because both helpers are only called after TryGet... returns true, explicitly marking platformName as non-nullable in the helper signatures would make the contract clearer.

Alternative: Add ArgumentNullException.ThrowIfNull (platformName); at the start of each helper method, or change the parameter to string platformName with a debug assertion.

Rule: Nullable Reference Types

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #fc0a48a] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: fc0a48a92bc47f50670aa993d758c39b644f6a2d [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #fc0a48a] Build passed (Build packages) ✅

Pipeline on Agent
Hash: fc0a48a92bc47f50670aa993d758c39b644f6a2d [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: fc0a48a92bc47f50670aa993d758c39b644f6a2d [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #fc0a48a] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: fc0a48a92bc47f50670aa993d758c39b644f6a2d [PR build]

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants