Skip to content

Commit 6beb616

Browse files
mhsmithSonicField
authored andcommitted
pythongh-116622: Android sysconfig updates (python#118352)
1 parent 70afd78 commit 6beb616

File tree

6 files changed

+53
-5
lines changed

6 files changed

+53
-5
lines changed

Android/android-env.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ done
6161
export CFLAGS=""
6262
export LDFLAGS="-Wl,--build-id=sha1 -Wl,--no-rosegment"
6363

64+
# Unlike Linux, Android does not implicitly use a dlopened library to resolve
65+
# relocations in subsequently-loaded libraries, even if RTLD_GLOBAL is used
66+
# (https://github.com/android/ndk/issues/1244). So any library that fails to
67+
# build with this flag, would also fail to load at runtime.
68+
LDFLAGS="$LDFLAGS -Wl,--no-undefined"
69+
6470
# Many packages get away with omitting -lm on Linux, but Android is stricter.
6571
LDFLAGS="$LDFLAGS -lm"
6672

Lib/sysconfig/__init__.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,22 @@ def get_platform():
601601
machine = machine.replace('/', '-')
602602

603603
if osname[:5] == "linux":
604-
# At least on Linux/Intel, 'machine' is the processor --
605-
# i386, etc.
606-
# XXX what about Alpha, SPARC, etc?
607-
return f"{osname}-{machine}"
604+
if sys.platform == "android":
605+
osname = "android"
606+
release = get_config_var("ANDROID_API_LEVEL")
607+
608+
# Wheel tags use the ABI names from Android's own tools.
609+
machine = {
610+
"x86_64": "x86_64",
611+
"i686": "x86",
612+
"aarch64": "arm64_v8a",
613+
"armv7l": "armeabi_v7a",
614+
}[machine]
615+
else:
616+
# At least on Linux/Intel, 'machine' is the processor --
617+
# i386, etc.
618+
# XXX what about Alpha, SPARC, etc?
619+
return f"{osname}-{machine}"
608620
elif osname[:5] == "sunos":
609621
if release[0] >= "5": # SunOS 5 == Solaris 2
610622
osname = "solaris"

Lib/test/test_sysconfig.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ def test_get_config_vars(self):
232232
self.assertTrue(cvars)
233233

234234
def test_get_platform(self):
235+
# Check the actual platform returns something reasonable.
236+
actual_platform = get_platform()
237+
self.assertIsInstance(actual_platform, str)
238+
self.assertTrue(actual_platform)
239+
235240
# windows XP, 32bits
236241
os.name = 'nt'
237242
sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
@@ -347,6 +352,21 @@ def test_get_platform(self):
347352

348353
self.assertEqual(get_platform(), 'linux-i686')
349354

355+
# Android
356+
os.name = 'posix'
357+
sys.platform = 'android'
358+
get_config_vars()['ANDROID_API_LEVEL'] = 9
359+
for machine, abi in {
360+
'x86_64': 'x86_64',
361+
'i686': 'x86',
362+
'aarch64': 'arm64_v8a',
363+
'armv7l': 'armeabi_v7a',
364+
}.items():
365+
with self.subTest(machine):
366+
self._set_uname(('Linux', 'localhost', '3.18.91+',
367+
'#1 Tue Jan 9 20:35:43 UTC 2018', machine))
368+
self.assertEqual(get_platform(), f'android-9-{abi}')
369+
350370
# XXX more platforms to tests here
351371

352372
@unittest.skipIf(is_wasi, "Incompatible with WASI mapdir and OOT builds")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
On Android, :any:`sysconfig.get_platform` now returns the format specified
2+
by :pep:`738`.

configure

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,9 @@ AS_CASE([$host/$ac_cv_cc_name],
11481148
[x86_64-*-freebsd*/clang], [PY_SUPPORT_TIER=3], dnl FreeBSD on AMD64
11491149
[aarch64-apple-ios*-simulator/clang], [PY_SUPPORT_TIER=3], dnl iOS Simulator on arm64
11501150
[aarch64-apple-ios*/clang], [PY_SUPPORT_TIER=3], dnl iOS on ARM64
1151+
[aarch64-*-linux-android/clang], [PY_SUPPORT_TIER=3], dnl Android on ARM64
1152+
[x86_64-*-linux-android/clang], [PY_SUPPORT_TIER=3], dnl Android on AMD64
1153+
11511154
[PY_SUPPORT_TIER=0]
11521155
)
11531156

0 commit comments

Comments
 (0)