Skip to content

Commit accc846

Browse files
authored
Bump to mono/mono@c66141a8; NDK r22 support (#5475)
Context: mono/mono#20606 Context: https://github.com/android/ndk/wiki/Changelog-r22 Changes: mono/mono@5e9cb6d...c66141a * mono/mono@c66141a8c7b: [AOT] Make native linker name configurable (#20816) * mono/mono@64368a00d85: Bump msbuild * mono/mono@364c87b1a7a: Disable acceptance-tests/roslyn.mk * mono/mono@9b139294c04: Bump msbuild to fix build break * mono/mono@b9c050faf2e: [aot] Quote the -Wl,install_name argument to clang. (#20660) Add support for using [NDK r22][0] when building Xamarin.Android apps. The most important NDK changes: * GNU binutils are deprecated (but still used) * LLVM 11 is used for the toolchain * LLD is now the default linker Mono changes: * Allow the `ld` name to be configurable, as we now prefer e.g. `aarch64-linux-android-ld.gold`, not `aarch64-linux-android-ld`, as the latter is LLD and not binutils. Xamarin.Android CI changes: * All the binutils tools are listed in a single location, within `xaprepare`'s `Configurables.Defaults`. * Host NDK binutils are installed by `xaprepare` instead of by Xamarin.Android.Build.Tools * `UBSAN` checked builds now require `RTTI` and exceptions. Xamarin.Android App build changes: * The `<Aot/>` task now supports using NDK r22 TODO: * Add a nightly job (916d24b) which builds Xamarin.Android apps against NDK r21, to ensure we don't break support. * NDK r22's [`cmake` doesn't work on Windows][1]. We have worked around this by copying the fixed `android.toolchain.cmake` as `src-ThirdParty/ndk/android.toolchain.cmake.ndk_r21.3`. Once NDK r22 properly includes the fix, we should remove `src-ThirdParty/ndk/android.toolchain.cmake.ndk_r21.3`. [0]: https://github.com/android/ndk/wiki/Changelog-r22 [1]: android/ndk#1427
1 parent c6b9a70 commit accc846

File tree

24 files changed

+1084
-147
lines changed

24 files changed

+1084
-147
lines changed

.external

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
xamarin/monodroid:main@7da768cf9ddbd137bbce5326dab79b139bcc59e0
2-
mono/mono:2020-02@5e9cb6d1c1de430965312927d5aed7fcb27bfa73
2+
mono/mono:2020-02@c66141a8c7ba2566c578c2dd012b2b723e006213

build-tools/cmake/xa_common.cmake

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
if((CMAKE_VERSION_MAJOR EQUAL 3 AND CMAKE_VERSION_MINOR GREATER_EQUAL 7) OR CMAKE_VERSION_MAJOR GREATER 3)
2-
set(CMAKE_POLICY_DEFAULT_CMP0066 NEW)
3-
endif()
4-
5-
if((CMAKE_VERSION_MAJOR EQUAL 3 AND CMAKE_VERSION_MINOR GREATER_EQUAL 8) OR CMAKE_VERSION_MAJOR GREATER 3)
6-
set(CMAKE_POLICY_DEFAULT_CMP0067 NEW)
7-
endif()
8-
1+
set(CMAKE_POLICY_DEFAULT_CMP0066 NEW)
2+
set(CMAKE_POLICY_DEFAULT_CMP0067 NEW)
93
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12)

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

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace Xamarin.Android.Prepare
1010
partial class BuildInfo : AppObject
1111
{
1212
static readonly char[] NDKPropertySeparator = new [] { '=' };
13-
static readonly char[] NDKPlatformDirectorySeparator = new [] { '-' };
1413

1514
public string CommitOfLastVersionChange { get; private set; } = String.Empty;
1615

@@ -38,9 +37,10 @@ public async Task GatherGitInfo (Context context)
3837
Log.StatusLine ();
3938
}
4039

