Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build-tools/android-toolchain/android-toolchain.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@
</ItemGroup>
<ItemGroup>
<_NdkToolchain Include="arm-linux-androideabi-clang" Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':armeabi:')) Or $(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':armeabi-v7a:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-armeabi:'))">
<Platform>9</Platform>
<Platform>14</Platform>
<Arch>arm</Arch>
</_NdkToolchain>
<_NdkToolchain Include="aarch64-linux-android-clang" Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':arm64-v8a:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-arm64:'))">
<Platform>21</Platform>
<Arch>arm64</Arch>
</_NdkToolchain>
<_NdkToolchain Include="x86-clang" Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':x86:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-x86:'))">
<Platform>9</Platform>
<Platform>14</Platform>
<Arch>x86</Arch>
</_NdkToolchain>
<_NdkToolchain Include="x86_64-clang" Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':x86_64:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-x86_64:'))">
Expand Down
1 change: 1 addition & 0 deletions build-tools/scripts/RunTests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<_TestAssembly Include="$(_TopDir)\bin\Test$(Configuration)\Xamarin.Android.Build.Tests.dll" />
<_ApkTestProject Include="$(_TopDir)\src\Mono.Android\Test\Mono.Android-Tests.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\CodeGen-Binding\Xamarin.Android.JcwGen-Tests\Xamarin.Android.JcwGen-Tests.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\CodeGen-MkBundle\Xamarin.Android.MakeBundle-Tests\Xamarin.Android.MakeBundle-Tests.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\locales\Xamarin.Android.Locale-Tests\Xamarin.Android.Locale-Tests.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\Xamarin.Android.Bcl-Tests\Xamarin.Android.Bcl-Tests.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\Xamarin.Forms-Performance-Integration\Droid\Xamarin.Forms.Performance.Integration.Droid.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,24 @@ bool DoExecute ()

clb = new CommandLineBuilder ();
clb.AppendSwitch ("-c");

// This is necessary only when unified headers are in use but it won't hurt to have it
// defined even if we don't use them
clb.AppendSwitch ($"-D__ANDROID_API__={level}");

clb.AppendSwitch ("-o");
clb.AppendFileNameIfNotNull (Path.Combine (outpath, "temp.o"));
if (!string.IsNullOrWhiteSpace (IncludePath)) {
clb.AppendSwitch ("-I");
clb.AppendFileNameIfNotNull (IncludePath);
}

string asmIncludePath = NdkUtil.GetNdkAsmIncludePath (AndroidNdkDirectory, arch, level);
if (!String.IsNullOrEmpty (asmIncludePath)) {
clb.AppendSwitch ("-I");
clb.AppendFileNameIfNotNull (asmIncludePath);
}

clb.AppendSwitch ("-I");
clb.AppendFileNameIfNotNull (NdkUtil.GetNdkPlatformIncludePath (AndroidNdkDirectory, arch, level));
clb.AppendFileNameIfNotNull (Path.Combine (outpath, "temp.c"));
Expand Down
64 changes: 61 additions & 3 deletions src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,69 @@ public static string GetNdkTool (string androidNdkPath, AndroidTargetArch arch,
return null;
}

public static string GetNdkPlatformIncludePath (string androidNdkPath, AndroidTargetArch arch, int level)
static string GetUnifiedHeadersPath (string androidNdkPath)
{
return Path.Combine (androidNdkPath, "sysroot", "usr", "include");
}

static string GetPerPlatformHeadersPath (string androidNdkPath, AndroidTargetArch arch, int level)
{
return Path.Combine (androidNdkPath, "platforms", "android-" + level, "arch-" + GetPlatformArch (arch), "usr", "include");
}

public static string GetNdkAsmIncludePath (string androidNdkPath, AndroidTargetArch arch, int level)
{
string path = Path.Combine (androidNdkPath, "platforms", "android-" + level, "arch-" + GetPlatformArch (arch), "usr", "include");
string path = GetPerPlatformHeadersPath (androidNdkPath, arch, level);
if (Directory.Exists (path))
return null;

path = GetUnifiedHeadersPath (androidNdkPath);
if (!Directory.Exists (path))
return null;

string archDir = null;
switch (arch) {
case AndroidTargetArch.Arm:
archDir = "arm-linux-androideabi";
break;

case AndroidTargetArch.Arm64:
archDir = "aarch64-linux-android";
break;

case AndroidTargetArch.Mips:
archDir = "mipsel-linux-android";
break;

case AndroidTargetArch.X86:
archDir = "i686-linux-android";
break;

case AndroidTargetArch.X86_64:
archDir = "x86_64-linux-android";
break;
}

if (archDir == null)
return null;

return Path.Combine (path, archDir);
}

public static string GetNdkPlatformIncludePath (string androidNdkPath, AndroidTargetArch arch, int level)
{
// This is for NDK older than r16 which isn't configured to use unified headers. We
string path = GetPerPlatformHeadersPath (androidNdkPath, arch, level);
if (!Directory.Exists (path)) {
// This is for NDK r15 (if configured to use unified headers) or NDK r16+ (which doesn't have
// the per-platform includes anymore)
path = GetUnifiedHeadersPath (androidNdkPath);
if (Directory.Exists (path))
return path;

throw new InvalidOperationException (String.Format ("Platform header files for target {0} and API Level {1} was not found. Expected path is \"{2}\"", arch, level, path));
}

return path;
}

Expand Down Expand Up @@ -257,7 +315,7 @@ public static IEnumerable<int> GetSupportedPlatforms (string androidNdkPath)

public static int GetMinimumApiLevelFor (AndroidTargetArch arch, string androidNdkPath)
{
var minValue = NdkUtil.IsNdk64BitArch (arch) ? 21 : arch == AndroidTargetArch.Arm ? 4 : 9;
var minValue = NdkUtil.IsNdk64BitArch (arch) ? 21 : 14;
var platforms = GetSupportedPlatforms (androidNdkPath).OrderBy (x => x).Where (x => x >= minValue);
return platforms.First (x => Directory.Exists (Path.Combine (androidNdkPath, "platforms", $"android-{x}", $"arch-{archPathMap[arch]}")));
}
Expand Down