Skip to content

Commit d672f76

Browse files
committed
Switch to the new Mono.Unix nuget
`Xamarin.Android` uses the Mono's Mono.Posix assembly on Unix machines to perform tasks not possible with BCL classes, provided so far by the `Mono.Posix.NETStandard` nuget. Unfortunately, that nuget doesn't work with `dotnet` and so the `Mono.Posix` code has recently been extracted from the Mono repository and placed in its own, from which the new `Mono.Unix` nuget is built and published. This commit switches to `Mono.Unix` in Xamarin.Android and also updates a number of submodules which likewise migrated from `Mono.Posix.NETStandard` to `Mono.Unix` Additionally, LibZipSharp is updated as well, since it now uses `Mono.Unix` `Mono.Unix` no longer uses the older `libMonoPosixHelper` dynamic library, replaced by a new `libMono.Unix` one. This change, however, broke a number of tests since the `Mono.Unix.dll` assembly was no longer able to find its companion native shared library. The reason is that `Mono.Posix.NETStandard` used the "standard" helper library which was also part of the Mono distribution that we use on all the Unix machines. However, that meant the helper library from `Mono.Posix.NETStandard` was never used, instead the Mono copy was loaded and everything worked as expected. `Mono.Unix`'s new native helper library, however, must be taken from the nuget and both Mono and dotnet runtimes must be told where from to load the library once a p/invoke into it is encountered in managed code. The native library is copied from the nuget to the referencing application's output directory and it should be loaded from there. This proved to be easy for the "legacy" Mono - a simple `dllmap` configuration is provided and everything works as it should. With `dotnet` however, dllmap doesn't work. `dotnet` has instead a number (5 I think) mechanisms to configure where the native libraries can be found. Unfortunately, the mechanisms either require that a main executable of the application calls the APIs on entry (e.g. in the `Main`) method or that a JSON configuration file is provided for the application, telling the runtime where the native libraries reside. In case of `Xamarin.Android.Build.Tasks` there is no main executable we can configure, since it works in the msbuild context, providing tasks and utilities to build Xamarin.Android apps. In such instance, `dotnet` could be persuaded to find the libraries by calling one of the 5 APIs. The problem with this approach, however, is that this action would have to be performed at **every** possible entry point to the `Xamarin.Android.Build.Tasks` assembly, since any of them could be used as the first one. While certainly possible, it would be both fragile and an unnecessary maintenance burden. Instead, a simpler (albeit a bit kludgy) solution was chosen. The `Xamarin.Android.Build.Tasks` build process now takes care of generating a fat (multi-architecture) binary for macOS hosts (including `x86-64` and `arm64` architectures) using the `lipo` utility, then it copies the resulting binary to the same directory where `Xamarin.Android.Build.Tasks.dll` and `Mono.Unix.dll` live. The Linux shared library is also copied to the same location. The `dotnet` runtime is able to find and load shared libraries that are in the same directory as the assembly that needs them and everything works as expected.
1 parent 002b5f9 commit d672f76

File tree

12 files changed

+65
-31
lines changed

12 files changed

+65
-31
lines changed

.external

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
xamarin/monodroid:main@76c04cd15eca7afc269a6d26296e9d2db6f79be2
1+
xamarin/monodroid:main@691310edec2472e4bfac7f14d1a6bfe39de91872
22
mono/mono:2020-02@c633fe923832f0c3db3c4e6aa98e5592bf5a06e7

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<!-- Common <PackageReference/> versions -->
2828
<PropertyGroup>
29-
<LibZipSharpVersion>1.0.24</LibZipSharpVersion>
29+
<LibZipSharpVersion>2.0.0-alpha4</LibZipSharpVersion>
3030
<MicroBuildCoreVersion>0.4.1</MicroBuildCoreVersion>
3131
<MonoCecilVersion>0.11.2</MonoCecilVersion>
3232
<NuGetApiPackageVersion>5.4.0</NuGetApiPackageVersion>

