Skip to content

Commit ff1edeb

Browse files
committed
[WIP] Bump to NDK r23-beta5
Let's see what breaks
1 parent 600e993 commit ff1edeb

File tree

11 files changed

+114
-52
lines changed

11 files changed

+114
-52
lines changed

build-tools/xaprepare/xaprepare/Application/BuildInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ partial class BuildInfo : AppObject
1818
public string NDKVersionMajor { get; private set; } = String.Empty;
1919
public string NDKVersionMinor { get; private set; } = String.Empty;
2020
public string NDKVersionMicro { get; private set; } = String.Empty;
21+
public string NDKVersionTag { get; private set; } = String.Empty;
2122
public string NDKMinimumApiAvailable { get; private set; } = String.Empty;
2223

2324
public string VersionHash { get; private set; } = String.Empty;
@@ -59,15 +60,15 @@ public bool GatherNDKInfo (Context context)
5960
string rev = parts [1].Trim ();
6061
NDKRevision = rev;
6162

62-
Version ver;
63-
if (!Version.TryParse (rev, out ver)) {
63+
if (!Utilities.ParseAndroidPkgRevision (rev, out Version? ver, out string tag)) {
6464
Log.ErrorLine ($"Unable to parse NDK revision '{rev}' as a valid version string");
6565
return false;
6666
}
6767

6868
NDKVersionMajor = ver.Major.ToString ();
6969
NDKVersionMinor = ver.Minor.ToString ();
7070
NDKVersionMicro = ver.Build.ToString ();
71+
NDKVersionTag = tag;
7172
break;
7273
}
7374

build-tools/xaprepare/xaprepare/Application/MonoJitRuntime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override void Init (Context context)
2424
OutputMonoBtlsFilename = Configurables.Defaults.MonoRuntimeOutputMonoBtlsFilename;
2525
OutputMonoPosixHelperFilename = Configurables.Defaults.MonoRuntimeOutputMonoPosixHelperFilename;
2626
OutputProfilerFilename = Configurables.Defaults.MonoRuntimeOutputProfilerFilename;
27-
Strip = Path.Combine (Configurables.Paths.AndroidToolchainBinDirectory, $"{Configurables.Defaults.AndroidToolchainPrefixes [Name]}-strip");
27+
Strip = Path.Combine (Configurables.Paths.AndroidToolchainBinDirectory, "llvm-strip");
2828
}
2929
}
3030
}

build-tools/xaprepare/xaprepare/Application/Utilities.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@ static partial class Utilities
2929

3030
public static readonly Encoding UTF8NoBOM = new UTF8Encoding (false);
3131

