You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[One .NET] improve native library ABI detection at build time #5432
Instead of doing more inference with directory names, we should actually look at the contents of the .so file and:
Give a warning if it is not an Android library and ignore it.
Determine the ABI. If none found, emit a warning and ignore it.
We should still use the %(Abi) metadata if specified, for backwards compatibility.
We could try using the ElfSharp library to do this. We would need to make sure the code path is fast, or we have some mechanism for making incremental builds fast.
I am looking at the targets here now and I think this code already works. When the packages restore, there is metadata on the .so files RuntimeIdentifier=android-arm64. There is also the code that detects and converts from this RID to the ABI in the ProcessNativeLibraries task in the _IncludeNativeSystemLibraries target.
However, the files that this task uses is obtained via the _ResolveAssemblies target, which calls msbuild with the _ComputeFilesToPublishForRuntimeIdentifiers target. The result of this operation does not include the RID metadata.
I got a bit of a hack to add it back...
<TargetName="_IncludeNativeSystemLibrariesFixes"BeforeTargets="_IncludeNativeSystemLibraries">
<ItemGroup>
<_FixedResolvedFileToPublishInclude="@(ResolvedFileToPublish)"Condition=" '%(ResolvedFileToPublish.Extension)' == '.so' and '%(ResolvedFileToPublish.NuGetPackageId)' != '' and '%(ResolvedFileToPublish.RuntimeIdentifier)' == '' and '%(ResolvedFileToPublish.PathInPackage)' != '' " />
<ResolvedFileToPublishRemove="@(_FixedResolvedFileToPublish)" />
<ResolvedFileToPublishInclude="@(_FixedResolvedFileToPublish)">
<RuntimeIdentifier>$([System.Text.RegularExpressions.Regex]::Match('%(_FixedResolvedFileToPublish.PathInPackage)', 'runtimes/([^/]+)/native/.*').Groups[1].Value)</RuntimeIdentifier>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
The dotnet/sdk creates @(ResolvedFileToPublish), and I've noticed that %(RuntimeIdentifier) is blank when the file is coming from a regular NuGet package.
For some reason, it's there for "runtime" packs that are defined such as:
Activity
jonathanpeppers commentedon Dec 18, 2020
I wrote a sample program using ElfSharp: ElfSharpTest.zip
It looks for the equivalent of
readelf -d | grep NEEDED | grep ld-linuxin about 47ms for 10 native libraries.However one native library breaks the pattern:
We may need to just check the file path and not use ElfSharp at all.
mattleibow commentedon May 20, 2021
We could just add another rule and see if it came from a nuget and was in the runtimes, then look at the value after the android-.
jonathanpeppers commentedon May 20, 2021
I just haven't gotten around to doing this yet, but I think the plan will be:
android-arm64/libfoo.soin an appandroid-arm64/foo/libbar.sowould also work in an app, but I think that would be fine.mattleibow commentedon May 24, 2021
I am looking at the targets here now and I think this code already works. When the packages restore, there is metadata on the .so files
RuntimeIdentifier=android-arm64. There is also the code that detects and converts from this RID to the ABI in theProcessNativeLibrariestask in the_IncludeNativeSystemLibrariestarget.However, the files that this task uses is obtained via the
_ResolveAssembliestarget, which calls msbuild with the_ComputeFilesToPublishForRuntimeIdentifierstarget. The result of this operation does not include the RID metadata.I got a bit of a hack to add it back...
jonathanpeppers commentedon May 24, 2021
The dotnet/sdk creates
@(ResolvedFileToPublish), and I've noticed that%(RuntimeIdentifier)is blank when the file is coming from a regular NuGet package.For some reason, it's there for "runtime" packs that are defined such as:
https://github.com/xamarin/xamarin-android/blob/02ab8f723b6b8e327a3d8a6fd99192598ca94668/build-tools/create-packs/Microsoft.Android.Sdk.proj#L103-L114
Native libraries from
Microsoft.Android.Runtime.android-armhasRuntimeIdentifier=android-armfilled out for us.[BaseTasks] add ABI detection for RIDs
[BaseTasks] add ABI detection for RIDs (#121)
Bump to xamarin/xamarin-android-tools/main@90d76212
Bump to xamarin/xamarin-android-tools/main@90d76212