From 336ff9cb97c18101a822128715cab0745d1c9469 Mon Sep 17 00:00:00 2001 From: Luke Mann Date: Fri, 16 Jan 2026 09:53:01 -0800 Subject: [PATCH] add 16kb align config --- .cargo/config.toml | 40 ++++++++++++++++++++++++++++++++++++++++ Cross.toml | 7 +++++++ 2 files changed, 47 insertions(+) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 000000000..30b5afd43 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,40 @@ +# Configuration for direct cargo builds (without cross) + +# max-page-size=16384: +# Android 15 (API 35) introduces support for 16KB page sizes to improve performance on devices with larger RAM. +# Apps with native libraries MUST be compiled with 16KB ELF alignment or they will crash on startup +# on devices configured with 16KB page sizes. This flag ensures proper alignment for both 32-bit and 64-bit targets. +# Reference: https://developer.android.com/guide/practices/page-sizes +# common-page-size=4096: +# -z max-page-size=16384 is what makes the ELF safely load on 16 KB-page kernels. Bumping -z common-page-size to 16 KB doesn’t improve compatibility, but it does increase padding and memory waste on 4 KB devices. +[target.aarch64-linux-android] +rustflags = [ + "-Clink-arg=-z", + "-Clink-arg=max-page-size=16384", + "-Clink-arg=-z", + "-Clink-arg=common-page-size=4096", +] + +[target.armv7-linux-androideabi] +rustflags = [ + "-Clink-arg=-z", + "-Clink-arg=max-page-size=16384", + "-Clink-arg=-z", + "-Clink-arg=common-page-size=4096", +] + +[target.i686-linux-android] +rustflags = [ + "-Clink-arg=-z", + "-Clink-arg=max-page-size=16384", + "-Clink-arg=-z", + "-Clink-arg=common-page-size=4096", +] + +[target.x86_64-linux-android] +rustflags = [ + "-Clink-arg=-z", + "-Clink-arg=max-page-size=16384", + "-Clink-arg=-z", + "-Clink-arg=common-page-size=4096", +] diff --git a/Cross.toml b/Cross.toml index 22ce50dfd..779abe3d7 100644 --- a/Cross.toml +++ b/Cross.toml @@ -1,3 +1,10 @@ +# max-page-size=16384: +# Android 15 (API 35) introduces support for 16KB page sizes to improve performance on devices with larger RAM. +# Apps with native libraries MUST be compiled with 16KB ELF alignment or they will crash on startup +# on devices configured with 16KB page sizes. This flag ensures proper alignment for both 32-bit and 64-bit targets. +# Reference: https://developer.android.com/guide/practices/page-sizes +RUSTFLAGS = "-C link-arg=-Wl,-z,max-page-size=16384" + [build] pre-build = [ "dpkg --add-architecture $CROSS_DEB_ARCH",