41-
public bool GatherNDKInfo (Context context, string ndkRoot)
40+
public bool GatherNDKInfo (Context context)
4241
{
43-
string props = Path.Combine (ndkRoot, "source.properties");
42+
string ndkDir = Configurables.Paths.AndroidNdkDirectory;
43+
string props = Path.Combine (ndkDir, "source.properties");
4444
if (!File.Exists (props)) {
4545
Log.ErrorLine ("NDK properties file does not exist: ", props, tailColor: Log.DestinationColor);
4646
return false;
@@ -71,24 +71,32 @@ public bool GatherNDKInfo (Context context, string ndkRoot)
7171
break;
7272
}
7373

74+
Log.DebugLine ($"Looking for minimum API available in {ndkDir}");
7475
int minimumApi = Int32.MaxValue;
75-
string platforms = Path.Combine (ndkRoot, "platforms");
76-
foreach (string p in Directory.EnumerateDirectories (platforms, "android-*", SearchOption.TopDirectoryOnly)) {
77-
string pdir = Path.GetFileName (p);
78-
string[] parts = pdir.Split (NDKPlatformDirectorySeparator, 2);
79-
if (parts.Length != 2)
80-
continue;
81-
82-
int api;
83-
if (!Int32.TryParse (parts [1].Trim (), out api))
84-
continue;
85-
86-
if (api >= minimumApi)
87-
continue;
88-
89-
minimumApi = api;
76+
foreach (var kvp in Configurables.Defaults.AndroidToolchainPrefixes) {
77+
string dirName = kvp.Value;
78+
string platforms = Path.Combine (Configurables.Paths.AndroidToolchainSysrootLibDirectory, dirName);
79+
Log.DebugLine ($" searching in {platforms}");
80+
foreach (string p in Directory.EnumerateDirectories (platforms, "*", SearchOption.TopDirectoryOnly)) {
81+
string plibc = Path.Combine (p, "libc.so");
82+
if (!Utilities.FileExists (plibc)) {
83+
continue;
84+
}
85+
86+
Log.DebugLine ($" found {p}");
87+
string pdir = Path.GetFileName (p);
88+
int api;
89+
if (!Int32.TryParse (pdir, out api))
90+
continue;
91+
92+
if (api >= minimumApi)
93+
continue;
94+
95+
minimumApi = api;
96+
}
9097
}
9198

99+
Log.DebugLine ($"Detected minimum NDK API level: {minimumApi}");
92100
NDKMinimumApiAvailable = minimumApi.ToString ();
93101
return true;
94102
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static class KnownProperties
2222
public const string DotNetPreviewVersionFull = "DotNetPreviewVersionFull";
2323
public const string EmulatorVersion = "EmulatorVersion";
2424
public const string EmulatorPkgRevision = "EmulatorPkgRevision";
25+
public const string HostOS = "HostOS";
2526
public const string IgnoreMaxMonoVersion = "IgnoreMaxMonoVersion";
2627
public const string IgnoreMinMonoVersion = "IgnoreMinMonoVersion";
2728
public const string JavaInteropFullPath = "JavaInteropFullPath";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace Xamarin.Android.Prepare
4+
{
5+
class NDKTool
6+
{
7+
public string Name { get; }
8+
public string DestinationName { get; } = String.Empty;
9+
10+
public NDKTool (string name, string? destinationName = null)
11+
{
12+
if (name.Trim ().Length == 0) {
13+
throw new ArgumentException (nameof (name), "must not be empty");
14+
}
15+
Name = name;
16+
if (String.IsNullOrWhiteSpace (destinationName)) {
17+
return;
18+
}
19+
DestinationName = destinationName!;
20+
}
21+
}
22+
}

build-tools/xaprepare/xaprepare/Application/Properties.Defaults.cs.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace Xamarin.Android.Prepare
2626
properties.Add (KnownProperties.DotNetPreviewVersionFull, StripQuotes ("@DotNetPreviewVersionFull@"));
2727
properties.Add (KnownProperties.EmulatorVersion, StripQuotes ("@EmulatorVersion@"));
2828
properties.Add (KnownProperties.EmulatorPkgRevision, StripQuotes ("@EmulatorPkgRevision@"));
29+
properties.Add (KnownProperties.HostOS, StripQuotes ("@HostOS@"));
2930
properties.Add (KnownProperties.IgnoreMaxMonoVersion, StripQuotes ("@IgnoreMaxMonoVersion@"));
3031
properties.Add (KnownProperties.IgnoreMinMonoVersion, StripQuotes ("@IgnoreMinMonoVersion@"));
3132
properties.Add (KnownProperties.JavaInteropFullPath, StripQuotes (@"@JavaInteropFullPath@"));

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

Lines changed: 2 additions & 2 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 = "21d";
9-
public const string AndroidNdkPkgRevision = "21.3.6528147";
8+
public const string AndroidNdkVersion = "22";
9+
public const string AndroidNdkPkgRevision = "22.0.7026061";
1010

1111
public static readonly List<AndroidPlatform> AllPlatforms = new List<AndroidPlatform> {
1212
new AndroidPlatform (apiName: "", apiLevel: 1, platformID: "1"),

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ public static partial class Defaults
266266
/// </summary>
267267
public static readonly List <string> BuildStatusBundleExclude = new List <string> {
268268
};
269+
270+
public static readonly List <NDKTool> NDKTools = new List<NDKTool> {
271+
new NDKTool (name: "as"),
272+
new NDKTool (name: "ld.gold", destinationName: "ld"),
273+
new NDKTool (name: "strip"),
274+
};
269275
}
270276

271277
public static partial class Paths
@@ -362,7 +368,12 @@ public static partial class Paths
362368
public static string MonoArchiveWindowsLocalPath => Path.Combine (ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainCacheDirectory), MonoArchiveWindowsFileName);
363369

364370
// Other
365-
public static string AndroidToolchainBinDirectory => EnsureAndroidToolchainBinDirectories ();
371+
public static string AndroidNdkDirectory => ctx.Properties.GetRequiredValue (KnownProperties.AndroidNdkDirectory);
372+
public static string AndroidToolchainRootDirectory => GetCachedPath (ref androidToolchainRootDirectory, () => Path.Combine (AndroidNdkDirectory, "toolchains", "llvm", "prebuilt", NdkToolchainOSTag));
373+
public static string AndroidToolchainBinDirectory => GetCachedPath (ref androidToolchainBinDirectory, () => Path.Combine (AndroidToolchainRootDirectory, "bin"));
374+
public static string AndroidToolchainSysrootLibDirectory => GetCachedPath (ref androidToolchainSysrootLibDirectory, () => Path.Combine (AndroidToolchainRootDirectory, "sysroot", "usr", "lib"));
375+
public static string WindowsBinutilsInstallDir => GetCachedPath (ref windowsBinutilsInstallDir, () => Path.Combine (InstallMSBuildDir, "ndk"));
376+
public static string HostBinutilsInstallDir => GetCachedPath (ref hostBinutilsInstallDir, () => Path.Combine (InstallMSBuildDir, ctx.Properties.GetRequiredValue (KnownProperties.HostOS), "ndk"));
366377

367378
// not really configurables, merely convenience aliases for more frequently used paths that come from properties
368379
public static string XAInstallPrefix => ctx.Properties.GetRequiredValue (KnownProperties.XAInstallPrefix);
@@ -410,7 +421,9 @@ static string GetCachedPath (ref string? variable, Func<string> creator)
410421
static string? binDir;
411422
static string? netCoreBinDir;
412423
static string? monoSDKsOutputDir;
424+
static string? androidToolchainRootDirectory;
413425
static string? androidToolchainBinDirectory;
426+
static string? androidToolchainSysrootLibDirectory;
414427
static string? monoProfileDir;
415428
static string? monoProfileToolsDir;
416429
static string? bclTestsDestDir;
@@ -449,6 +462,8 @@ static string GetCachedPath (ref string? variable, Func<string> creator)
449462
static string? openJDK8CacheDir, openJDK11CacheDir;
450463
static string? oldOpenJDKInstallDir;
451464
static string? configurationPropsGeneratedPath;
465+
static string? windowsBinutilsInstallDir;
466+
static string? hostBinutilsInstallDir;
452467
}
453468
}
454469
}

build-tools/xaprepare/xaprepare/OperatingSystems/OS.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ string GetExecutableWithExtension (string programPath, Func<string, string> find
521521
return String.Empty;
522522
}
523523

524+
public virtual string AppendExecutableExtension (string programName)
525+
{
526+
return programName;
527+
}
528+
524529
protected static string FindProgram (string programName, List<string> directories)
525530
{
526531
foreach (string dir in directories) {

build-tools/xaprepare/xaprepare/OperatingSystems/Windows.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ public override string Which (string programPath, bool required = true)
8080
return base.Which (programPath, required);
8181
}
8282

83+
public override string AppendExecutableExtension (string programName)
84+
{
85+
string ext = Path.GetExtension (programName);
86+
if (String.Compare (".exe", ext, StringComparison.OrdinalIgnoreCase) == 0) {
87+
return programName;
88+
}
89+
90+
return $"{programName}.exe";
91+
}
92+
8393
protected override string AssertIsExecutable (string fullPath)
8494
{
8595
return fullPath;

0 commit comments

Comments
 (0)