[tools/msbuild] Add support for mergeable libraries. Fixes #20262.#24710
[tools/msbuild] Add support for mergeable libraries. Fixes #20262.#24710rolfbjarne wants to merge 10 commits intomainfrom
Conversation
Add support for detecting and stripping mergeable library metadata (LC_ATOM_INFO) from frameworks embedded in app bundles. Mergeable libraries are dylibs/frameworks built with -make_mergeable that contain extra static linking metadata, roughly doubling their size. When used as dynamic libraries, this metadata is unnecessary. Changes: - Add LC_ATOM_INFO (0x36) to LoadCommands enum in MachO.cs - Add HasAtomInfo property and IsMergeableLibrary() method for detection - Add -no_atom_info flag to SymbolStrip task when stripping frameworks - Add tests for detection and stripping of mergeable libraries Fixes #20262
Add a new StripMergeableLibraries MSBuild property that controls whether LC_ATOM_INFO (mergeable library metadata) is stripped from frameworks during symbol stripping. The property defaults to the value of Optimize, so Release builds strip the metadata (reducing app size) while Debug builds preserve it. Changes: - SymbolStrip task: add StripMergeableLibraries property, conditionally pass -no_atom_info to strip. - Xamarin.Shared.props: define StripMergeableLibraries defaulting to Optimize. - Xamarin.Shared.targets: pass StripMergeableLibraries to SymbolStrip. - test-libraries: add XMergeableTest framework built with -Wl,-make_mergeable, including plists for all RIDs. - NativeMergeableFrameworkReferencesApp: test app that references the mergeable framework. - ProjectTest.cs: add test cases for building the mergeable framework app and verifying atom info stripping behavior. - MergeableLibraryTests.cs: add test for preserving atom info when StripMergeableLibraries is false.
Add a binding project that embeds the XMergeableTest mergeable framework, with pack tests verifying the nupkg contains the framework correctly. - bindings-framework-test/dotnet-mergeable: binding project referencing XMergeableTest.framework with IsBindingProject=true. - PackTest.cs: BindingMergeableFrameworksProject test verifying dotnet pack produces correct nupkg structure with the mergeable framework. - ProjectTest.cs: BuildNativeMergeableFrameworkReferencesApp_AtomInfoStripping test verifying atom info is stripped when Optimize=true and preserved when Optimize=false.
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.
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.
Add a new StripMergeableLibraryMetadata MSBuild task and target that strips LC_ATOM_INFO from frameworks in the app bundle. This runs independently of the regular symbol stripping (_NativeStripFiles), which is disabled for simulator builds, debug builds, and macOS/MacCatalyst. The new task: - Scans the app bundle's Frameworks directory for .framework directories - Checks each framework executable with MachO.IsMergeableLibrary() - Only strips frameworks that actually have LC_ATOM_INFO - Runs strip -no_atom_info on matching frameworks This ensures mergeable library metadata is stripped when StripMergeableLibraries=true (i.e. Optimize=true), regardless of whether NoSymbolStrip is enabled.
- Remove RuntimeIdentifier from NativeMergeableFrameworkReferencesApp platform projects (default values are chosen automatically). - Add NativeMergeableDylibReferencesApp test app referencing a standalone mergeable dylib (libMergeableFramework.dylib). - Add libMergeableFramework.dylib build rule in test-libraries Makefile. - Extend StripMergeableLibraryMetadata task to also scan dylib directories (e.g. MonoBundle) for mergeable libraries. - Add BuildNativeMergeableDylibReferencesApp_AtomInfoStripping test verifying dylib atom info stripping behavior. All 8 integration tests and 10 unit tests pass.
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.
The XMergeableTest framework is always packaged as a .resources.zip in the nupkg, regardless of platform. Remove the per-platform symlink check that incorrectly expected individual files for iOS and tvOS.
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.
tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/MergeableLibraryTests.cs
Outdated
Show resolved
Hide resolved
- Document StripMergeableLibraries property in build-properties.md
- Remove [Category ("Multiplatform")] from BindingMergeableFrameworksProject test
- Replace custom RunProcess with ExecutionHelper in MergeableLibraryTests
✅ [CI Build #1a5150c] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #1a5150c] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ 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 #1a5150c] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #1a5150c] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #1a5150c] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #1a5150c] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #1a5150c] Tests on macOS arm64 - Mac Tahoe (26) passed 💻✅ All tests on macOS arm64 - Mac Tahoe (26) passed. Pipeline on Agent |
💻 [CI Build #1a5150c] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
🔥 [CI Build #1a5150c] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 3 tests failed, 128 tests passed. Failures❌ linker tests3 tests failed, 41 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
WIP WIP WIP.
Fixes #20262.