Skip to content

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

Merged
rolfbjarne merged 25 commits into
mainfrom
dev/rolf/mergeable-libraries
Sep 10, 2026
Merged

rolfbjarne merged 25 commits into
mainfrom
dev/rolf/mergeable-libraries

Conversation

@rolfbjarne

@rolfbjarne rolfbjarne commented Feb 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds MSBuild support for mergeable libraries by detecting mergeable framework/dylib metadata and stripping it when requested during native reference processing.

This includes:

  • a new StripMergeableLibraries build property
  • a StripMergeableLibraryMetadata task wired into native reference handling
  • Mach-O support for detecting mergeable-library atom info
  • tests for mergeable frameworks and dylibs across Apple platforms
  • documentation for the new build property

Testing

  • Added unit/task coverage for mergeable library stripping behavior.
  • Added pack/project test coverage for mergeable framework and dylib references.

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.

@rolfbjarne rolfbjarne added the ready-to-review This PR is ready to review/merge. label Sep 7, 2026
dalexsoto
dalexsoto previously approved these changes Sep 7, 2026
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne removed the ready-to-review This PR is ready to review/merge. label Sep 7, 2026
rolfbjarne and others added 2 commits September 7, 2026 18:30
Hash each absolute library path before creating its incremental stamp file. This keeps stamp names deterministic and unique without exceeding the filesystem's per-component length limit for deeply nested app bundles.

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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 35b9fddd-0b2f-4427-9990-90225546e53a
@rolfbjarne rolfbjarne added the ready-to-review This PR is ready to review/merge. label Sep 8, 2026
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne removed the ready-to-review This PR is ready to review/merge. label Sep 8, 2026
@rolfbjarne rolfbjarne added the ready-to-review This PR is ready to review/merge. label Sep 8, 2026
@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: 1b2afec17a6d00607843a89f66efa21add10eef3 [PR build]

@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 #1b2afec] Test results πŸš€

Test results

βœ… All tests passed on VSTS: test results.

πŸŽ‰ All 264 tests passed πŸŽ‰

Tests counts

βœ… assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
βœ… 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 7 tests passed. Html Report (VSDrops) Download
βœ… linker (iOS): All 31 tests passed. Html Report (VSDrops) Download
βœ… linker (MacCatalyst): All 31 tests passed. Html Report (VSDrops) Download
βœ… linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
βœ… linker (tvOS): All 31 tests passed. Html Report (VSDrops) Download
βœ… monotouch (iOS): All 25 tests passed. [attempt 3] Html Report (VSDrops) Download
βœ… monotouch (MacCatalyst): All 25 tests passed. Html Report (VSDrops) Download
βœ… monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
βœ… monotouch (tvOS): All 25 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

macOS tests

βœ… 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. [attempt 2] Html Report (VSDrops) Download

Linux Build Verification

βœ… Linux build succeeded

Pipeline on Agent
Hash: 1b2afec17a6d00607843a89f66efa21add10eef3 [PR build]

@rolfbjarne
rolfbjarne merged commit 482d490 into main Sep 10, 2026
54 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/mergeable-libraries branch September 10, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot ready-to-review This PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for mergeable libraries

5 participants