Skip to content

Commit 6c4c045

Browse files
mhsmithmiss-islington
authored andcommitted
gh-125940: Android: support 16 KB pages (GH-125941)
Modify Android build tooling to use 16kB pages. (cherry picked from commit e68d4b0) Co-authored-by: Malcolm Smith <[email protected]>
1 parent d46d291 commit 6c4c045

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

Android/android-env.sh

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fail() {
2424
# * https://android.googlesource.com/platform/ndk/+/ndk-rXX-release/docs/BuildSystemMaintainers.md
2525
# where XX is the NDK version. Do a diff against the version you're upgrading from, e.g.:
2626
# https://android.googlesource.com/platform/ndk/+/ndk-r25-release..ndk-r26-release/docs/BuildSystemMaintainers.md
27-
ndk_version=26.2.11394342
27+
ndk_version=27.1.12297006
2828

2929
ndk=$ANDROID_HOME/ndk/$ndk_version
3030
if ! [ -e $ndk ]; then
@@ -58,8 +58,8 @@ for path in "$AR" "$AS" "$CC" "$CXX" "$LD" "$NM" "$RANLIB" "$READELF" "$STRIP";
5858
fi
5959
done
6060

61-
export CFLAGS=""
62-
export LDFLAGS="-Wl,--build-id=sha1 -Wl,--no-rosegment"
61+
export CFLAGS="-D__BIONIC_NO_PAGE_SIZE_MACRO"
62+
export LDFLAGS="-Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,-z,max-page-size=16384"
6363

6464
# Unlike Linux, Android does not implicitly use a dlopened library to resolve
6565
# relocations in subsequently-loaded libraries, even if RTLD_GLOBAL is used
@@ -85,6 +85,10 @@ if [ -n "${PREFIX:-}" ]; then
8585
export PKG_CONFIG_LIBDIR="$abs_prefix/lib/pkgconfig"
8686
fi
8787

88+
# When compiling C++, some build systems will combine CFLAGS and CXXFLAGS, and some will
89+
# use CXXFLAGS alone.
90+
export CXXFLAGS=$CFLAGS
91+
8892
# Use the same variable name as conda-build
8993
if [ $(uname) = "Darwin" ]; then
9094
export CPU_COUNT=$(sysctl -n hw.ncpu)

Android/android.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ def make_build_python(context):
138138

139139
def unpack_deps(host):
140140
deps_url = "https://github.com/beeware/cpython-android-source-deps/releases/download"
141-
for name_ver in ["bzip2-1.0.8-1", "libffi-3.4.4-2", "openssl-3.0.15-0",
142-
"sqlite-3.45.1-0", "xz-5.4.6-0"]:
141+
for name_ver in ["bzip2-1.0.8-2", "libffi-3.4.4-3", "openssl-3.0.15-4",
142+
"sqlite-3.45.3-3", "xz-5.4.6-1"]:
143143
filename = f"{name_ver}-{host}.tar.gz"
144144
download(f"{deps_url}/{name_ver}/{filename}")
145145
run(["tar", "-xf", filename])
@@ -189,12 +189,13 @@ def configure_host_python(context):
189189

190190
def make_host_python(context):
191191
# The CFLAGS and LDFLAGS set in android-env include the prefix dir, so
192-
# delete any previously-installed Python libs and include files to prevent
193-
# them being used during the build.
192+
# delete any previous Python installation to prevent it being used during
193+
# the build.
194194
host_dir = subdir(context.host)
195195
prefix_dir = host_dir / "prefix"
196196
delete_glob(f"{prefix_dir}/include/python*")
197197
delete_glob(f"{prefix_dir}/lib/libpython*")
198+
delete_glob(f"{prefix_dir}/lib/python*")
198199

199200
os.chdir(host_dir / "build")
200201
run(["make", "-j", str(os.cpu_count())], host=context.host)

Android/testbed/app/build.gradle.kts

+12-11
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ val PYTHON_VERSION = file("$PYTHON_DIR/Include/patchlevel.h").useLines {
3030
throw GradleException("Failed to find Python version")
3131
}
3232

33-
android.ndkVersion = file("../../android-env.sh").useLines {
34-
for (line in it) {
35-
val match = """ndk_version=(\S+)""".toRegex().find(line)
36-
if (match != null) {
37-
return@useLines match.groupValues[1]
38-
}
39-
}
40-
throw GradleException("Failed to find NDK version")
41-
}
42-
4333

4434
android {
4535
namespace = "org.python.testbed"
@@ -55,11 +45,22 @@ android {
5545
ndk.abiFilters.addAll(ABIS.keys)
5646
externalNativeBuild.cmake.arguments(
5747
"-DPYTHON_CROSS_DIR=$PYTHON_CROSS_DIR",
58-
"-DPYTHON_VERSION=$PYTHON_VERSION")
48+
"-DPYTHON_VERSION=$PYTHON_VERSION",
49+
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
50+
)
5951

6052
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
6153
}
6254

55+
val androidEnvFile = file("../../android-env.sh").absoluteFile
56+
ndkVersion = androidEnvFile.useLines {
57+
for (line in it) {
58+
"""ndk_version=(\S+)""".toRegex().find(line)?.let {
59+
return@useLines it.groupValues[1]
60+
}
61+
}
62+
throw GradleException("Failed to find NDK version in $androidEnvFile")
63+
}
6364
externalNativeBuild.cmake {
6465
path("src/main/c/CMakeLists.txt")
6566
}

Android/testbed/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
id("com.android.application") version "8.4.2" apply false
3+
id("com.android.application") version "8.6.1" apply false
44
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
55
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Mon Feb 19 20:29:06 GMT 2024
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The Android build now supports `16 KB page sizes
2+
<https://developer.android.com/guide/practices/page-sizes>`__.

0 commit comments

Comments
 (0)