build-tools/create-packs/SignList.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project>
22
<ItemGroup>
33
<!-- Do not sign files that already have a signature -->
4-
<Skip Include="libzip*" />
54
<Skip Include="libZipSharp*" />
65
</ItemGroup>
76

build-tools/debian-metadata/rules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ override_dh_install:
2121
rm -f bin/*/lib/xamarin.android/xbuild/Xamarin/Android/opt.exe
2222
rm -f bin/*/lib/xamarin.android/xbuild/Xamarin/Android/aapt2.exe
2323
rm -f bin/*/lib/xamarin.android/xbuild/Xamarin/Android/libwinpthread-1.dll
24-
rm -f bin/*/lib/xamarin.android/xbuild/Xamarin/Android/libzip.dll
24+
rm -f bin/*/lib/xamarin.android/xbuild/Xamarin/Android/libZipSharpNative.dll
2525

2626
dh_install
2727

build-tools/installers/create-installers.targets

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,12 @@
193193
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\interpreter-%(Identity)\libmonosgen-2.0.so')" ExcludeFromAndroidNETSdk="true" />
194194
<_MSBuildFiles Include="$(MSBuildSrcDir)\libZipSharp.dll" />
195195
<_MSBuildFiles Include="@(_LocalizationLanguages->'$(MSBuildSrcDir)\%(Identity)\libZipSharp.resources.dll')" />
196-
<_MSBuildFiles Include="$(MSBuildSrcDir)\libZipSharp.dll.config" />
197196
<_MSBuildFiles Include="$(MSBuildSrcDir)\libZipSharp.pdb" />
198-
<_MSBuildFiles Include="$(MSBuildSrcDir)\Mono.Posix.NETStandard.dll" />
199-
<_MSBuildFiles Include="$(MSBuildSrcDir)\Mono.Posix.NETStandard.pdb" />
197+
<_MSBuildFiles Include="$(MSBuildSrcDir)\Mono.Unix.dll" />
198+
<_MSBuildFiles Include="$(MSBuildSrcDir)\Mono.Unix.dll.config" />
199+
<_MSBuildFiles Include="$(MSBuildSrcDir)\Mono.Unix.pdb" />
200+
<_MSBuildFiles Include="$(MSBuildSrcDir)\libMono.Unix.so" />
201+
<_MSBuildFiles Include="$(MSBuildSrcDir)\libMono.Unix.dylib" />
200202
<_MSBuildFiles Include="$(MSBuildSrcDir)\Mono.Profiler.Log.dll" />
201203
<_MSBuildFiles Include="$(MSBuildSrcDir)\Mono.Profiler.Log.pdb" />
202204
<_MSBuildFiles Include="$(MSBuildSrcDir)\logcat-parse.exe" ExcludeFromAndroidNETSdk="true" />
@@ -304,10 +306,10 @@
304306
<_MSBuildTargetsSrcFiles Include="$(MSBuildTargetsSrcDir)\Xamarin.Android.DefaultOutputPaths.targets" />
305307
</ItemGroup>
306308
<ItemGroup>
307-
<_MSBuildFilesWin Include="$(MSBuildSrcDir)\libzip.dll" />
308-
<_MSBuildFilesWin Include="$(MSBuildSrcDir)\libzip.pdb" />
309-
<_MSBuildFilesWin Include="$(MSBuildSrcDir)\lib64\libzip.dll" />
310-
<_MSBuildFilesWin Include="$(MSBuildSrcDir)\lib64\libzip.pdb" />
309+
<_MSBuildFilesWin Include="$(MSBuildSrcDir)\libZipSharpNative.dll" />
310+
<_MSBuildFilesWin Include="$(MSBuildSrcDir)\libZipSharpNative.pdb" />
311+
<_MSBuildFilesWin Include="$(MSBuildSrcDir)\lib64\libZipSharpNative.dll" />
312+
<_MSBuildFilesWin Include="$(MSBuildSrcDir)\lib64\libZipSharpNative.pdb" />
311313
<_MSBuildFilesWin Include="$(MSBuildSrcDir)\proguard\bin\proguard.bat" />
312314
<_MSBuildFilesWin Include="$(MSBuildSrcDir)\aapt2.exe" />
313315
<_MSBuildFilesWin Include="$(MSBuildSrcDir)\ndk\aarch64-linux-android-as.exe" />
@@ -368,9 +370,10 @@
368370
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\lib\host-$(HostOS)\libmonosgen-2.0.$(LibExtension)" ExcludeFromAndroidNETSdk="true" />
369371
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\lib\host-$(HostOS)\libxamarin-app.$(LibExtension)" ExcludeFromAndroidNETSdk="true" />
370372
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\lib\host-$(HostOS)\libxa-internal-api.$(LibExtension)" ExcludeFromAndroidNETSdk="true" />
371-
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\libzip.$(LibExtension)" />
372-
<!-- A second libMonoPosixHelper.dylib is needed for libZipSharp.dll to load -->
373-
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\libMonoPosixHelper.$(LibExtension)" />
373+
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\libZipSharpNative.$(LibExtension)" />
374+
<!-- A second libMono.Unix.{dylib,so} is needed for libZipSharp.dll to load -->
375+
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\libMono.Unix.so" />
376+
<_MSBuildFilesUnixSign Include="$(MSBuildSrcDir)\libMono.Unix.dylib" />
374377
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\proguard\bin\proguard.sh" />
375378
</ItemGroup>
376379
<!-- Allow us to exclude mono bundle files for PR builds -->

build-tools/xaprepare/xaprepare/xaprepare.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<PackageReference Include="7-Zip.CommandLine" Version="18.1.0" GeneratePathProperty="true" />
5353
<PackageReference Include="Kajabity.Tools.Java" Version="0.2.6862.30334" />
5454
<PackageReference Include="Mono.Options" Version="$(MonoOptionsVersion)" />
55-
<PackageReference Include="Mono.Posix.NetStandard" Version="1.0.0" />
55+
<PackageReference Include="Mono.Unix" Version="7.0.0-alpha8.21302.6" />
5656
<PackageReference Include="System.Net.Http" Version="4.3.4" />
5757
<PackageReference Include="Xamarin.LibZipSharp" Version="$(LibZipSharpVersion)" GeneratePathProperty="true" />
5858
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />

external/xamarin-android-tools

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<dllmap dll="Mono.Unix" os="linux" cpu="x86-64" wordsize="64" target="libMono.Unix.so" />
4+
<dllmap dll="Mono.Unix" os="osx" target="libMono.Unix.dylib" />
5+
</configuration>

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public void CheckAapt2WarningsDoNotGenerateErrors ()
451451
//https://github.com/xamarin/xamarin-android/issues/3083
452452
var proj = new XamarinAndroidApplicationProject () {
453453
IsRelease = true,
454-
TargetFrameworkVersion = Versions.Oreo_27,
454+
TargetFrameworkVersion = Xamarin.ProjectTools.Versions.Oreo_27,
455455
UseLatestPlatformSdk = false,
456456
};
457457
proj.PackageReferences.Add (KnownPackages.XamarinForms_2_3_4_231);

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,6 @@
366366
<None Include="startup-xf.aotprofile">
367367
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
368368
</None>
369-
<None Include="$(PkgMono_Posix_NETStandard)\runtimes\osx\native\libMonoPosixHelper.dylib">
370-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
371-
</None>
372-
<None Include="$(PkgMono_Posix_NETStandard)\runtimes\linux-x64\native\libMonoPosixHelper.so">
373-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
374-
</None>
375369
</ItemGroup>
376370

377371
<ItemGroup>

0 commit comments

Comments
 (0)