[dotnet] Add support for .so files (#16887)

Autotools-based project using libtool's -module flag generate plugins
with the .so extension that needs to be treated like DynamicLibraries in
terms of deployment location and relocation, except they are not linked
to the app.

This PR adds support for such .so files: they're treated as .dylib files, except
that they're not linked to the app.
This commit is contained in:
Andoni Morales Alastruey 2023-02-03 09:16:40 +01:00 коммит произвёл GitHub
Родитель 7798c7c5f1
Коммит 97ab14801f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
12 изменённых файлов: 63 добавлений и 5 удалений

Просмотреть файл

@ -63,6 +63,7 @@ wrong, then developers can override the target location by:
* \*.framework.zip and \*.xcframework.zip:
`PublishFolderType=CompressedAppleFramework`
* \*.dylib: `PublishFolderType=DynamicLibrary`
* \*.so: `PublishFolderType=PluginLibrary`
* \*.a: `PublishFolderType=StaticLibrary`
* No other files are copied. We show a warning if we find any such files.
@ -174,6 +175,20 @@ The target directory is the same as for `Assembly`:
*Warning*: The App Store will reject any apps with \*.dylib files (for iOS and
tvOS, not for macOS or Mac Catalyst).
### PluginLibrary
These are plugins provided as un-versioned dynamic library (\*.so or \*.dylib) files.
An example are GStreamer plugins: `libgstogg.dylib`
We will _not_ link with these libraries when linking the native executable since
this type of plugins are loaded on demand at runtime.
The target directory is the same as for `DynamicLibrary`
*Warning*: The App Store will reject any apps with dynamic library files, for iOS and
tvOS plugins must be provided as static libraries.
### StaticLibrary
These are static libraries (\*.a) files.

Просмотреть файл

@ -1212,7 +1212,7 @@
</PropertyGroup>
<ItemGroup>
<!-- Create the ComputedRelativePath metadata from RelativePath -->
<_DynamicLibraryToReidentify Include="@(_FileNativeReference)" Condition="'%(Extension)' == '.dylib'">
<_DynamicLibraryToReidentify Include="@(_FileNativeReference)" Condition="'%(Kind)' == 'Dynamic'">
<SourceItemGroup>_FileNativeReference</SourceItemGroup>
<ComputedRelativePath>%(_FileNativeReference.RelativePath)</ComputedRelativePath>
</_DynamicLibraryToReidentify>
@ -1257,6 +1257,12 @@
Outputs="$(_IntermediateNativeLibraryDir)$(_NativeExecutableName);$(_MtouchSymbolsList)"
>
<ItemGroup Condition="'$(IsMacEnabled)' == 'true'">
<_NativeReferences Include="@(_FrameworkNativeReference)" />
<!-- Do not link native references with LinkToExecutable='false' such as PluginLibrary files -->
<_NativeReferences Include="@(_FileNativeReference)" Condition="'%(_FileNativeReference.LinkToExecutable)' != 'false'" />
</ItemGroup>
<LinkNativeCode
SessionId="$(BuildSessionId)"
DylibRPath="$(_DylibRPath)"
@ -1266,7 +1272,7 @@
LinkerFlags="@(_AssemblyLinkerFlags);@(_ReferencesLinkerFlags);@(_MainLinkerFlags);@(_CustomLinkFlags)"
LinkWithLibraries="@(_XamarinMainLibraries);@(_BindingLibraryLinkWith);@(_MainLinkWith)"
MinimumOSVersion="$(_MinimumOSVersion)"
NativeReferences="@(_FileNativeReference);@(_FrameworkNativeReference)"
NativeReferences="@(_NativeReferences)"
ObjectFiles="@(_NativeExecutableObjectFiles)"
OutputFile="$(_IntermediateNativeLibraryDir)$(_NativeExecutableName)"
SdkDevPath="$(_SdkDevPath)"
@ -1393,11 +1399,11 @@
Update="@(ResolvedFileToPublish)"
RelativePath="$(_AssemblyPublishDir)\%(ResolvedFileToPublish.DestinationSubDirectory)\%(ResolvedFileToPublish.TargetPath)"
Condition="'$(AppConfig)' != '' And '%(ResolvedFileToPublish.OriginalItemSpec)' == '$(AppConfig)' And '%(ResolvedFileToPublish.Link)' == 'app.config' And '%(ResolvedFileToPublish.TargetPath)' != ''" />
<!-- .dylib are never needed (nor allowed) for fully AOT'ed applications FIXME https://github.com/xamarin/xamarin-macios/issues/11145 -->
<!-- .dylib and .so are never needed (nor allowed) for fully AOT'ed applications FIXME https://github.com/xamarin/xamarin-macios/issues/11145 -->
<ResolvedFileToPublish
Update="@(ResolvedFileToPublish)"
RelativePath="$(_DylibPublishDir)\%(Filename)%(Extension)"
Condition="('$(_SdkIsSimulator)' != 'false' Or '$(_PlatformName)' == 'macOS' Or '$(_PlatformName)' == 'MacCatalyst') And '%(Extension)' == '.dylib'" />
Condition="('$(_SdkIsSimulator)' != 'false' Or '$(_PlatformName)' == 'macOS' Or '$(_PlatformName)' == 'MacCatalyst') And ('%(Extension)' == '.dylib' Or '%(Extension)' == '.so') " />
<!-- Don't publish any icu*dat file (by setting PublishFolderType = None) -->
<ResolvedFileToPublish
@ -1543,7 +1549,11 @@
<!-- we link with dynamic libraries, and we copy them to the app bundle (the copying part is handled in _ComputeDynamicLibrariesToPublish) -->
<_ResolvedFileToPublish_DynamicLibrary Include="@(ResolvedFileToPublish)" Condition="'%(ResolvedFileToPublish.PublishFolderType)' == 'DynamicLibrary'" />
<_FileNativeReference Include="@(_ResolvedFileToPublish_DynamicLibrary)" Kind="Dynamic" />
<!-- we link with dynamic libraries, and we copy them to the app bundle (the copying part is handled in _ComputeDynamicLibrariesToPublish) -->
<_ResolvedFileToPublish_PluginLibrary Include="@(ResolvedFileToPublish)" Condition="'%(ResolvedFileToPublish.PublishFolderType)' == 'PluginLibrary'" />
<_FileNativeReference Include="@(_ResolvedFileToPublish_PluginLibrary)" Kind="Dynamic" LinkToExecutable="false" />
<ResolvedFileToPublish Remove="@(_ResolvedFileToPublish_DynamicLibrary)" />
<ResolvedFileToPublish Remove="@(_ResolvedFileToPublish_PluginLibrary)" />
<!-- we link with the contents of binding resource packages, but the packages themselves aren't copied to the app bundle, so remove them here -->
<_AppleBindingResourcePackage Include="@(ResolvedFileToPublish)" Condition="'%(ResolvedFileToPublish.PublishFolderType)' == 'AppleBindingResourcePackage'" />

Просмотреть файл

@ -135,6 +135,9 @@ namespace Xamarin.MacDev.Tasks {
case PublishFolderType.DynamicLibrary:
relativePath = AssemblyDirectory;
break;
case PublishFolderType.PluginLibrary:
relativePath = AssemblyDirectory;
break;
case PublishFolderType.StaticLibrary:
// Nothing to do here.
continue;
@ -320,11 +323,13 @@ namespace Xamarin.MacDev.Tasks {
return PublishFolderType.CompressedAppleFramework;
}
// *.a and *.dylib
// *.a, *.dylib and *.so
if (filename.EndsWith (".a", StringComparison.OrdinalIgnoreCase)) {
return PublishFolderType.StaticLibrary;
} else if (filename.EndsWith (".dylib", StringComparison.OrdinalIgnoreCase)) {
return PublishFolderType.DynamicLibrary;
} else if (filename.EndsWith (".so", StringComparison.OrdinalIgnoreCase)) {
return PublishFolderType.PluginLibrary;
}
// no other files are copied
@ -363,6 +368,7 @@ namespace Xamarin.MacDev.Tasks {
PlugIns,
CompressedPlugIns,
DynamicLibrary, // link with + copy to app bundle
PluginLibrary, // copy to app bundle (but not link with main executable)
StaticLibrary, // link with (but not copy to app bundle)
Unknown,
}

Просмотреть файл

@ -0,0 +1 @@
NoneQ

Просмотреть файл

@ -0,0 +1 @@
NoneQ

Просмотреть файл

@ -0,0 +1 @@
NoneQ

Просмотреть файл

@ -54,6 +54,10 @@
<!-- Bundled, linked with -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(RootTestsDirectory)/test-libraries/libraries/.libs/$(RuntimeIdentifier)/libNoneE.so">
<!-- Bundled, not linked with -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(RootTestsDirectory)/test-libraries/libraries/.libs/$(RuntimeIdentifier)/libNoneF.a">
<!-- Not bundled; linked with -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@ -103,6 +107,10 @@
<!-- Bundled, linked with, install_name_tool must have been executed -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(RootTestsDirectory)/test-libraries/libraries/.libs/$(RuntimeIdentifier)/libSkipInstallNameTool.so">
<!-- Bundled, not linked with, install_name_tool must have been executed -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -0,0 +1 @@
NoneQ

Просмотреть файл

@ -120,6 +120,7 @@ namespace Xamarin.Tests {
expectedFiles.Add ($"{assemblyDirectory}NoneC.pdb");
expectedFiles.Add ($"{assemblyDirectory}NoneD.exe");
expectedFiles.Add ($"{assemblyDirectory}libNoneE.dylib");
expectedFiles.Add ($"{assemblyDirectory}libNoneE.so");
// NoneF.a is not bundled
// Sub/NoneG.txt is not bundled
// Sub/NoneH.txt is not bundled
@ -129,6 +130,7 @@ namespace Xamarin.Tests {
expectedFiles.Add ($"{assemblyDirectory}NoneL.config");
// NoneM.unknown is not bundled
expectedFiles.Add ($"{assemblyDirectory}libSkipInstallNameTool.dylib");
expectedFiles.Add ($"{assemblyDirectory}libSkipInstallNameTool.so");
expectedFiles.Add ($"{resourcesDirectory}basn3p08.png");
expectedFiles.Add ($"{resourcesDirectory}basn3p08_with_loc.png");
@ -335,6 +337,7 @@ namespace Xamarin.Tests {
Assert.That (missingFiles, Is.Empty, "No missing files");
AssertDynamicLibraryId (platform, appPath, assemblyDirectory, "libSkipInstallNameTool.dylib");
AssertDynamicLibraryId (platform, appPath, assemblyDirectory, "libSkipInstallNameTool.so");
AssertLibraryArchitectures (appPath, runtimeIdentifiers);
}

Просмотреть файл

@ -1218,6 +1218,7 @@ namespace Xamarin.Tests {
AssertThatDylibExistsAndIsReidentified (appPath, "libtest.dylib");
AssertThatDylibExistsAndIsReidentified (appPath, "/subdir/libtest.dylib");
AssertThatDylibExistsAndIsReidentified (appPath, "/subdir/libtest.so");
ExecuteWithMagicWordAndAssert (appExecutable);
}

Просмотреть файл

@ -35,6 +35,7 @@ $(1)_$(3)_TARGETS += \
.libs/$(3)/lib$(1).a \
.libs/$(3)/lib$(1).o \
.libs/$(3)/lib$(1).dylib \
.libs/$(3)/lib$(1).so \
$(3)_TARGETS += \
$$($(1)_$(3)_TARGETS) \
@ -56,6 +57,9 @@ endif
.libs/$(3)/lib$(1).a: .libs/$(3)/lib$(1).o
$$(call Q_2,AR [$(1)]) $(XCODE_DEVELOPER_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar cru $$@ $$<
.libs/$(3)/lib$(1).so: .libs/$(3)/lib$(1).dylib
$$(Q) $(CP) .libs/$(3)/lib$(1).dylib .libs/$(3)/lib$(1).so
$$($(3)_$(1)_DIRECTORIES):
$$(Q) mkdir -p $$@

Просмотреть файл

@ -7,5 +7,12 @@
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<PublishState>Included</PublishState>
</None>
<None Include="$(MSBuildThisFileDirectory)..\bin\$(RuntimeIdentifier)\libtest.dylib">
<Visible>false</Visible>
<Link>$(OutputDirectory)\subdir\%(FileName).so</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<PublishState>Included</PublishState>
</None>
</ItemGroup>
</Project>