[runtime] Generate trusted platform assemblies at build time Fixes #16744 - #26245
[runtime] Generate trusted platform assemblies at build time Fixes #16744#26245rolfbjarne wants to merge 16 commits into
Conversation
Generate trusted platform assembly data from final publish items for non-debug builds while retaining runtime discovery for debug builds. Optimize single-RID startup and preserve universal bundle handling on supported platforms. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b6c903d4-d655-47d4-9e0c-636bea8e7d37
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…he dylib Commit fae4375 made the runtime reference three symbols that are generated at app build time (GenerateTrustedPlatformAssemblySource): xamarin_trusted_platform_assemblies, xamarin_trusted_platform_assembly_count and xamarin_is_multi_rid_build. They're declared weak_import in main.h, with a runtime null-check fallback for debug builds where they aren't generated. The compiler correctly emits them as weak external undefined, but the Xcode 26 linker still errors ("Undefined symbols ...") when building the standalone libxamarin-dotnet.dylib, because no linked dylib exports them. Pass -Wl,-U for each of these symbols so they're allowed to be undefined (resolved via dynamic lookup) in the runtime dylib. The final app link provides the real definitions, and debug builds keep resolving them to NULL via weak_import. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4aa93657-2767-43e8-ab51-f761657b87fd
There was a problem hiding this comment.
Pull request overview
This PR reduces startup overhead by generating the trusted platform assemblies (TPA) list at build time for non-Debug builds, so the runtime can avoid enumerating the app bundle on startup (fixing #16744). Debug builds keep the existing runtime discovery behavior to avoid extra build work.
Changes:
- Add an MSBuild task to generate per-architecture native source containing the TPA names and count, and compile it into the native executable inputs.
- Update the runtime to prefer the build-time generated TPA list (with a fallback to runtime discovery when symbols aren’t present).
- Document the new
GenerateTrustedPlatformAssembliesbuild property and add task-level unit tests.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GenerateTrustedPlatformAssemblySourceTests.cs | Adds unit tests validating filtering, ordering, escaping, and Multi-RID behavior of the generated TPA source. |
| runtime/xamarin/main.h | Declares weak-imported build-time TPA symbols and introduces a platform macro for universal-build support. |
| runtime/runtime.m | Switches xamarin_compute_trusted_platform_assemblies to use build-time TPA symbols when available, with Multi-RID handling on supported platforms. |
| runtime/Makefile | Allows weak undefined references to the new build-time TPA symbols when building the runtime dylib. |
| msbuild/Xamarin.MacDev.Tasks/Tasks/GenerateTrustedPlatformAssemblySource.cs | New task that generates native source for the TPA list/count and optional Multi-RID flag. |
| dotnet/targets/Xamarin.Shared.Sdk.targets | Wires in the new task/target, defaults property based on Debug, compiles generated sources, and forces export of the new native symbols. |
| docs/building-apps/build-properties.md | Documents GenerateTrustedPlatformAssemblies and its default behavior. |
Comments suppressed due to low confidence (2)
runtime/xamarin/main.h:139
- Use the corrected macro name here as well ("SUPPORTS_UNIVERSAL_BUILDS"), to match the definition and avoid inconsistencies.
#if defined (SUPPORTS_UNIVERAL_BUILDS)
extern const bool xamarin_is_multi_rid_build __attribute__ ((weak_import));
#endif
runtime/runtime.m:2406
- Typo in the macro name: "UNIVERAL" should be "UNIVERSAL" (and match the header + generated source).
#if defined (SUPPORTS_UNIVERAL_BUILDS)
if (xamarin_is_multi_rid_build) {
Resolve the overlapping bundler-debug defaults, correct the universal-build macro spelling, and safely fall back when generated weak TPA symbols are incomplete. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b6c903d4-d655-47d4-9e0c-636bea8e7d37
Define runtime defaults for trusted platform assembly data and initialize the final single-RID value from the generated main source. Keep runtime path adjustment only for universal builds and remove the extra native source compilation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b6c903d4-d655-47d4-9e0c-636bea8e7d37
Return a caller-owned copy of the generated trusted platform assembly string so xamarin_vm_initialize can free it safely. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b6c903d4-d655-47d4-9e0c-636bea8e7d37
This comment has been minimized.
This comment has been minimized.
Embed a constant array of assembly filenames in generated main and construct full trusted platform assembly paths at runtime. Probe for RID-specific paths only in multi-RID builds. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b6c903d4-d655-47d4-9e0c-636bea8e7d37
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Preserve external linkage for the runtime trusted platform assembly discovery helper. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b6c903d4-d655-47d4-9e0c-636bea8e7d37
Apply the expected size updates produced by AppSizeTest for the current PR build. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b6c903d4-d655-47d4-9e0c-636bea8e7d37
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b6c903d4-d655-47d4-9e0c-636bea8e7d37
…ue-16744-generate-the-result
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ue-16744-generate-the-result
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ue-16744-generate-the-result
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🚀 [CI Build #d218bdd] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 204 tests passed 🎉 Tests counts✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Generate the trusted platform assembly list from final publish items for non-debug builds, avoiding app bundle enumeration during startup.
Retain runtime discovery for debug builds to minimize build overhead, optimize single-RID path expansion, and preserve universal bundle handling on supported platforms.
Fixes #16744
🤖 Pull request created by Copilot