Open ViliusSutkus89 opened 2 weeks ago
I have a workaround in def generate(self):
which sets the correct ENV vars for the toolchain, but it's not really fun applying that workaround to each affected package.
def generate(self):
tc = AutotoolsToolchain(self)
# ...
env = tc.environment()
if cross_building(self) and self.settings.os == "Android":
# NDK binary paths need to be supplied as posixpath, not os path, even on windows
# This means no backslashes, because scripts in NDK don't like backslashes
android_ndk_home = self.conf.get("tools.android:ndk_path").replace("\\", "/")
target_host_triple = {
"armv7": "armv7a-linux-androideabi",
"armv8": "aarch64-linux-android",
"x86": "i686-linux-android",
"x86_64": "x86_64-linux-android",
}[self.settings.get_safe("arch")]
api_level = self.settings.os.get_safe("api_level")
build_machine = "{}-x86_64".format({"Linux": "linux", "Macos": "darwin","Windows": "windows"}[str(self.settings_build.os)])
toolchain = posixpath.join(android_ndk_home, "toolchains", "llvm", "prebuilt", build_machine, "bin")
if self.settings_build.os == "Windows":
executable_suffix = ".exe"
else:
executable_suffix = ""
env.define("AR", posixpath.join(toolchain, "llvm-ar" + executable_suffix))
env.define("AS", posixpath.join(toolchain, "llvm-as" + executable_suffix))
env.define("RANLIB", posixpath.join(toolchain, "llvm-ranlib" + executable_suffix))
env.define("CC", posixpath.join(toolchain, "{}{}-clang".format(target_host_triple, api_level)))
env.define("CXX", posixpath.join(toolchain, "{}{}-clang++".format(target_host_triple, api_level)))
env.define("LD", posixpath.join(toolchain, "ld" + executable_suffix))
env.define("STRIP", posixpath.join(toolchain, "llvm-strip" + executable_suffix))
tc.generate(env)
Hi @ViliusSutkus89 thanks a lot for taking the time to report the issue, we appreciate it.
We'll take a look into this as soon as we can, you might be onto something :)
I've ran into more autotools packages that I want to use, so instead of patching every single one of them, I've added the toolchain to my host profile:
{% set android_home = os.getenv("ANDROID_HOME") %}
{% set ndk_version = "26.3.11579264" %}
{% set api_level = "21" %}
[settings]
os=Android
os.api_level={{api_level}}
arch=armv8
build_type=RelWithDebInfo
compiler=clang
compiler.version=17
compiler.cppstd=20
compiler.libcxx=c++_static
[conf]
tools.android:ndk_path={{android_home}}/ndk/{{ndk_version}}
[buildenv]
AR={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
AS={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-as
RANLIB={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib
CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android{{api_level}}-clang
CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android{{api_level}}-clang++
LD={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/ld
STRIP={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
CC
and CXX
are different for each abi:
CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi{{api_level}}-clang
CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi{{api_level}}-clang++
CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android{{api_level}}-clang
CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android{{api_level}}-clang++
CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android{{api_level}}-clang
CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android{{api_level}}-clang++
I still count this as a workaround, not a proper solution, because I would have to add it to host profiles of every downstream user of my Android libraries.
(Corrected armv7 CC and CXX values in the previous comment)
tools.android:ndk_path
is not a silver bullet.
There is indeed some magic in CMakeToolchain & MesonToolchain when tools.android:ndk_path
is set:
Except of that there is no magic, so your profile must provide these information. It's not really an issue for conancenter, but for conan client. The confusion comes from the fact that this micro-management of Android NDK details has been implemented in some conan helpers and not in others, so there is now an expectation from users that it should work out of the box irrespective of underlying build system.
Fully agree with the part that this is a conan client, not a conan center issue. Sorry about misfiling. Haven't looked much into conan client code yet, but I assume that it would be the correct place for a proper solution, not these profile workarounds.
moving this to conan client -!
Description
Hello, I'm trying to build some software for Android, but I've noticed that all of the autoconf packages are ignoring my host profile and just build for my build machine. This becomes apparent only when I try to link against the freshly built binary.
Here's a GitHub actions run illustrating the problem: https://github.com/ViliusSutkus89/conan-center-index/actions/runs/9534760342
CMake and Meson packages seem to be building fine, so it's just the Autotools
Package and Environment Details
Conan profile
Profile host: [settings] arch=armv8 build_type=Release compiler=clang compiler.cppstd=20 compiler.libcxx=c++_static compiler.version=17 os=Android os.api_level=23 [conf] tools.android:ndk_path=/usr/local/lib/android/sdk/ndk/26.3.11579264
Profile build: [settings] arch=x86_64 build_type=Release compiler=clang compiler.cppstd=17 compiler.libcxx=libstdc++11 compiler.version=15 os=Linux
Steps to reproduce
conan create recipes/libiconv/all/conanfile.py --version=1.17 --profile:host armv8
Logs
Click to expand log
``` ======== Calling build() ======== conanfile.py (libiconv/1.17): Calling build() conanfile.py (libiconv/1.17): RUN: "/home/runner/work/conan-center-index/conan-center-index/recipes/libiconv/all/src/configure" --disable-shared --enable-static --prefix=/ '--bindir=${prefix}/bin' '--sbindir=${prefix}/bin' '--libdir=${prefix}/lib' '--includedir=${prefix}/include' '--oldincludedir=${prefix}/include' --host=aarch64-linux-android --build=x86_64-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for aarch64-linux-android-strip... no checking for strip... strip configure: WARNING: using cross tools not prefixed with host triplet checking for a race-free mkdir -p... /usr/bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking whether make sets $(MAKE)... (cached) yes checking for aarch64-linux-android-gcc... no checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... yes checking for suffix of object files... o checking whether the compiler supports GNU C... yes checking whether gcc accepts -g... yes checking for gcc option to enable C11 features... none needed checking whether gcc understands -c and -o together... yes checking whether the compiler is clang... no checking for compiler option needed when checking for declarations... none checking whether make supports the include directive... yes (GNU style) checking dependency style of gcc... none checking how to run the C preprocessor... gcc -E checking for strip... /usr/bin/strip checking for aarch64-linux-android-strip... /usr/bin/strip checking build system type... x86_64-pc-linux-gnu checking host system type... aarch64-unknown-linux-android checking for stdio.h... yes checking for stdlib.h... yes checking for string.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for strings.h... yes checking for sys/stat.h... yes checking for sys/types.h... yes checking for unistd.h... yes checking for wchar.h... yes checking for minix/config.h... no checking for sys/param.h... yes checking for sys/socket.h... yes checking for limits.h... yes checking for sys/time.h... yes checking for features.h... yes checking for crtdefs.h... no checking whether it is safe to define __EXTENSIONS__... yes checking whether _XOPEN_SOURCE should be defined... no checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for Minix Amsterdam compiler... no checking for aarch64-linux-android-ar... no checking for ar... ar checking for aarch64-linux-android-ranlib... no checking for ranlib... ranlib checking for special C compiler options needed for large files... no checking for _FILE_OFFSET_BITS value needed for large files... no checking how to print strings... printf checking for a sed that does not truncate output... /usr/bin/sed checking for fgrep... /usr/bin/grep -F checking for ld used by gcc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... no checking for aarch64-linux-android-dumpbin... no checking for aarch64-linux-android-link... no checking for dumpbin... no checking for link... link -dump checking the name lister (nm) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 3145728 checking how to convert x86_64-pc-linux-gnu file names to aarch64-unknown-linux-android format... func_convert_file_noop checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop checking for /usr/bin/ld option to reload object files... -r checking for aarch64-linux-android-file... no checking for file... file checking for aarch64-linux-android-objdump... no checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for aarch64-linux-android-dlltool... no checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for aarch64-linux-android-ar... ar checking for archiver @FILE support... @ checking for aarch64-linux-android-strip... (cached) /usr/bin/strip checking for aarch64-linux-android-ranlib... ranlib checking command to parse nm output from gcc object... ok checking for sysroot... no checking for a working dd... /usr/bin/dd checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1 checking for aarch64-linux-android-mt... no checking for mt... mt checking if mt is a manifest tool... no checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC -DPIC checking if gcc PIC flag -fPIC -DPIC works... yes checking if gcc static flag -static works... yes checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes checking dynamic linker characteristics... Android linker checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... no checking whether to build static libraries... yes checking for ld... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for shared library path variable... LD_LIBRARY_PATH checking whether to activate relocatable installation... no checking how to copy files... cp -p checking how to make hard links... ln checking whether ln -s works... yes checking for aarch64-linux-android-windres... no checking for windres... no checking whether the -Werror option is usable... yes checking for simple visibility declarations... yes checking for shared library run path origin... done checking 32-bit host C ABI... yes checking for ELF binary format... yes checking for the common suffixes of directories in the library search path... lib,lib32,lib checking for iconv... yes checking for working iconv... guessing yes checking whether iconv is compatible with its POSIX signature... yes checking whether NLS is requested... yes checking for msgfmt... no checking for gmsgfmt... : checking for xgettext... no checking for msgmerge... no checking for CFPreferencesCopyAppValue... no checking for CFLocaleCopyPreferredLanguages... no checking for GNU gettext in libc... yes checking whether to use NLS... yes checking where the gettext function comes from... libc checking for mbstate_t... yes checking for wchar_t... yes checking for getc_unlocked... yes checking for mbrtowc... yes checking for wcrtomb... yes checking for mbsinit... yes checking for setlocale... yes checking whether