classification
Title: $CPP invocation in configure must use $CPPFLAGS
Type: compile error Stage: resolved
Components: Cross-Build Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Alex.Willmer, doko, python-dev, thomas-petazzoni, vstinner, xdegaye, yan12125
Priority: normal Keywords: patch

Created on 2016-07-05 11:18 by yan12125, last changed 2016-07-30 09:43 by xdegaye. This issue is now closed.

Files
File name Uploaded Description Edit
ndk-clang-preprocessor.patch yan12125, 2016-07-05 11:18 review
Messages (6)
msg269816 - (view) Author: Chih-Hsuan Yen (yan12125) * Date: 2016-07-05 11:18
Motivation: Android NDK is deprecating GCC and moving ot Clang/LLVM. From [1]:

We strongly recommend switching to Clang.
GCC in the NDK is now deprecated in favor of Clang.

This patch fixes the only one problem when migrating GCC to Clang.

In my build script, $CPP is set to "${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -E" and $CPPFLAGS is set to "-target armv7-none-linux-androideabi -gcc-toolchain ${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot ${ANDROID_NDK}/platforms/android-21/arch-arm/usr -I${PREFIX}/include -DANDROID". I'm not sure whether it's the correct usage of clang, but at least it works.

With such a configuration, most Python parts builds well. Just something wrong - extensions as built as xyz.cpython-36m-x86_64-linux-gnu.so. My patch just fixes $(PLATFORM_TRIPLET) detection.

[1] https://developer.android.com/ndk/downloads/revision_history.html
msg269824 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-07-05 15:00
With configure run as './configure CC="$(CC)" ...' and when CC is set to:
CC = clang --sysroot=$(SYSROOT) -target $(TARGET) -gcc-toolchain $(GCC_TOOLCHAIN)

and building for armv7 on android-21, then configure runs $CPP as:

checking for CPP... clang --sysroot=/opt/android-ndk/platforms/android-21/arch-arm -target armv7-none-linux-androideabi -gcc-toolchain /opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -E

as can be seen by inserting in configure.ac:
AC_MSG_CHECKING([for CPP])
AC_MSG_RESULT([$CPP])

and the shared libraries are named 'module_name.cpython-36m-arm-linux-gnueabi.so'.

OTOH, the 'configure' script runs its own preprocessings with the following idiom:
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "memchr" >/dev/null 2>&1; then :

where 'ac_cpp' is set to ac_cpp='$CPP $CPPFLAGS'.
So the proposed patch LGTM.

PLATFORM_TRIPLETs are specific to multiarch systems such as debian and should not be relied upon on Android, but they should not be entirely wrong of course.
msg269827 - (view) Author: Chih-Hsuan Yen (yan12125) * Date: 2016-07-05 15:31
Several days ago I have once tried to set
CC="clang -target $(TARGET) -gcc-toolchain $(GCC_TOOLCHAIN)", and it failed to build some dependency of Python (I can't remember). Just tried  and everything is OK. Dunno what's changed. Anyway both approaches (-target in $CC/$CXX/$CPP and -target in $CFLAGS/$CXXFLAGS/$CPPFLAGS) should be supported.
msg271637 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-07-29 17:04
ndk-clang-preprocessor.patch LGTM.
msg271670 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-07-30 09:40
New changeset 4cb94e561e2d by Xavier de Gaye in branch '3.5':
Issue #27453: CPP invocation in configure must use CPPFLAGS.
https://hg.python.org/cpython/rev/4cb94e561e2d

New changeset 92b3ce7ca95c by Xavier de Gaye in branch 'default':
(merge from 3.5) Issue #27453: CPP invocation in configure must use CPPFLAGS.
https://hg.python.org/cpython/rev/92b3ce7ca95c
msg271671 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-07-30 09:43
Thanks for the patch Chi Hsuan Yen!
History
Date User Action Args
2016-07-30 09:43:22xdegayesetstatus: open -> closed
resolution: fixed
messages: + msg271671

stage: commit review -> resolved
2016-07-30 09:40:05python-devsetnosy: + python-dev
messages: + msg271670
2016-07-29 17:04:48vstinnersetmessages: + msg271637
2016-07-29 15:41:33xdegayesetnosy: + vstinner

stage: commit review
2016-07-29 10:26:08xdegayesetnosy: + thomas-petazzoni
2016-07-06 10:23:16xdegayesettitle: Fix cross-compilation with Android NDK and Clang -> $CPP invocation in configure must use $CPPFLAGS
versions: + Python 3.5
2016-07-05 15:31:50yan12125setmessages: + msg269827
2016-07-05 15:00:49xdegayesetnosy: + doko
messages: + msg269824
2016-07-05 11:18:43yan12125create