Skip to content

Commit

Permalink
Update the Android NDK to r27c and update to 16kb alignment (#3096) (#…
Browse files Browse the repository at this point in the history
…3099)

* 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

(cherry picked from commit db01ee1)

Co-authored-by: Matthew Leibowitz <[email protected]>
  • Loading branch information
github-actions[bot] and mattleibow authored Dec 4, 2024
1 parent ea04534 commit de16bbc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
33 changes: 31 additions & 2 deletions native/android/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ DirectoryPath ANDROID_NDK_HOME = Argument("ndk", EnvironmentVariable("ANDROID_ND
string SUPPORT_VULKAN_VAR = Argument ("supportVulkan", EnvironmentVariable ("SUPPORT_VULKAN") ?? "true");
bool SUPPORT_VULKAN = SUPPORT_VULKAN_VAR == "1" || SUPPORT_VULKAN_VAR.ToLower () == "true";

Information("Android NDK Path: {0}", ANDROID_NDK_HOME);
Information("Building Vulkan: {0}", SUPPORT_VULKAN);

void CheckAlignment(FilePath so)
{
Information($"Making sure that everything is 16 KB aligned...");

var prebuilt = ANDROID_NDK_HOME.CombineWithFilePath("toolchains/llvm/prebuilt").FullPath;
var objdump = GetFiles($"{prebuilt}/*/bin/llvm-objdump*").FirstOrDefault() ?? throw new Exception("Could not find llvm-objdump");
RunProcess(objdump.FullPath, $"-p {so}", out var stdout);

var loads = stdout
.Where(l => l.Trim().StartsWith("LOAD"))
.ToList();

if (loads.Any(l => !l.Trim().EndsWith("align 2**14"))) {
Information(String.Join(Environment.NewLine + " ", stdout));
throw new Exception($"{so} contained a LOAD that was not 16 KB aligned.");
} else {
Information("Everything is 16 KB aligned:");
Information(String.Join(Environment.NewLine, loads));
}
}

Task("libSkiaSharp")
.IsDependentOn("git-sync-deps")
.WithCriteria(IsRunningOnMacOs() || IsRunningOnWindows())
Expand Down Expand Up @@ -38,12 +62,15 @@ Task("libSkiaSharp")
$"skia_use_vulkan={SUPPORT_VULKAN} ".ToLower () +
$"skia_enable_skottie=true " +
$"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_SYSCALL_GETRANDOM', '-DXML_DEV_URANDOM' ] " +
$"extra_ldflags=[ '-Wl,-z,max-page-size=16384' ] " +
$"ndk='{ANDROID_NDK_HOME}' " +
$"ndk_api=21");

var so = SKIA_PATH.CombineWithFilePath($"out/android/{arch}/libSkiaSharp.so");
var outDir = OUTPUT_PATH.Combine(arch);
EnsureDirectoryExists(outDir);
CopyFileToDirectory(SKIA_PATH.CombineWithFilePath($"out/android/{arch}/libSkiaSharp.so"), outDir);
CopyFileToDirectory(so, outDir);
CheckAlignment(so);
}
});

Expand All @@ -68,9 +95,11 @@ Task("libHarfBuzzSharp")
WorkingDirectory = "libHarfBuzzSharp",
});

var so = $"libHarfBuzzSharp/libs/{arch}/libHarfBuzzSharp.so";
var outDir = OUTPUT_PATH.Combine(arch);
EnsureDirectoryExists(outDir);
CopyFileToDirectory($"libHarfBuzzSharp/libs/{arch}/libHarfBuzzSharp.so", outDir);
CopyFileToDirectory(so, outDir);
CheckAlignment(so);
}
});

Expand Down
1 change: 1 addition & 0 deletions native/android/libHarfBuzzSharp/jni/Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ APP_PLATFORM := android-21
NDK_TOOLCHAIN_VERSION := clang
APP_STL := c++_static
APP_OPTIM := release
APP_SUPPORT_FLEXIBLE_PAGE_SIZES := true
2 changes: 1 addition & 1 deletion native/android/libHarfBuzzSharp/jni/HarfBuzzSharp.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LOCAL_MODULE := HarfBuzzSharp

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

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

LOCAL_CFLAGS := -DNDEBUG \
-DHAVE_CONFIG_OVERRIDE_H -DHAVE_OT -DHB_NO_FALLBACK_SHAPE \
Expand Down
2 changes: 1 addition & 1 deletion scripts/install-android-ndk.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Param(
[string] $Version = "r25c",
[string] $Version = "r27c",
[string] $InstallDestination = $null
)

Expand Down

0 comments on commit de16bbc

Please sign in to comment.