diff --git a/native/android/build.cake b/native/android/build.cake index e677e664a3..1a41d85d87 100644 --- a/native/android/build.cake +++ b/native/android/build.cake @@ -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()) @@ -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); } }); @@ -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); } }); diff --git a/native/android/libHarfBuzzSharp/jni/Application.mk b/native/android/libHarfBuzzSharp/jni/Application.mk index 84ee05cc4c..6c1ddb9f00 100644 --- a/native/android/libHarfBuzzSharp/jni/Application.mk +++ b/native/android/libHarfBuzzSharp/jni/Application.mk @@ -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 diff --git a/native/android/libHarfBuzzSharp/jni/HarfBuzzSharp.mk b/native/android/libHarfBuzzSharp/jni/HarfBuzzSharp.mk index 62e66f9efe..6536c71bde 100644 --- a/native/android/libHarfBuzzSharp/jni/HarfBuzzSharp.mk +++ b/native/android/libHarfBuzzSharp/jni/HarfBuzzSharp.mk @@ -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 \ diff --git a/scripts/install-android-ndk.ps1 b/scripts/install-android-ndk.ps1 index 9957ea1436..bbd1bddc2b 100644 --- a/scripts/install-android-ndk.ps1 +++ b/scripts/install-android-ndk.ps1 @@ -1,5 +1,5 @@ Param( - [string] $Version = "r25c", + [string] $Version = "r27c", [string] $InstallDestination = $null )