Skip to content

Commit c6dc43c

Browse files
[release/7.0.2xx] [dotnet] Add support for .so files (#17440)
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 depends on #16706 Backport of #16887 Co-authored-by: Andoni Morales Alastruey <[email protected]>
1 parent 18b517f commit c6dc43c

File tree

12 files changed

+63
-5
lines changed

12 files changed

+63
-5
lines changed

dotnet/BundleContents.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ wrong, then developers can override the target location by:
6363
* \*.framework.zip and \*.xcframework.zip:
6464
`PublishFolderType=CompressedAppleFramework`
6565
* \*.dylib: `PublishFolderType=DynamicLibrary`
66+
* \*.so: `PublishFolderType=PluginLibrary`
6667
* \*.a: `PublishFolderType=StaticLibrary`
6768
* No other files are copied. We show a warning if we find any such files.
6869

@@ -174,6 +175,20 @@ The target directory is the same as for `Assembly`:
174175
*Warning*: The App Store will reject any apps with \*.dylib files (for iOS and
175176
tvOS, not for macOS or Mac Catalyst).
176177

178+
### PluginLibrary
179+
180+
These are plugins provided as un-versioned dynamic library (\*.so or \*.dylib) files.
181+
182+
An example are GStreamer plugins: `libgstogg.dylib`
183+
184+
We will _not_ link with these libraries when linking the native executable since
185+
this type of plugins are loaded on demand at runtime.
186+
187+
The target directory is the same as for `DynamicLibrary`
188+
189+
*Warning*: The App Store will reject any apps with dynamic library files, for iOS and
190+
tvOS plugins must be provided as static libraries.
191+
177192
### StaticLibrary
178193

179194
These are static libraries (\*.a) files.

dotnet/targets/Xamarin.Shared.Sdk.targets

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@
11881188
</PropertyGroup>
11891189
<ItemGroup>
11901190
<!-- Create the ComputedRelativePath metadata from RelativePath -->
1191-
<_DynamicLibraryToReidentify Include="@(_FileNativeReference)" Condition="'%(Extension)' == '.dylib'">
1191+
<_DynamicLibraryToReidentify Include="@(_FileNativeReference)" Condition="'%(Kind)' == 'Dynamic'">
11921192
<SourceItemGroup>_FileNativeReference</SourceItemGroup>
11931193
<ComputedRelativePath>%(_FileNativeReference.RelativePath)</ComputedRelativePath>
11941194
</_DynamicLibraryToReidentify>
@@ -1233,6 +1233,12 @@
12331233
Outputs="$(_IntermediateNativeLibraryDir)$(_NativeExecutableName);$(_MtouchSymbolsList)"
12341234
>
12351235

1236+
<ItemGroup Condition="'$(IsMacEnabled)' == 'true'">
1237+
<_NativeReferences Include="@(_FrameworkNativeReference)" />
1238+
<!-- Do not link native references with LinkToExecutable='false' such as PluginLibrary files -->
1239+
<_NativeReferences Include="@(_FileNativeReference)" Condition="'%(_FileNativeReference.LinkToExecutable)' != 'false'" />
1240+
</ItemGroup>
1241+
12361242
<LinkNativeCode
12371243
SessionId="$(BuildSessionId)"
12381244
DylibRPath="$(_DylibRPath)"
@@ -1242,7 +1248,7 @@
12421248
LinkerFlags="@(_AssemblyLinkerFlags);@(_ReferencesLinkerFlags);@(_MainLinkerFlags);@(_CustomLinkFlags)"
12431249
LinkWithLibraries="@(_XamarinMainLibraries);@(_BindingLibraryLinkWith);@(_MainLinkWith)"
12441250
MinimumOSVersion="$(_MinimumOSVersion)"
1245-
NativeReferences="@(_FileNativeReference);@(_FrameworkNativeReference)"
1251+
NativeReferences="@(_NativeReferences)"
12461252
ObjectFiles="@(_NativeExecutableObjectFiles)"
12471253
OutputFile="$(_IntermediateNativeLibraryDir)$(_NativeExecutableName)"
12481254
SdkDevPath="$(_SdkDevPath)"
@@ -1369,11 +1375,11 @@
13691375
Update="@(ResolvedFileToPublish)"
13701376
RelativePath="$(_AssemblyPublishDir)\%(ResolvedFileToPublish.DestinationSubDirectory)\%(ResolvedFileToPublish.TargetPath)"
13711377
Condition="'$(AppConfig)' != '' And '%(ResolvedFileToPublish.OriginalItemSpec)' == '$(AppConfig)' And '%(ResolvedFileToPublish.Link)' == 'app.config' And '%(ResolvedFileToPublish.TargetPath)' != ''" />
1372-
<!-- .dylib are never needed (nor allowed) for fully AOT'ed applications FIXME https://github.com/xamarin/xamarin-macios/issues/11145 -->
1378+
<!-- .dylib and .so are never needed (nor allowed) for fully AOT'ed applications FIXME https://github.com/xamarin/xamarin-macios/issues/11145 -->
13731379
<ResolvedFileToPublish
13741380
Update="@(ResolvedFileToPublish)"
13751381
RelativePath="$(_DylibPublishDir)\%(Filename)%(Extension)"
1376-
Condition="('$(_SdkIsSimulator)' != 'false' Or '$(_PlatformName)' == 'macOS' Or '$(_PlatformName)' == 'MacCatalyst') And '%(Extension)' == '.dylib'" />
1382+
Condition="('$(_SdkIsSimulator)' != 'false' Or '$(_PlatformName)' == 'macOS' Or '$(_PlatformName)' == 'MacCatalyst') And ('%(Extension)' == '.dylib' Or '%(Extension)' == '.so') " />
13771383

13781384
<!-- Don't publish any icu*dat file (by setting PublishFolderType = None) -->
13791385
<ResolvedFileToPublish
@@ -1519,7 +1525,11 @@
15191525
<!-- we link with dynamic libraries, and we copy them to the app bundle (the copying part is handled in _ComputeDynamicLibrariesToPublish) -->
15201526
<_ResolvedFileToPublish_DynamicLibrary Include="@(ResolvedFileToPublish)" Condition="'%(ResolvedFileToPublish.PublishFolderType)' == 'DynamicLibrary'" />
15211527
<_FileNativeReference Include="@(_ResolvedFileToPublish_DynamicLibrary)" Kind="Dynamic" />
1528+
<!-- we link with dynamic libraries, and we copy them to the app bundle (the copying part is handled in _ComputeDynamicLibrariesToPublish) -->
1529+
<_ResolvedFileToPublish_PluginLibrary Include="@(ResolvedFileToPublish)" Condition="'%(ResolvedFileToPublish.PublishFolderType)' == 'PluginLibrary'" />
1530+
<_FileNativeReference Include="@(_ResolvedFileToPublish_PluginLibrary)" Kind="Dynamic" LinkToExecutable="false" />
15221531
<ResolvedFileToPublish Remove="@(_ResolvedFileToPublish_DynamicLibrary)" />
1532+
<ResolvedFileToPublish Remove="@(_ResolvedFileToPublish_PluginLibrary)" />
15231533

15241534
<!-- we link with the contents of binding resource packages, but the packages themselves aren't copied to the app bundle, so remove them here -->
15251535
<_AppleBindingResourcePackage Include="@(ResolvedFileToPublish)" Condition="'%(ResolvedFileToPublish.PublishFolderType)' == 'AppleBindingResourcePackage'" />

msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeBundleLocationTaskBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ public override bool Execute ()
135135
case PublishFolderType.DynamicLibrary:
136136
relativePath = AssemblyDirectory;
137137
break;
138+
case PublishFolderType.PluginLibrary:
139+
relativePath = AssemblyDirectory;
140+
break;
138141
case PublishFolderType.StaticLibrary:
139142
// Nothing to do here.
140143
continue;
@@ -320,11 +323,13 @@ PublishFolderType ComputePublishFolderType (IList<ITaskItem> items, ITaskItem it
320323
return PublishFolderType.CompressedAppleFramework;
321324
}
322325

323-
// *.a and *.dylib
326+
// *.a, *.dylib and *.so
324327
if (filename.EndsWith (".a", StringComparison.OrdinalIgnoreCase)) {
325328
return PublishFolderType.StaticLibrary;
326329
} else if (filename.EndsWith (".dylib", StringComparison.OrdinalIgnoreCase)) {
327330
return PublishFolderType.DynamicLibrary;
331+
} else if (filename.EndsWith (".so", StringComparison.OrdinalIgnoreCase)) {
332+
return PublishFolderType.PluginLibrary;
328333
}
329334

330335
// no other files are copied
@@ -363,6 +368,7 @@ enum PublishFolderType {
363368
PlugIns,
364369
CompressedPlugIns,
365370
DynamicLibrary, // link with + copy to app bundle
371+
PluginLibrary, // copy to app bundle (but not link with main executable)
366372
StaticLibrary, // link with (but not copy to app bundle)
367373
Unknown,
368374
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NoneQ
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NoneQ
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NoneQ

tests/dotnet/BundleStructure/shared.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
<!-- Bundled, linked with -->
5555
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5656
</None>
57+
<None Include="$(RootTestsDirectory)/test-libraries/libraries/.libs/$(RuntimeIdentifier)/libNoneE.so">
58+
<!-- Bundled, not linked with -->
59+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
60+
</None>
5761
<None Include="$(RootTestsDirectory)/test-libraries/libraries/.libs/$(RuntimeIdentifier)/libNoneF.a">
5862
<!-- Not bundled; linked with -->
5963
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -103,6 +107,10 @@
103107
<!-- Bundled, linked with, install_name_tool must have been executed -->
104108
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
105109
</None>
110+
<None Include="$(RootTestsDirectory)/test-libraries/libraries/.libs/$(RuntimeIdentifier)/libSkipInstallNameTool.so">
111+
<!-- Bundled, not linked with, install_name_tool must have been executed -->
112+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
113+
</None>
106114
</ItemGroup>
107115

108116
<ItemGroup>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NoneQ

tests/dotnet/UnitTests/BundleStructureTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ void CheckAppBundleContents (ApplePlatform platform, string appPath, string [] r
120120
expectedFiles.Add ($"{assemblyDirectory}NoneC.pdb");
121121
expectedFiles.Add ($"{assemblyDirectory}NoneD.exe");
122122
expectedFiles.Add ($"{assemblyDirectory}libNoneE.dylib");
123+
expectedFiles.Add ($"{assemblyDirectory}libNoneE.so");
123124
// NoneF.a is not bundled
124125
// Sub/NoneG.txt is not bundled
125126
// Sub/NoneH.txt is not bundled
@@ -129,6 +130,7 @@ void CheckAppBundleContents (ApplePlatform platform, string appPath, string [] r
129130
expectedFiles.Add ($"{assemblyDirectory}NoneL.config");
130131
// NoneM.unknown is not bundled
131132
expectedFiles.Add ($"{assemblyDirectory}libSkipInstallNameTool.dylib");
133+
expectedFiles.Add ($"{assemblyDirectory}libSkipInstallNameTool.so");
132134

133135
expectedFiles.Add ($"{resourcesDirectory}basn3p08.png");
134136
expectedFiles.Add ($"{resourcesDirectory}iTunesArtwork.jpg");
@@ -334,6 +336,7 @@ void CheckAppBundleContents (ApplePlatform platform, string appPath, string [] r
334336
Assert.That (missingFiles, Is.Empty, "No missing files");
335337

336338
AssertDynamicLibraryId (platform, appPath, assemblyDirectory, "libSkipInstallNameTool.dylib");
339+
AssertDynamicLibraryId (platform, appPath, assemblyDirectory, "libSkipInstallNameTool.so");
337340
AssertLibraryArchitectures (appPath, runtimeIdentifiers);
338341
}
339342

tests/dotnet/UnitTests/ProjectTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,7 @@ public void BuildAndExecuteAppWithNativeDynamicLibrariesInPackageReference (Appl
11751175

11761176
AssertThatDylibExistsAndIsReidentified (appPath, "libtest.dylib");
11771177
AssertThatDylibExistsAndIsReidentified (appPath, "/subdir/libtest.dylib");
1178+
AssertThatDylibExistsAndIsReidentified (appPath, "/subdir/libtest.so");
11781179

11791180
ExecuteWithMagicWordAndAssert (appExecutable);
11801181
}

0 commit comments

Comments
 (0)