Skip to content

Commit

Permalink
[release/7.0.3xx] [dotnet] Link Mono and Xamarin statically in Mac Ca…
Browse files Browse the repository at this point in the history
…talyst by default. Fixes #14686. (#19134)

It's possible to create a provisioning profile for Mac Catalyst that doesn't
allow dylibs in the app. It seems a significant number of people run into this
problem when publishing their apps, so avoid it by linking Mono and Xamarin
statically by default instead.

The downside is that build time might increase a little bit.

An upside however is that the app size might decrese somewhat.

Fixes #14686.

Backport of #18619

---------

Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
  • Loading branch information
1 parent 4ef3035 commit 0be2e28
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -922,11 +922,15 @@
<_AOTInputDirectory>$(_IntermediateNativeLibraryDir)aot-input/</_AOTInputDirectory>
<_AOTOutputDirectory>$(_IntermediateNativeLibraryDir)aot-output/</_AOTOutputDirectory>

<!-- default to 'static' for Mac Catalyst to work around https://github.com/xamarin/xamarin-macios/issues/14686 -->
<_LibMonoLinkMode Condition="'$(_LibMonoLinkMode)' == '' And '$(_PlatformName)' == 'MacCatalyst'">static</_LibMonoLinkMode>
<_LibMonoLinkMode Condition="'$(_LibMonoLinkMode)' == '' And ('$(ComputedPlatform)' != 'iPhone' Or '$(_PlatformName)' == 'macOS')">dylib</_LibMonoLinkMode>
<_LibMonoLinkMode Condition="'$(_LibMonoLinkMode)' == ''">static</_LibMonoLinkMode>
<_LibMonoExtension Condition="'$(_LibMonoLinkMode)' == 'dylib'">dylib</_LibMonoExtension>
<_LibMonoExtension Condition="'$(_LibMonoLinkMode)' == 'static'">a</_LibMonoExtension>

<!-- default to 'static' for Mac Catalyst to work around https://github.com/xamarin/xamarin-macios/issues/14686 -->
<_LibXamarinLinkMode Condition="'$(_LibXamarinLinkMode)' == '' And '$(_PlatformName)' == 'MacCatalyst'">static</_LibXamarinLinkMode>
<_LibXamarinLinkMode Condition="'$(_LibXamarinLinkMode)' == '' And '$(ComputedPlatform)' != 'iPhone' And '$(_PlatformName)' != 'macOS'">dylib</_LibXamarinLinkMode>
<_LibXamarinLinkMode Condition="'$(_LibXamarinLinkMode)' == ''">static</_LibXamarinLinkMode>
<_LibXamarinExtension Condition="'$(_LibXamarinLinkMode)' == 'dylib'">dylib</_LibXamarinExtension>
Expand Down
8 changes: 0 additions & 8 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,14 +1164,6 @@ public void CustomizedCodeSigning (ApplePlatform platform, string runtimeIdentif
var signedDylibs = new List<string> {
Path.Combine (sharedSupportDir, "app2.app", dylibDir, "lib2.dylib"),
};
if (platform == ApplePlatform.MacCatalyst) {
signedDylibs.Add (Path.Combine (dylibDir, "libSystem.IO.Compression.Native.dylib"));
signedDylibs.Add (Path.Combine (dylibDir, "libSystem.Native.dylib"));
signedDylibs.Add (Path.Combine (dylibDir, "libSystem.Net.Security.Native.dylib"));
signedDylibs.Add (Path.Combine (dylibDir, "libSystem.Security.Cryptography.Native.Apple.dylib"));
signedDylibs.Add (Path.Combine (dylibDir, "libmonosgen-2.0.dylib"));
signedDylibs.Add (Path.Combine (dylibDir, "libxamarin-dotnet-debug.dylib"));
}

foreach (var dylib in signedDylibs) {
var path = Path.Combine (appPath, dylib);
Expand Down
18 changes: 17 additions & 1 deletion tests/introspection/ApiPInvokeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,23 @@ protected void Check (Assembly a)
path = null;
break;
case "libSystem.Native":
path += ".dylib";
var staticallyLinked = false;
#if __MACCATALYST__
// always statically linked
staticallyLinked = true;
#elif __IOS__ || __TVOS__
// statically linked on device
staticallyLinked = Runtime.Arch == Arch.DEVICE;
#elif __MACOS__
// never statically linked (by default)
#else
#error Unknown platform
#endif
if (staticallyLinked) {
path = null;
} else {
path += ".dylib";
}
break;
#endif
case "libc":
Expand Down
3 changes: 3 additions & 0 deletions tools/linker/MonoTouch.Tuner/ListExportedSymbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ bool ProcessMethod (MethodDefinition method)
Where (v => v.EndsWith (".dylib", StringComparison.OrdinalIgnoreCase) || v.EndsWith (".a", StringComparison.OrdinalIgnoreCase)).
Select (v => Path.GetFileNameWithoutExtension (v)).
Select (v => v.StartsWith ("lib", StringComparison.OrdinalIgnoreCase) ? v.Substring (3) : v).ToHashSet ();
#if !__MACOS__
monoLibraryVariations.Add ("System.Globalization.Native"); // System.Private.CoreLib has P/Invokes pointing to libSystem.Globalization.Native, but they're actually in libmonosgen-2.0
#endif
monoLibraryVariations.UnionWith (monoLibraryVariations.Select (v => "lib" + v).ToArray ());
monoLibraryVariations.UnionWith (monoLibraryVariations.Select (v => v + ".dylib").ToArray ());
// If the P/Invoke points to any of those libraries, then we add it as a P/Invoke symbol.
Expand Down

4 comments on commit 0be2e28

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

Choose a reason for hiding this comment

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

💻 [CI Build] Tests on macOS M1 - Mac Ventura (13.0) passed 💻

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

Pipeline on Agent
Hash: 0be2e2879b06b7b6b61c2b603b32e47b69a27f9f [CI build]

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

Choose a reason for hiding this comment

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

💻 [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: 0be2e2879b06b7b6b61c2b603b32e47b69a27f9f [CI build]

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

Choose a reason for hiding this comment

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

✅ API diff for current PR / commit

NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

.NET (No breaking changes)

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: 0be2e2879b06b7b6b61c2b603b32e47b69a27f9f [CI build]

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

Choose a reason for hiding this comment

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

🚀 [CI Build] Test results 🚀

Test results

✅ All tests passed on VSTS: simulator tests.

🎉 All 79 tests passed 🎉

Tests counts

⚠️ bcl: No tests selected. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ framework: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 1 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 4 tests passed. Html Report (VSDrops) Download
⚠️ install_source: No tests selected. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker: All 40 tests passed. Html Report (VSDrops) Download
⚠️ mac_binding_project: No tests selected. Html Report (VSDrops) Download
⚠️ mmp: No tests selected. Html Report (VSDrops) Download
⚠️ mononative: No tests selected. Html Report (VSDrops) Download
✅ monotouch: All 13 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
⚠️ mtouch: No tests selected. Html Report (VSDrops) Download
⚠️ xammac: No tests selected. 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: 0be2e2879b06b7b6b61c2b603b32e47b69a27f9f [CI build]

Please sign in to comment.