-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BaseTasks] add ABI detection for RIDs (#121)
Context: dotnet/android#5432 Two cases currently do not work in .NET 6: 1. When an Android App project includes native libraries which are in directory names consisting of .NET runtime identifiers instead of Android ABI names, e.g. android-arm/libfoo.so android-arm64/libfoo.so android-x86/libfoo.so android-x64/libfoo.so 2. When a NuGet package places native libraries into a `native` directory *between* the `$(RuntimeIdentifier)` directory and the native library, a'la [`SQLitePCLRaw.lib.e_sqlite3.linux`][0]: runtimes/linux-arm/native/libe_sqlite3.so Fix case (1) by checking using `AndroidRidAbiHelper.RuntimeIdentifierToAbi()` on the directory name to determine the Android ABI of the library. Fix case (2) by also checking the native library's parent parent directory name against Android ABI names and Runtime Identifiers. This allows us to correctly associate runtimes/android-arm64/native/libe_sqlite3.so as an arm64-v8a native library. I implemented these two cases as fallbacks to the existing logic. I think this will be fine for the behavior to be in "legacy" Xamarin.Android as well as .NET 6. I added tests for `AndroidRidAbiHelper`, since we had none before. [0]: https://www.nuget.org/packages/SQLitePCLRaw.lib.e_sqlite3.linux/1.1.14
- Loading branch information
1 parent
79e3b97
commit 90d7621
Showing
2 changed files
with
162 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.Android.Build.Tasks; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Android.Build.BaseTasks.Tests | ||
{ | ||
[TestFixture] | ||
public class AndroidRidAbiHelperTests | ||
{ | ||
static object [] StringValueSource = new object [] { | ||
new[] { | ||
/* input */ "armeabi-v7a/libfoo.so", | ||
/* expected */ "armeabi-v7a" | ||
}, | ||
new[] { | ||
/* input */ "arm64-v8a/libfoo.so", | ||
/* expected */ "arm64-v8a" | ||
}, | ||
new[] { | ||
/* input */ "x86/libfoo.so", | ||
/* expected */ "x86" | ||
}, | ||
new[] { | ||
/* input */ "x86_64/libfoo.so", | ||
/* expected */ "x86_64" | ||
}, | ||
new[] { | ||
/* input */ "android-arm/libfoo.so", | ||
/* expected */ "armeabi-v7a" | ||
}, | ||
new[] { | ||
/* input */ "android-arm64/libfoo.so", | ||
/* expected */ "arm64-v8a" | ||
}, | ||
new[] { | ||
/* input */ "android-x86/libfoo.so", | ||
/* expected */ "x86" | ||
}, | ||
new[] { | ||
/* input */ "android-x64/libfoo.so", | ||
/* expected */ "x86_64" | ||
}, | ||
new[] { | ||
/* input */ "android-arm/native/libfoo.so", | ||
/* expected */ "armeabi-v7a" | ||
}, | ||
new[] { | ||
/* input */ "android-arm64/native/libfoo.so", | ||
/* expected */ "arm64-v8a" | ||
}, | ||
new[] { | ||
/* input */ "android-x86/native/libfoo.so", | ||
/* expected */ "x86" | ||
}, | ||
new[] { | ||
/* input */ "android-x64/native/libfoo.so", | ||
/* expected */ "x86_64" | ||
}, | ||
new[] { | ||
/* input */ "android.21-x64/native/libfoo.so", | ||
/* expected */ "x86_64" | ||
}, | ||
new[] { | ||
/* input */ "packages/sqlitepclraw.lib.e_sqlite3.android/1.1.11/runtimes/android-arm64/native/libe_sqlite3.so", | ||
/* expected */ "arm64-v8a" | ||
} | ||
}; | ||
|
||
[Test] | ||
[TestCaseSource (nameof (StringValueSource))] | ||
public void StringValue (string input, string expected) | ||
{ | ||
Assert.AreEqual (expected, AndroidRidAbiHelper.GetNativeLibraryAbi (input)); | ||
} | ||
|
||
static object [] ITaskItemValueSource = new object [] { | ||
new object [] { | ||
/* input */ | ||
new TaskItem("armeabi-v7a/libfoo.so"), | ||
/* expected */ | ||
"armeabi-v7a" | ||
}, | ||
new object [] { | ||
/* input */ | ||
new TaskItem("libabi.so", new Dictionary<string,string> { | ||
{ "Abi", "armeabi-v7a" } | ||
}), | ||
/* expected */ | ||
"armeabi-v7a" | ||
}, | ||
new object [] { | ||
/* input */ | ||
new TaskItem("librid.so", new Dictionary<string,string> { | ||
{ "RuntimeIdentifier", "android-arm" } | ||
}), | ||
/* expected */ | ||
"armeabi-v7a" | ||
}, | ||
new object [] { | ||
/* input */ | ||
new TaskItem("liblink.so", new Dictionary<string,string> { | ||
{ "Link", "armeabi-v7a/libfoo.so" } | ||
}), | ||
/* expected */ | ||
"armeabi-v7a" | ||
}, | ||
new object [] { | ||
/* input */ | ||
new TaskItem("liblink.so", new Dictionary<string,string> { | ||
{ "Link", "x86/libfoo.so" } | ||
}), | ||
/* expected */ | ||
"x86" | ||
}, | ||
new object [] { | ||
/* input */ | ||
new TaskItem("liblink.so", new Dictionary<string,string> { | ||
{ "Link", "x86_64/libfoo.so" } | ||
}), | ||
/* expected */ | ||
"x86_64" | ||
}, | ||
new object [] { | ||
/* input */ | ||
new TaskItem("libridlink.so", new Dictionary<string,string> { | ||
{ "Link", "android-arm/libfoo.so" } | ||
}), | ||
/* expected */ | ||
"armeabi-v7a" | ||
}, | ||
}; | ||
|
||
[Test] | ||
[TestCaseSource (nameof (ITaskItemValueSource))] | ||
public void ITaskItemValue (ITaskItem input, string expected) | ||
{ | ||
Assert.AreEqual (expected, AndroidRidAbiHelper.GetNativeLibraryAbi (input)); | ||
} | ||
} | ||
} |