32+
public static bool ParseAndroidPkgRevision (string? v, out Version? version, out string? tag)
33+
{
34+
string? ver = v?.Trim ();
35+
version = null;
36+
tag = null;
37+
if (String.IsNullOrEmpty (ver))
38+
return false;
39+
40+
if (ver!.IndexOf ('.') < 0)
41+
ver = $"{ver}.0";
42+
43+
int tagIdx = ver.IndexOf ('-');
44+
if (tagIdx >= 0) {
45+
tag = ver.Substring (tagIdx + 1);
46+
ver = ver.Substring (0, tagIdx - 1);
47+
}
48+
49+
if (Version.TryParse (ver, out version))
50+
return true;
51+
52+
return false;
53+
}
54+
3255
public static bool AbiChoiceChanged (Context context)
3356
{
3457
string cacheFile = Configurables.Paths.MonoRuntimesEnabledAbisCachePath;

build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace Xamarin.Android.Prepare
55
{
66
class BuildAndroidPlatforms
77
{
8-
public const string AndroidNdkVersion = "22b";
9-
public const string AndroidNdkPkgRevision = "22.1.7171670";
8+
public const string AndroidNdkVersion = "23-beta5";
9+
public const string AndroidNdkPkgRevision = "23.0.7421159-beta5";
1010

1111
public static readonly List<AndroidPlatform> AllPlatforms = new List<AndroidPlatform> {
1212
new AndroidPlatform (apiName: "", apiLevel: 1, platformID: "1"),
@@ -49,9 +49,9 @@ class BuildAndroidPlatforms
4949
public const string AndroidX86_64_NET6 = AbiNames.TargetJit.AndroidX86_64 + "_NET6";
5050

5151
public static readonly Dictionary<string, uint> NdkMinimumAPI = new Dictionary<string, uint> {
52-
{ AbiNames.TargetJit.AndroidArmV7a, 16 }, { AndroidArmV7a_NET6, 21 },
52+
{ AbiNames.TargetJit.AndroidArmV7a, 19 }, { AndroidArmV7a_NET6, 21 },
5353
{ AbiNames.TargetJit.AndroidArmV8a, 21 }, { AndroidArmV8a_NET6, 21 },
54-
{ AbiNames.TargetJit.AndroidX86, 16 }, { AndroidX86_NET6, 21 },
54+
{ AbiNames.TargetJit.AndroidX86, 19 }, { AndroidX86_NET6, 21 },
5555
{ AbiNames.TargetJit.AndroidX86_64, 21 }, { AndroidX86_64_NET6, 21 },
5656
};
5757
}

build-tools/xaprepare/xaprepare/ConfigAndData/Dependencies/AndroidToolchain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public AndroidToolchain ()
6969
new AndroidToolchainComponent ("docs-24_r01", destDir: "docs", pkgRevision: "1", dependencyType: AndroidToolchainComponentType.BuildDependency),
7070
new AndroidToolchainComponent ("android_m2repository_r47", destDir: Path.Combine ("extras", "android", "m2repository"), pkgRevision: "47.0.0", dependencyType: AndroidToolchainComponentType.BuildDependency),
7171
new AndroidToolchainComponent ($"x86_64-29_r07-{osTag}", destDir: Path.Combine ("system-images", "android-29", "default", "x86_64"), relativeUrl: new Uri ("sys-img/android/", UriKind.Relative), pkgRevision: "7", dependencyType: AndroidToolchainComponentType.EmulatorDependency),
72-
new AndroidToolchainComponent ($"android-ndk-r{AndroidNdkVersion}-{osTag}-x86_64", destDir: AndroidNdkDirectory, pkgRevision: AndroidPkgRevision),
72+
new AndroidToolchainComponent ($"android-ndk-r{AndroidNdkVersion}-{osTag}", destDir: AndroidNdkDirectory, pkgRevision: AndroidPkgRevision),
7373
new AndroidToolchainComponent ($"{XABuildToolsPackagePrefix}build-tools_r{XABuildToolsVersion}-{altOsTag}", destDir: Path.Combine ("build-tools", XABuildToolsFolder), isMultiVersion: true),
7474
new AndroidToolchainComponent ($"commandlinetools-{cltOsTag}-{CommandLineToolsVersion}",
7575
destDir: Path.Combine ("cmdline-tools", CommandLineToolsFolder), isMultiVersion: true),

build-tools/xaprepare/xaprepare/Steps/Step_Android_SDK_NDK.cs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -307,37 +307,21 @@ bool IsInstalled (AndroidToolchainComponent component, string path, out bool mis
307307
return false;
308308
}
309309

310-
if (!ParseVersion (pkgRevision, out Version? pkgVer) || pkgVer == null) {
310+
if (!Utilities.ParseAndroidPkgRevision (pkgRevision, out Version? pkgVer, out string pkgTag) || pkgVer == null) {
311311
Log.DebugLine ($"Failed to parse a valid version from Pkg.Revision ({pkgRevision}) for component '{component.Name}'. Component will be reinstalled.");
312312
return false;
313313
}
314314

315-
if (!ParseVersion (component.PkgRevision, out Version? expectedPkgVer) || expectedPkgVer == null)
315+
if (!Utilities.ParseAndroidPkgRevision (component.PkgRevision, out Version? expectedPkgVer, out string expectedTag) || expectedPkgVer == null)
316316
throw new InvalidOperationException ($"Invalid expected package version for component '{component.Name}': {component.PkgRevision}");
317317

318-
bool equal = pkgVer == expectedPkgVer;
318+
bool equal = (pkgVer == expectedPkgVer) && (pkgTag == expectedTag);
319319
if (!equal)
320-
Log.DebugLine ($"Installed version of '{component.Name}' ({pkgVer}) is different than the required one ({expectedPkgVer})");
320+
Log.DebugLine ($"Installed version of '{component.Name}' ({pkgRevision}) is different than the required one ({component.PkgRevision})");
321321

322322
return equal;
323323
}
324324

325-
bool ParseVersion (string? v, out Version? version)
326-
{
327-
string? ver = v?.Trim ();
328-
version = null;
329-
if (String.IsNullOrEmpty (ver))
330-
return false;
331-
332-
if (ver!.IndexOf ('.') < 0)
333-
ver = $"{ver}.0";
334-
335-
if (Version.TryParse (ver, out version))
336-
return true;
337-
338-
return false;
339-
}
340-
341325
bool IsNdk (AndroidToolchainComponent component)
342326
{
343327
return component.Name.StartsWith ("android-ndk", StringComparison.OrdinalIgnoreCase);

external/xamarin-android-tools

src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,20 @@ IEnumerable<Config> GetAotConfigs ()
359359
}
360360

361361
string toolchainLibDir;
362-
if (NdkUtil.UsingClangNDK)
363-
toolchainLibDir = GetNdkToolchainLibraryDir (toolchainPath, arch);
364-
else
362+
if (NdkUtil.UsingClangNDK) {
363+
if (!NdkUtil.UsingNDKWithoutBinutils) {
364+
toolchainLibDir = GetNdkToolchainLibraryDir (toolchainPath, arch);
365+
} else {
366+
toolchainLibDir = String.Empty;
367+
}
368+
} else
365369
toolchainLibDir = GetNdkToolchainLibraryDir (toolchainPath);
366370

367371
var libs = new List<string>();
368372
if (NdkUtil.UsingClangNDK) {
369-
libs.Add ($"-L{toolchainLibDir.TrimEnd ('\\')}");
373+
if (!String.IsNullOrEmpty (toolchainLibDir)) {
374+
libs.Add ($"-L{toolchainLibDir.TrimEnd ('\\')}");
375+
}
370376
libs.Add ($"-L{androidLibPath.TrimEnd ('\\')}");
371377

372378
if (arch == AndroidTargetArch.Arm) {
@@ -376,7 +382,9 @@ IEnumerable<Config> GetAotConfigs ()
376382
}
377383
}
378384

379-
libs.Add (Path.Combine (toolchainLibDir, "libgcc.a"));
385+
if (!String.IsNullOrEmpty (toolchainLibDir)) {
386+
libs.Add (Path.Combine (toolchainLibDir, "libgcc.a"));
387+
}
380388
libs.Add (Path.Combine (androidLibPath, "libc.so"));
381389
libs.Add (Path.Combine (androidLibPath, "libm.so"));
382390

src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ namespace Xamarin.Android.Tasks
1818
{
1919
public static class NdkUtil
2020
{
21+
class NDKToolchainInfo
22+
{
23+
public bool IsClangNDK;
24+
public bool NoBinutils;
25+
public int MajorVersion;
26+
}
27+
2128
// We need it to work fine during our tests which are executed at the same time in various threads.
2229
[ThreadStatic]
23-
static bool usingClangNDK;
30+
static NDKToolchainInfo? ndkToolchainInfo;
2431

25-
public static bool UsingClangNDK => usingClangNDK;
32+
public static bool UsingClangNDK => ndkToolchainInfo == null ? false : ndkToolchainInfo.IsClangNDK;
33+
public static bool UsingNDKWithoutBinutils => ndkToolchainInfo == null ? false : ndkToolchainInfo.NoBinutils;
34+
public static int NDKMajorVersion = ndkToolchainInfo == null ? 0 : ndkToolchainInfo.MajorVersion;
2635

2736
public static bool Init (string ndkPath)
2837
{
@@ -41,7 +50,11 @@ public static bool Init (Action<string, string> logError, string ndkPath)
4150
return false;
4251
}
4352

44-
usingClangNDK = ndkVersion.Major >= 19;
53+
ndkToolchainInfo = new NDKToolchainInfo {
54+
IsClangNDK = ndkVersion.Major >= 19,
55+
NoBinutils = ndkVersion.Major > 22,
56+
MajorVersion = ndkVersion.Major,
57+
};
4558

4659
return true;
4760
}
@@ -198,12 +211,17 @@ public static string GetNdkTool (string androidNdkPath, AndroidTargetArch arch,
198211
//
199212
string toolchainPrefix;
200213
if (forCompiler) {
201-
if (!OS.IsWindows)
214+
if (!OS.IsWindows || NDKMajorVersion >= 21) {
202215
toolchainPrefix = $"{GetNdkToolchainPrefix (arch, true)}{apiLevel}";
203-
else
216+
} else
204217
toolchainPrefix = String.Empty;
205-
} else
206-
toolchainPrefix = GetNdkToolchainPrefix (arch, false);
218+
} else {
219+
if (UsingNDKWithoutBinutils && !IsBinutilsToolOrLd ()) {
220+
toolchainPrefix = "llvm";
221+
} else {
222+
toolchainPrefix = GetNdkToolchainPrefix (arch, false);
223+
}
224+
}
207225

208226
string extension = OS.IsWindows ? ".exe" : String.Empty;
209227
if (forCompiler && OS.IsWindows)
@@ -212,12 +230,8 @@ public static string GetNdkTool (string androidNdkPath, AndroidTargetArch arch,
212230
toolName = GetPrefixedName (toolName);
213231

214232
string toolPath = GetToolPath (toolName);
215-
if (String.IsNullOrEmpty (toolPath) && String.Compare ("ld", tool, StringComparison.OrdinalIgnoreCase) == 0) {
216-
// NDK r22 removed arch-prefixed `ld` binary. There exists the unprefixed `ld` binary, from the LLVM
217-
// toolchain, and two binutils linkers - `ld.bfd` and `ld.gold`. Since we will need to keep using
218-
// binutils once NDK removes them, let's use one of the latter. `ld.gold` is the better choice, so we'll
219-
// use it if found
220-
toolPath = GetToolPath (GetPrefixedName ("ld.gold"));
233+
if (String.IsNullOrEmpty (toolPath) && IsBinutilsToolOrLd ()) {
234+
toolPath = GetBundledToolPath (GetPrefixedName (tool));
221235
}
222236

223237
if (!String.IsNullOrEmpty (toolPath)) {
@@ -232,15 +246,41 @@ string GetPrefixedName (string name)
232246
return $"{toolchainPrefix}-{name}{extension}";
233247
}
234248

249+
string GetBundledToolPath (string name)
250+
{
251+
return GetFullToolPath (Path.Combine (MonoAndroidHelper.GetOSBinPath (), "ndk"), name);
252+
}
253+
235254
string GetToolPath (string name)
236255
{
237-
string binDir = Path.Combine (toolchainDir, "bin");
256+
return GetFullToolPath (Path.Combine (toolchainDir, "bin"), name);
257+
}
258+
259+
string GetFullToolPath (string binDir, string name)
260+
{
238261
string toolExe = MonoAndroidHelper.GetExecutablePath (binDir, name);
239-
string toolPath = Path.Combine (binDir, toolExe);
262+
string toolPath = Path.Combine (binDir, toolExe);
240263
if (File.Exists (toolPath))
241264
return toolPath;
242265
return null;
243266
}
267+
268+
bool IsBinutilsToolOrLd ()
269+
{
270+
switch (tool) {
271+
case "ld":
272+
return true;
273+
274+
case "as":
275+
case "strip":
276+
if (UsingNDKWithoutBinutils) {
277+
return true;
278+
}
279+
break;
280+
}
281+
282+
return false;
283+
}
244284
}
245285

246286
static string GetUnifiedHeadersPath (string androidNdkPath)
@@ -378,7 +418,14 @@ public static bool GetNdkToolchainRelease (string androidNdkPath, out Version nd
378418
if (parts.Length != 2)
379419
return false;
380420

381-
if (Version.TryParse (parts [1].Trim (), out ndkVersion))
421+
string ver = parts [1].Trim ();
422+
int tagIdx = ver.IndexOf ('-');
423+
if (tagIdx >= 0) {
424+
// We ignore the tag, it doesn't really matter to us. This code will be used only when testing beta releases of the NDK
425+
ver = ver.Substring (0, tagIdx - 1);
426+
}
427+
428+
if (Version.TryParse (ver, out ndkVersion))
382429
return true;
383430
break;
384431
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void TestNdkUtil ()
4141
Assert.IsTrue (NdkUtil.ValidateNdkPlatform (log, ndkDir, arch, enableLLVM: false));
4242
Assert.AreEqual (0, errors.Count, "NdkUtil.ValidateNdkPlatform should not have returned false.");
4343
int level = NdkUtil.GetMinimumApiLevelFor (arch, ndkDir);
44-
int expected = 16;
44+
int expected = 19;
4545
Assert.AreEqual (expected, level, $"Min Api Level for {arch} should be {expected}.");
4646
var compilerNoQuotes = NdkUtil.GetNdkTool (ndkDir, arch, "gcc", level);
4747
Assert.AreEqual (0, errors.Count, "NdkUtil.GetNdkTool should not have errored.");

0 commit comments

Comments
 (0)