-
Notifications
You must be signed in to change notification settings - Fork 576
[tools/msbuild] Add support for mergeable libraries. Fixes #20262. #24710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rolfbjarne
wants to merge
24
commits into
main
Choose a base branch
from
dev/rolf/mergeable-libraries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
13a839f
[msbuild] Add support for stripping mergeable library metadata
rolfbjarne fcd6b2b
[msbuild] Add StripMergeableLibraries property and test infrastructure
rolfbjarne ace8553
[tests] Add mergeable framework binding project and pack test
rolfbjarne 9ebf2af
Auto-format source code
ac502d3
[msbuild] Fix mergeable library stripping for all build configurations
rolfbjarne 140eb62
[tests] Add mergeable dylib test and remove hardcoded RuntimeIdentifiers
rolfbjarne 2c4267d
[tests] Use arm64 runtime identifiers in mergeable library tests
rolfbjarne c5264a1
Merge remote-tracking branch 'origin/main' into dev/rolf/mergeable-li…
rolfbjarne 6fa9a8d
[tests] Fix BindingMergeableFrameworksProject nupkg content assertions
rolfbjarne 1a5150c
[review] Address PR review comments
rolfbjarne 57b4643
Merge origin/main into dev/rolf/mergeable-libraries
rolfbjarne 892215e
Restore BindingXcFrameworksProject iOS test case
rolfbjarne b300d98
Address mergeable library review feedback
rolfbjarne c8cd8fe
Merge remote-tracking branch 'origin/main' into dev/rolf/mergeable-li…
rolfbjarne d2bb947
[msbuild] Fix stripping universal mergeable dylibs
rolfbjarne c312fa8
Merge remote-tracking branch 'origin/main' into dev/rolf/mergeable-li…
rolfbjarne 14f99e6
Address mergeable library review comments
rolfbjarne ce1c8a1
Simplify mergeable library stamps
rolfbjarne 729ba3d
Merge remote-tracking branch 'origin/main' into dev/rolf/mergeable-li…
rolfbjarne 8b80584
Merge branch 'main' into dev/rolf/mergeable-libraries
rolfbjarne 57b3041
[msbuild] Keep mergeable library stamp names short
rolfbjarne ab786e1
Merge remote-tracking branch 'origin/main' into dev/rolf/mergeable-li…
rolfbjarne 9b613b8
Merge remote-tracking branch 'origin/main' into dev/rolf/mergeable-li…
rolfbjarne 6fe310c
Add license header to mergeable library task
rolfbjarne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
msbuild/Xamarin.MacDev.Tasks/Tasks/StripMergeableLibraryMetadata.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
|
|
||
| using Microsoft.Build.Framework; | ||
| using Xamarin.Messaging.Build.Client; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Xamarin.MacDev.Tasks { | ||
| // Strips LC_ATOM_INFO (mergeable library metadata) from frameworks and dylibs in an app bundle. | ||
| public class StripMergeableLibraryMetadata : XamarinTask, ITaskCallback { | ||
| #region Inputs | ||
|
|
||
| // The Frameworks directory inside the app bundle. | ||
| public string FrameworksDirectory { get; set; } = string.Empty; | ||
|
|
||
| // Additional directories to scan for mergeable dylibs (e.g. MonoBundle). | ||
| public string [] DylibDirectories { get; set; } = []; | ||
|
|
||
| public string StripPath { get; set; } = string.Empty; | ||
|
|
||
| #endregion | ||
|
|
||
| public override bool Execute () | ||
| { | ||
| if (ShouldExecuteRemotely ()) | ||
| return ExecuteRemotely (); | ||
|
|
||
| StripFrameworks (); | ||
| StripDylibs (); | ||
|
|
||
| return !Log.HasLoggedErrors; | ||
| } | ||
|
|
||
| void StripFrameworks () | ||
| { | ||
| if (string.IsNullOrEmpty (FrameworksDirectory) || !Directory.Exists (FrameworksDirectory)) | ||
| return; | ||
|
|
||
| foreach (var framework in Directory.GetDirectories (FrameworksDirectory, "*.framework")) { | ||
| var name = Path.GetFileNameWithoutExtension (framework); | ||
| var executable = Path.Combine (framework, name); | ||
| StripIfMergeable (executable); | ||
| } | ||
| } | ||
|
|
||
| void StripDylibs () | ||
| { | ||
| if (DylibDirectories is null) | ||
| return; | ||
|
|
||
| foreach (var dir in DylibDirectories) { | ||
| if (string.IsNullOrEmpty (dir) || !Directory.Exists (dir)) | ||
| continue; | ||
|
|
||
| foreach (var dylib in Directory.GetFiles (dir, "*.dylib")) { | ||
| StripIfMergeable (dylib); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void StripIfMergeable (string path) | ||
| { | ||
| if (!File.Exists (path)) | ||
| return; | ||
|
|
||
| if (!MachO.IsMergeableLibrary (path)) { | ||
| Log.LogMessage (MessageImportance.Low, $"Not a mergeable library: {path}"); | ||
| return; | ||
| } | ||
|
|
||
| Log.LogMessage (MessageImportance.Normal, $"Stripping mergeable library metadata from: {path}"); | ||
|
|
||
| var args = new List<string> (); | ||
| var stripExecutable = GetExecutable (args, "strip", StripPath); | ||
| args.Add ("-no_atom_info"); | ||
| args.Add ("-S"); | ||
| args.Add (Path.GetFullPath (path)); | ||
| ExecuteAsync (stripExecutable, args).Wait (); | ||
| } | ||
|
|
||
| public bool ShouldCopyToBuildServer (ITaskItem item) => false; | ||
|
|
||
| public bool ShouldCreateOutputFile (ITaskItem item) => false; | ||
|
|
||
| public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied () => Enumerable.Empty<ITaskItem> (); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tests/dotnet/NativeMergeableDylibReferencesApp/AppDelegate.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| using Foundation; | ||
|
|
||
| namespace NativeMergeableDylibReferencesApp { | ||
| public class Program { | ||
| [DllImport ("libMergeableFramework.dylib")] | ||
| static extern int theUltimateAnswer (); | ||
|
|
||
| static int Main (string [] args) | ||
| { | ||
| Console.WriteLine ($"Mergeable Dynamic library: {theUltimateAnswer ()}"); | ||
|
|
||
| GC.KeepAlive (typeof (NSObject)); // prevent linking away the platform assembly | ||
|
|
||
| Console.WriteLine (Environment.GetEnvironmentVariable ("MAGIC_WORD")); | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
...et/NativeMergeableDylibReferencesApp/MacCatalyst/NativeMergeableDylibReferencesApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-maccatalyst</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| TOP=../../.. | ||
| include $(TOP)/tests/common/shared-dotnet-test.mk |
7 changes: 7 additions & 0 deletions
7
tests/dotnet/NativeMergeableDylibReferencesApp/iOS/NativeMergeableDylibReferencesApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-ios</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
7 changes: 7 additions & 0 deletions
7
...s/dotnet/NativeMergeableDylibReferencesApp/macOS/NativeMergeableDylibReferencesApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-macos</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
20 changes: 20 additions & 0 deletions
20
tests/dotnet/NativeMergeableDylibReferencesApp/shared.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
|
|
||
| <ApplicationTitle>NativeMergeableDylibReferencesApp</ApplicationTitle> | ||
| <ApplicationId>com.xamarin.nativemergeabledylibreferences</ApplicationId> | ||
| <ApplicationVersion>1.0</ApplicationVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <Import Project="../../common/shared-dotnet.csproj" /> | ||
|
|
||
| <ItemGroup> | ||
| <NativeReference Include="..\..\..\test-libraries\.libs\$(NativeLibName)\libMergeableFramework.dylib" Kind="Dynamic" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="../*.cs" /> | ||
| </ItemGroup> | ||
| </Project> |
7 changes: 7 additions & 0 deletions
7
tests/dotnet/NativeMergeableDylibReferencesApp/tvOS/NativeMergeableDylibReferencesApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-tvos</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
22 changes: 22 additions & 0 deletions
22
tests/dotnet/NativeMergeableFrameworkReferencesApp/AppDelegate.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| using Foundation; | ||
|
|
||
| namespace NativeMergeableFrameworkReferencesApp { | ||
| public class Program { | ||
| [DllImport ("XMergeableTest.framework/XMergeableTest")] | ||
| static extern int theUltimateAnswer (); | ||
|
|
||
| static int Main (string [] args) | ||
| { | ||
| Console.WriteLine ($"Mergeable Framework: {theUltimateAnswer ()}"); | ||
|
|
||
| GC.KeepAlive (typeof (NSObject)); // prevent linking away the platform assembly | ||
|
|
||
| Console.WriteLine (Environment.GetEnvironmentVariable ("MAGIC_WORD")); | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
...eMergeableFrameworkReferencesApp/MacCatalyst/NativeMergeableFrameworkReferencesApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-maccatalyst</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| TOP=../../.. | ||
| include $(TOP)/tests/common/shared-dotnet-test.mk |
7 changes: 7 additions & 0 deletions
7
...et/NativeMergeableFrameworkReferencesApp/iOS/NativeMergeableFrameworkReferencesApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-ios</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
7 changes: 7 additions & 0 deletions
7
.../NativeMergeableFrameworkReferencesApp/macOS/NativeMergeableFrameworkReferencesApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-macos</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
20 changes: 20 additions & 0 deletions
20
tests/dotnet/NativeMergeableFrameworkReferencesApp/shared.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
|
|
||
| <ApplicationTitle>NativeMergeableFrameworkReferencesApp</ApplicationTitle> | ||
| <ApplicationId>com.xamarin.nativemergeableframeworkreferences</ApplicationId> | ||
| <ApplicationVersion>1.0</ApplicationVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <Import Project="../../common/shared-dotnet.csproj" /> | ||
|
|
||
| <ItemGroup> | ||
| <NativeReference Include="..\..\..\test-libraries\.libs\$(NativeLibName)\XMergeableTest.framework" Kind="Framework" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="../*.cs" /> | ||
| </ItemGroup> | ||
| </Project> |
7 changes: 7 additions & 0 deletions
7
...t/NativeMergeableFrameworkReferencesApp/tvOS/NativeMergeableFrameworkReferencesApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-tvos</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.