Skip to content

[tools/msbuild] Add support for mergeable libraries. Fixes #20262.#24710

Draft
rolfbjarne wants to merge 10 commits intomainfrom
dev/rolf/mergeable-libraries
Draft

[tools/msbuild] Add support for mergeable libraries. Fixes #20262.#24710
rolfbjarne wants to merge 10 commits intomainfrom
dev/rolf/mergeable-libraries

Conversation

@rolfbjarne
Copy link
Member

WIP WIP WIP.

Fixes #20262.

rolfbjarne and others added 4 commits February 12, 2026 17:25
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.
@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

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.

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.
@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.

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.
@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.

- Document StripMergeableLibraries property in build-properties.md
- Remove [Category ("Multiplatform")] from BindingMergeableFrameworksProject test
- Replace custom RunProcess with ExecutionHelper in MergeableLibraryTests
@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #1a5150c] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 1a5150c6fedf0f4252fc0597e2f91d7175de1e23 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

Pipeline on Agent
Hash: 1a5150c6fedf0f4252fc0597e2f91d7175de1e23 [PR build]

@vs-mobiletools-engineering-service2
Copy link
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: 1a5150c6fedf0f4252fc0597e2f91d7175de1e23 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #1a5150c] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 1a5150c6fedf0f4252fc0597e2f91d7175de1e23 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #1a5150c] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 1a5150c6fedf0f4252fc0597e2f91d7175de1e23 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #1a5150c] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 1a5150c6fedf0f4252fc0597e2f91d7175de1e23 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #1a5150c] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 1a5150c6fedf0f4252fc0597e2f91d7175de1e23 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #1a5150c] Tests on macOS arm64 - Mac Tahoe (26) passed 💻

All tests on macOS arm64 - Mac Tahoe (26) passed.

Pipeline on Agent
Hash: 1a5150c6fedf0f4252fc0597e2f91d7175de1e23 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #1a5150c] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 1a5150c6fedf0f4252fc0597e2f91d7175de1e23 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #1a5150c] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 3 tests failed, 128 tests passed.

Failures

❌ linker tests

3 tests failed, 41 tests passed.

Failed tests

  • link all/iOS - simulator/Release: LaunchFailure
  • trimmode copy/iOS - simulator/Release: LaunchFailure
  • trimmode link/iOS - simulator/Debug: LaunchFailure

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
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) 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

Pipeline on Agent
Hash: 1a5150c6fedf0f4252fc0597e2f91d7175de1e23 [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.

Add support for mergeable libraries

2 participants

Comments