Skip to content

Commit 80da503

Browse files
committed
gh-146541: Allow building the Android testbed for 32-bit targets
This allows building the Android testbed for 32-bit targets using the prebuilt 32-bit dependencies that are already available here: https://github.com/beeware/cpython-android-source-deps/releases , adding the target triplets to match them, `arm-linux-androideabi` and `i686-linux-android`. This also adds the `arm` key to the dictionary used to convert the `machine` variable to an Android ABI in `sysconfig.get_platform()`, because when the Android testbed is being cross-compiled, it stores the contents of the first substring of `_PYTHON_HOST_PLATFORM` before the first `-` symbol in the `machine` variable, which the dictionary does not currently handle.
1 parent 617f4cc commit 80da503

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

Android/android.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
TESTBED_DIR = ANDROID_DIR / "testbed"
3535
CROSS_BUILD_DIR = PYTHON_DIR / "cross-build"
3636

37-
HOSTS = ["aarch64-linux-android", "x86_64-linux-android"]
37+
HOSTS = [
38+
"aarch64-linux-android",
39+
"arm-linux-androideabi",
40+
"i686-linux-android",
41+
"x86_64-linux-android",
42+
]
3843
APP_ID = "org.python.testbed"
3944
DECODE_ARGS = ("UTF-8", "backslashreplace")
4045

Android/testbed/app/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ val inSourceTree = (
1515

1616
val KNOWN_ABIS = mapOf(
1717
"aarch64-linux-android" to "arm64-v8a",
18+
"arm-linux-androideabi" to "armeabi-v7a",
19+
"i686-linux-android" to "x86",
1820
"x86_64-linux-android" to "x86_64",
1921
)
2022

Lib/sysconfig/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,16 @@ def get_platform():
697697
# When Python is running on 32-bit ARM Android on a 64-bit ARM kernel,
698698
# 'os.uname().machine' is 'armv8l'. Such devices run the same userspace
699699
# code as 'armv7l' devices.
700+
# During the build process of the Android testbed when targeting 32-bit ARM,
701+
# '_PYTHON_HOST_PLATFORM' is 'arm-linux-androideabi', so 'machine' becomes
702+
# 'arm'.
700703
machine = {
701-
"x86_64": "x86_64",
702-
"i686": "x86",
703704
"aarch64": "arm64_v8a",
705+
"arm": "armeabi_v7a",
704706
"armv7l": "armeabi_v7a",
705707
"armv8l": "armeabi_v7a",
708+
"i686": "x86",
709+
"x86_64": "x86_64",
706710
}[machine]
707711
elif osname == "linux":
708712
# At least on Linux/Intel, 'machine' is the processor --

Lib/test/test_sysconfig.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,12 @@ def test_get_platform(self):
371371
sys.platform = 'android'
372372
get_config_vars()['ANDROID_API_LEVEL'] = 9
373373
for machine, abi in {
374-
'x86_64': 'x86_64',
375-
'i686': 'x86',
376374
'aarch64': 'arm64_v8a',
375+
'arm': 'armeabi_v7a',
377376
'armv7l': 'armeabi_v7a',
378377
'armv8l': 'armeabi_v7a',
378+
'i686': 'x86',
379+
'x86_64': 'x86_64',
379380
}.items():
380381
with self.subTest(machine):
381382
self._set_uname(('Linux', 'localhost', '3.18.91+',
@@ -580,11 +581,12 @@ def test_android_ext_suffix(self):
580581
machine = platform.machine()
581582
suffix = sysconfig.get_config_var('EXT_SUFFIX')
582583
expected_triplet = {
583-
"x86_64": "x86_64-linux-android",
584-
"i686": "i686-linux-android",
585584
"aarch64": "aarch64-linux-android",
585+
"arm": "arm-linux-androideabi",
586586
"armv7l": "arm-linux-androideabi",
587587
"armv8l": "arm-linux-androideabi",
588+
"i686": "i686-linux-android",
589+
"x86_64": "x86_64-linux-android",
588590
}[machine]
589591
self.assertEndsWith(suffix, f"-{expected_triplet}.so")
590592

0 commit comments

Comments
 (0)