Skip to content

Commit db01ee1

Browse files
authored
Update the Android NDK to r27c and update to 16kb alignment (#3096)
* Update the Android NDK to r27c * Set the max page size to be 16kb * https://developer.android.com/guide/practices/page-sizes * https://android-developers.googleblog.com/2024/08/adding-16-kb-page-size-to-android.html * Add a test
1 parent 7ac6027 commit db01ee1

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

native/android/build.cake

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@ DirectoryPath ANDROID_NDK_HOME = Argument("ndk", EnvironmentVariable("ANDROID_ND
88
string SUPPORT_VULKAN_VAR = Argument ("supportVulkan", EnvironmentVariable ("SUPPORT_VULKAN") ?? "true");
99
bool SUPPORT_VULKAN = SUPPORT_VULKAN_VAR == "1" || SUPPORT_VULKAN_VAR.ToLower () == "true";
1010

11+
Information("Android NDK Path: {0}", ANDROID_NDK_HOME);
12+
Information("Building Vulkan: {0}", SUPPORT_VULKAN);
13+
14+
void CheckAlignment(FilePath so)
15+
{
16+
Information($"Making sure that everything is 16 KB aligned...");
17+
18+
var prebuilt = ANDROID_NDK_HOME.CombineWithFilePath("toolchains/llvm/prebuilt").FullPath;
19+
var objdump = GetFiles($"{prebuilt}/*/bin/llvm-objdump*").FirstOrDefault() ?? throw new Exception("Could not find llvm-objdump");
20+
RunProcess(objdump.FullPath, $"-p {so}", out var stdout);
21+
22+
var loads = stdout
23+
.Where(l => l.Trim().StartsWith("LOAD"))
24+
.ToList();
25+
26+
if (loads.Any(l => !l.Trim().EndsWith("align 2**14"))) {
27+
Information(String.Join(Environment.NewLine + " ", stdout));
28+
throw new Exception($"{so} contained a LOAD that was not 16 KB aligned.");
29+
} else {
30+
Information("Everything is 16 KB aligned:");
31+
Information(String.Join(Environment.NewLine, loads));
32+
}
33+
}
34+
1135
Task("libSkiaSharp")
1236
.IsDependentOn("git-sync-deps")
1337
.WithCriteria(IsRunningOnMacOs() || IsRunningOnWindows())
@@ -38,12 +62,15 @@ Task("libSkiaSharp")
3862
$"skia_use_vulkan={SUPPORT_VULKAN} ".ToLower () +
3963
$"skia_enable_skottie=true " +
4064
$"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_SYSCALL_GETRANDOM', '-DXML_DEV_URANDOM' ] " +
65+
$"extra_ldflags=[ '-Wl,-z,max-page-size=16384' ] " +
4166
$"ndk='{ANDROID_NDK_HOME}' " +
4267
$"ndk_api=21");
4368

69+
var so = SKIA_PATH.CombineWithFilePath($"out/android/{arch}/libSkiaSharp.so");
4470
var outDir = OUTPUT_PATH.Combine(arch);
4571
EnsureDirectoryExists(outDir);
46-
CopyFileToDirectory(SKIA_PATH.CombineWithFilePath($"out/android/{arch}/libSkiaSharp.so"), outDir);
72+
CopyFileToDirectory(so, outDir);
73+
CheckAlignment(so);
4774
}
4875
});
4976

@@ -68,9 +95,11 @@ Task("libHarfBuzzSharp")
6895
WorkingDirectory = "libHarfBuzzSharp",
6996
});
7097

98+
var so = $"libHarfBuzzSharp/libs/{arch}/libHarfBuzzSharp.so";
7199
var outDir = OUTPUT_PATH.Combine(arch);
72100
EnsureDirectoryExists(outDir);
73-
CopyFileToDirectory($"libHarfBuzzSharp/libs/{arch}/libHarfBuzzSharp.so", outDir);
101+
CopyFileToDirectory(so, outDir);
102+
CheckAlignment(so);
74103
}
75104
});
76105

native/android/libHarfBuzzSharp/jni/Application.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ APP_PLATFORM := android-21
33
NDK_TOOLCHAIN_VERSION := clang
44
APP_STL := c++_static
55
APP_OPTIM := release
6+
APP_SUPPORT_FLEXIBLE_PAGE_SIZES := true

native/android/libHarfBuzzSharp/jni/HarfBuzzSharp.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LOCAL_MODULE := HarfBuzzSharp
1010

1111
LOCAL_C_INCLUDES := . $(src_root) $(ext_root)
1212

13-
LOCAL_LDFLAGS := -s -Wl,--gc-sections
13+
LOCAL_LDFLAGS := -s -Wl,--gc-sections -Wl,-z,max-page-size=16384
1414

1515
LOCAL_CFLAGS := -DNDEBUG \
1616
-DHAVE_CONFIG_OVERRIDE_H -DHAVE_OT -DHB_NO_FALLBACK_SHAPE \

scripts/install-android-ndk.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Param(
2-
[string] $Version = "r25c",
2+
[string] $Version = "r27c",
33
[string] $InstallDestination = $null
44
)
55

0 commit comments

Comments
 (0)