Commit 82a0070
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 46677fd commit 82a0070
File tree
13 files changed
+69
-31
lines changed- build-tools
- create-packs
- debian-metadata
- installers
- xaprepare/xaprepare
- external
- src/Xamarin.Android.Build.Tasks
- Resources
- Tests/Xamarin.Android.Build.Tests
- tests/MSBuildDeviceIntegration/Tests
13 files changed
+69
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
197 | 196 | | |
198 | | - | |
199 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
200 | 202 | | |
201 | 203 | | |
202 | 204 | | |
| |||
304 | 306 | | |
305 | 307 | | |
306 | 308 | | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
311 | 313 | | |
312 | 314 | | |
313 | 315 | | |
| |||
368 | 370 | | |
369 | 371 | | |
370 | 372 | | |
371 | | - | |
372 | | - | |
373 | | - | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
374 | 377 | | |
375 | 378 | | |
376 | 379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
Submodule xamarin-android-tools updated from 683f375 to e3d708c
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
454 | | - | |
| 454 | + | |
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
| |||
Lines changed: 0 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | 369 | | |
376 | 370 | | |
377 | 371 | | |
| |||
0 commit comments