conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
949 stars 1.73k forks source link

[package] boost/all: can't build with Linux Cross Compiler with spaces #16051

Open dornbirndevelops opened 1 year ago

dornbirndevelops commented 1 year ago

Description

I have a Yocto SDK installed on my system which I intend to use for a cross compilation. Relevant information (which is usually sourced via environment-setup-script) is propagated to conan via a profiles tool_requires.

I managed to fix it locally by changing a single line in boost/all/conanfile.py:

-            contents += f" \"{cxx_fwd_slahes}\""
+            contents += f" {cxx_fwd_slahes}"

Worries are now that this change could lead to a regression, since it basically undoes https://github.com/conan-io/conan-center-index/pull/15154 (issue was https://github.com/conan-io/conan-center-index/issues/15070).

Package and Environment Details

Conan profile

native

[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.version=11.3
compiler.libcxx=libstdc++11
os=Linux

cross

[settings]
arch=armv8
build_type=Release
compiler=gcc
compiler.version=11.3
compiler.libcxx=libstdc++11
os=Linux

[tool_requires]
yoctoenv/0.1.0@user/channel

Steps to reproduce

yoctoenv/conanfile.py (= updated version of https://github.com/conan-io/conan/issues/5059 + ideas from android-ndk)

from conan import ConanFile, conan_version
from conan.errors import ConanException
from conan.tools.scm import Version
import os, glob, re

class ToolchainPackage(ConanFile):
    name = 'yoctoenv'
    version = '0.1.0'
    upload_policy = 'skip'

    def __parse_sdk_env(self, sdk_path):
        sdk_path = os.path.realpath(sdk_path)

        if not os.path.exists(sdk_path):
            raise ConanException(f'{sdk_path} not present on your system')

        environment_config = {}

        environment_setup_files = glob.glob(os.path.join(sdk_path, 'environment-setup-*')) + glob.glob(os.path.join(sdk_path, 'sysroots', '*', 'environment-setup.d', '*.sh'))
        for environment_setup_file in environment_setup_files:
            with open(environment_setup_file) as f:
                for line in f:
                    match = re.search(r'export ([^=]+)=(.*)', line)
                    if match:
                        key, value = match.groups()
                        environment_config[key] = value.strip('"')

        for key, value in environment_config.items():
            # Remove references to self (e.g. in PATH=...:$PATH)
            value = re.sub(f'\\${key}', '', value)
            # Find all other references and resolve them
            refs = re.findall(r'\$[a-zA-Z0-9_]+', value)
            for ref in refs:
                value = re.sub(f'\\{ref}', environment_config[ref[1:]], value)
            environment_config[key] = value

        return environment_config

    def __expand_info(self, key, value):
        if key.lower() == "path":
            paths = [x for x in value.split(":") if x]
            for path in paths:
                self.buildenv_info.append_path(key, path)
        else:
            self.buildenv_info.define(key, value)

        # TODO: conan v1 stuff to remove later
        if Version(conan_version).major < 2:
            if key.lower() == "path":
                # The content of the PATH variable must be set as a list to make
                # Conan append to the existing PATH. Otherwise it will overwrite
                # the environment variable.
                self.env_info.PATH.extend(paths)
            else:
                # All other variables can be handled in the standard way.
                setattr(self.env_info, key, value)

    def package_info(self):
        self.cpp_info.includedirs = []
        self.cpp_info.libdirs = []

        # TODO: parametrize sdk_install_path (preferably via profile)
        sdk_install_path = '/opt/poky'
        environment_config = self.__parse_sdk_env(sdk_install_path)

        for key, value in environment_config.items():
            self.__expand_info(key, value)

        # Unset command_not_found_handle to fix problems on Ubuntu due to
        # toolchains overriding PYTHONHOME
        self.__expand_info('command_not_found_handle', None)
  1. download a (official) yocto sdk installer
  2. install the sdk
    chmod +x path/to/sdk.sh && path/to/sdk.sh -y -d /opt/poky
  3. apply fixes for oe cmake toolchain
    sed -i '/ONLY/s/^/#/g' /opt/poky/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
  4. export yoctoenv recipe
    conan export yoctoenv user/channel
  5. try to build boost
    conan create conan-center-index/recipes/boost/all boost/1.79.0@ -b missing -b boost -pr:b native -pr:h cross

Logs

original recipe ``` warning: toolset gcc initialization: warning: can not find user-provided command 'aarch64-poky-linux-g++ -mcpu=cortex-a57 -march=armv8-a+crc -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/poky/sysroots/cortexa57-poky-linux' warning: initialized from /workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build/user-config.jam:5 /workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/tools/common.jam:1104: in common.find-compiler from module common error: toolset gcc initialization: error: provided command '"aarch64-poky-linux-g++ -mcpu=cortex-a57 -march=armv8-a+crc -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/poky/sysroots/cortexa57-poky-linux"' not found error: initialized from /workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build/user-config.jam:5 ```
modified recipe ``` notice: will use 'aarch64-poky-linux-g++' '-mcpu=cortex-a57' '-march=armv8-a+crc' '-fstack-protector-strong' '-O2' '-D_FORTIFY_SOURCE=2' '-Wformat' '-Wformat-security' '-Werror=format-security' '--sysroot=/opt/poky/sysroots/cortexa57-poky-linux' for gcc, condition gcc-11 notice: using gcc libraries :: gcc-11 :: --sysroot=/opt/poky/bin --sysroot=/opt/poky/lib --sysroot=/opt/poky/lib32 --sysroot=/opt/poky/lib64 notice: using gcc archiver :: gcc-11 :: aarch64-poky-linux-ar warning: toolset gcc initialization: can not find tool windres warning: initialized from /workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build/user-config.jam:5 ```

full error log ``` Exporting package recipe boost/1.79.0 exports: File 'conandata.yml' found. Exporting it... boost/1.79.0 exports: Copied 1 '.yml' file: conandata.yml boost/1.79.0: Calling export() boost/1.79.0: Copied 1 '.yml' file: dependencies-1.79.0.yml boost/1.79.0: Calling export_sources() boost/1.79.0: The stored package has not changed boost/1.79.0: Exported revision: 7e3ccedb3882273b9467973efff282d6 Configuration (profile_host): [settings] arch=armv8 build_type=Release compiler=gcc compiler.libcxx=libstdc++11 compiler.version=11.3 os=Linux [options] [build_requires] *: yoctoenv/0.1.0@user/channel [env] Configuration (profile_build): [settings] arch=x86_64 build_type=Release compiler=gcc compiler.libcxx=libstdc++11 compiler.version=11.3 os=Linux [options] [build_requires] [env] boost/1.79.0: Forced build from source boost/1.79.0 (test package): Installing package Requirements boost/1.79.0 from local cache - Cache bzip2/1.0.8 from 'conancenter' - Cache libbacktrace/cci.20210118 from 'conancenter' - Cache zlib/1.2.13 from 'conancenter' - Cache Packages boost/1.79.0:c4b374b9a424b32e9a3de4b28850101d319f40eb - Build bzip2/1.0.8:578ee81484b9a78d79603e4317b520749ee97294 - Cache libbacktrace/cci.20210118:f7bf7f2b9d3c831882a24374763de8125c6889b3 - Cache zlib/1.2.13:f7bf7f2b9d3c831882a24374763de8125c6889b3 - Cache Build requirements b2/4.9.3 from 'conancenter' - Cache yoctoenv/0.1.0@user/channel from local cache - Cache Build requirements packages b2/4.9.3:4db1be536558d833e52e862fd84d64d75c2b3656 - Cache yoctoenv/0.1.0@user/channel:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache Cross-build from 'Linux:x86_64' to 'Linux:armv8' Installing (downloading, building) binaries... b2/4.9.3: Already installed! bzip2/1.0.8: Already installed! libbacktrace/cci.20210118: Already installed! yoctoenv/0.1.0@user/channel: Already installed! zlib/1.2.13: Already installed! boost/1.79.0: Applying build-requirement: yoctoenv/0.1.0@user/channel boost/1.79.0: Applying build-requirement: b2/4.9.3 boost/1.79.0: WARN: Build folder is dirty, removing it: /workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/build/c4b374b9a424b32e9a3de4b28850101d319f40eb boost/1.79.0: Building your package in /workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/build/c4b374b9a424b32e9a3de4b28850101d319f40eb boost/1.79.0: Generator txt created conanbuildinfo.txt boost/1.79.0: Calling generate() boost/1.79.0: Aggregating env generators boost/1.79.0: Calling build() boost/1.79.0: WARN: replace_in_file didn't find pattern '$(>) > $(<)' in '/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/libs/stacktrace/build/Jamfile.v2' file. boost/1.79.0: WARN: replace_in_file didn't find pattern '/* thread_local */' in '/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/boost/stacktrace/detail/libbacktrace_impls.hpp' file. boost/1.79.0: WARN: replace_in_file didn't find pattern '/* static __thread */' in '/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/boost/stacktrace/detail/libbacktrace_impls.hpp' file. boost/1.79.0: WARN: replace_in_file didn't find pattern 'local generic-os = [ set.difference $(all-os) : aix darwin vxworks solaris osf hpux ] ;' in '/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build/src/tools/gcc.jam' file. boost/1.79.0: WARN: replace_in_file didn't find pattern 'local no-threading = android beos haiku sgi darwin vxworks ;' in '/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build/src/tools/gcc.jam' file. boost/1.79.0: WARN: replace_in_file didn't find pattern ' @numa' in '/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/libs/fiber/build/Jamfile.v2' file. boost/1.79.0: WARN: Patching user-config.jam boost/1.79.0: WARN: using zlib : 1.2.13 : "/workspaces/yocto-sandbox/.conan/data/zlib/1.2.13/_/_/package/f7bf7f2b9d3c831882a24374763de8125c6889b3/include" "/workspaces/yocto-sandbox/.conan/data/zlib/1.2.13/_/_/package/f7bf7f2b9d3c831882a24374763de8125c6889b3/lib" z ; using bzip2 : 1.0.8 : "/workspaces/yocto-sandbox/.conan/data/bzip2/1.0.8/_/_/package/578ee81484b9a78d79603e4317b520749ee97294/include" "/workspaces/yocto-sandbox/.conan/data/bzip2/1.0.8/_/_/package/578ee81484b9a78d79603e4317b520749ee97294/lib" bz2 ; using "gcc" : : "aarch64-poky-linux-g++ -mcpu=cortex-a57 -march=armv8-a+crc -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/poky/sysroots/cortexa57-poky-linux" : "aarch64-poky-linux-ar" "aarch64-poky-linux-ranlib" "-I/workspaces/yocto-sandbox/.conan/data/libbacktrace/cci.20210118/_/_/package/f7bf7f2b9d3c831882a24374763de8125c6889b3/include" "-L/workspaces/yocto-sandbox/.conan/data/libbacktrace/cci.20210118/_/_/package/f7bf7f2b9d3c831882a24374763de8125c6889b3/lib" ; boost/1.79.0: Cross building, detecting compiler... boost/1.79.0: Cross building flags: [] boost/1.79.0: WARN: b2 -q numa=on target-os=linux architecture=arm address-model=64 binary-format=elf abi=aapcs --layout=system --user-config=/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build/user-config.jam -sNO_ZLIB=0 -sNO_BZIP2=0 -sNO_LZMA=1 -sNO_ZSTD=1 boost.locale.icu=off --disable-icu boost.locale.iconv=on boost.locale.iconv.lib=libc threading=multi visibility=hidden link=static variant=release --with-atomic --with-chrono --with-container --with-context --with-contract --with-coroutine --with-date_time --with-exception --with-fiber --with-filesystem --with-graph --with-iostreams --with-json --with-locale --with-log --with-math --with-nowide --with-program_options --with-random --with-regex --with-serialization --with-stacktrace --with-system --with-test --with-thread --with-timer --with-type_erasure --with-wave toolset=gcc define=_GLIBCXX_USE_CXX11_ABI=1 pch=on -sLIBBACKTRACE_PATH=/workspaces/yocto-sandbox/.conan/data/libbacktrace/cci.20210118/_/_/package/f7bf7f2b9d3c831882a24374763de8125c6889b3 linkflags="" cxxflags="-fPIC -DBOOST_STACKTRACE_ADDR2LINE_LOCATION=/usr/bin/addr2line" install --prefix=/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/package/c4b374b9a424b32e9a3de4b28850101d319f40eb -j12 --abbreviate-paths -d0 --debug-configuration --build-dir="/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/build/c4b374b9a424b32e9a3de4b28850101d319f40eb/build-release" notice: found boost-build.jam at /workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/boost-build.jam notice: loading B2 from /workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/kernel/bootstrap.jam notice: Searching '/etc' '/home/user' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/kernel' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/util' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/build' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/tools' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/contrib' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/.' for site-config configuration file 'site-config.jam'. notice: Configuration file 'site-config.jam' not found in '/etc' '/home/user' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/kernel' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/util' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/build' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/tools' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/contrib' '/workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/.'. notice: Loading explicitly specified user configuration file: /workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build/user-config.jam notice: Searching '/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build' for user-config configuration file 'user-config.jam'. notice: Loading user-config configuration file 'user-config.jam' from '/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build'. notice: [zlib] Using pre-installed library notice: [zlib] Condition notice: [bzip2] Using pre-installed library notice: [bzip2] Condition warning: toolset gcc initialization: warning: can not find user-provided command 'aarch64-poky-linux-g++ -mcpu=cortex-a57 -march=armv8-a+crc -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/poky/sysroots/cortexa57-poky-linux' warning: initialized from /workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build/user-config.jam:5 /workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/tools/common.jam:1104: in common.find-compiler from module common error: toolset gcc initialization: error: provided command '"aarch64-poky-linux-g++ -mcpu=cortex-a57 -march=armv8-a+crc -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/poky/sysroots/cortexa57-poky-linux"' not found error: initialized from /workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build/user-config.jam:5 /workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/tools/gcc.jam:165: in gcc.init from module gcc /workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/build/toolset.jam:44: in toolset.using from module toolset /workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/build/project.jam:1104: in using from module project-rules /workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build/user-config.jam:5: in modules.load from module user-config /workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/build-system.jam:255: in load-config from module build-system /workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/build-system.jam:449: in load-configuration-files from module build-system /workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/build-system.jam:607: in load from module build-system /workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/kernel/modules.jam:294: in import from module modules /workspaces/yocto-sandbox/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/kernel/bootstrap.jam:135: in module scope from module boost/1.79.0: boost/1.79.0: ERROR: Package 'c4b374b9a424b32e9a3de4b28850101d319f40eb' build failed boost/1.79.0: WARN: Build folder /workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/build/c4b374b9a424b32e9a3de4b28850101d319f40eb/build-release ERROR: boost/1.79.0: Error in build() method, line 880 self.run(full_command) ConanException: Error 1 while executing b2 -q numa=on target-os=linux architecture=arm address-model=64 binary-format=elf abi=aapcs --layout=system --user-config=/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/source/src/tools/build/user-config.jam -sNO_ZLIB=0 -sNO_BZIP2=0 -sNO_LZMA=1 -sNO_ZSTD=1 boost.locale.icu=off --disable-icu boost.locale.iconv=on boost.locale.iconv.lib=libc threading=multi visibility=hidden link=static variant=release --with-atomic --with-chrono --with-container --with-context --with-contract --with-coroutine --with-date_time --with-exception --with-fiber --with-filesystem --with-graph --with-iostreams --with-json --with-locale --with-log --with-math --with-nowide --with-program_options --with-random --with-regex --with-serialization --with-stacktrace --with-system --with-test --with-thread --with-timer --with-type_erasure --with-wave toolset=gcc define=_GLIBCXX_USE_CXX11_ABI=1 pch=on -sLIBBACKTRACE_PATH=/workspaces/yocto-sandbox/.conan/data/libbacktrace/cci.20210118/_/_/package/f7bf7f2b9d3c831882a24374763de8125c6889b3 linkflags="" cxxflags="-fPIC -DBOOST_STACKTRACE_ADDR2LINE_LOCATION=/usr/bin/addr2line" install --prefix=/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/package/c4b374b9a424b32e9a3de4b28850101d319f40eb -j12 --abbreviate-paths -d0 --debug-configuration --build-dir="/workspaces/yocto-sandbox/.conan/data/boost/1.79.0/_/_/build/c4b374b9a424b32e9a3de4b28850101d319f40eb/build-release" ```
dornbirndevelops commented 1 year ago

the failing LOC I was looking at was introduced

due to this issue: https://github.com/conan-io/conan-center-index/issues/15070 in this PR: https://github.com/conan-io/conan-center-index/pull/15154

does someone else have the same issue? what would be a good solution that does not necessarily break the issue above (👀 @SpaceIm)?

SpaceIm commented 1 year ago

It's not how you should translate yocto env vars to conan profile. CC & CXX are only for compiler path. Pass:

And prefer tools.build:compiler_executables to CC/CXX (both can be used).

So something like this:

[settings]
os=Linux
arch=armv8
compiler=gcc
compiler.version=11
compiler.libcxx=libstdc++11
build_type=Release
# for conan v2 recipes
[conf]
tools.build:compiler_executables={"c": "aarch64-poky-linux-gcc", "cpp": "aarch64-poky-linux-g++"}
tools.build:cflags+=["-mcpu=cortex-a53", "-march=armv8-a+crc+crypto", "-fstack-protector-strong", "-O2", "-Wformat", "-Wformat-security", "-Werror=format-security"]
tools.build:cxxflags+=["-mcpu=cortex-a53", "-march=armv8-a+crc+crypto", "-fstack-protector-strong", "-O2", "-Wformat", "-Wformat-security", "-Werror=format-security"]
tools.build:defines+=["_FORTIFY_SOURCE=2"]
tools.build:sysroot="/usr/local/poky-x86_64/sysroots/cortexa53-crypto-poky-linux"
# for conan v2 recipes also, shouldn't be necessary when recipe is properly written to listen [conf]
[buildenv]
CC=aarch64-poky-linux-gcc
CXX=aarch64-poky-linux-g++
CFLAGS="-mcpu=cortex-a53 -march=armv8-a+crc+crypto -fstack-protector-strong -O2 -Wformat -Wformat-security Werror=format-security"
CXXFLAGS="-mcpu=cortex-a53 -march=armv8-a+crc+crypto -fstack-protector-strong -O2 -Wformat -Wformat-security Werror=format-security"
CPPFLAGS="-D_FORTIFY_SOURCE=2"
SYSROOT="/usr/local/poky-x86_64/sysroots/cortexa53-crypto-poky-linux"

# legacy stuff conan v1 recipes
[env]
CC=aarch64-poky-linux-gcc
CXX=aarch64-poky-linux-g++
CFLAGS="-mcpu=cortex-a53 -march=armv8-a+crc+crypto -fstack-protector-strong -O2 -Wformat -Wformat-security Werror=format-security"
CXXFLAGS="-mcpu=cortex-a53 -march=armv8-a+crc+crypto -fstack-protector-strong -O2 -Wformat -Wformat-security Werror=format-security"
CPPFLAGS="-D_FORTIFY_SOURCE=2"
SYSROOT="/usr/local/poky-x86_64/sysroots/cortexa53-crypto-poky-linux"
dornbirndevelops commented 1 year ago

thank you for the quick and detailed response. i will try out your solution and close the issue once it works.

dornbirndevelops commented 1 year ago

CC & CXX are only for compiler path.

not a feasible solution, since the CC/CXX variable can also be more than just the compiler path. Options that are required to make the compiler work correctly can be included

are there other options/opinions to solve this?

SpaceIm commented 1 year ago

You mean that CMake fails while testing your C/C++ compiler or what? Does it really matter if options are isolated in CFLAGS & CXXFLAGS?

dornbirndevelops commented 1 year ago

You mean that CMake fails while testing your C/C++ compiler or what? Does it really matter if options are isolated in CFLAGS & CXXFLAGS?

I mean that pretty much every Yocto SDK does not specify anything wrong in particular. Generally setting compiler flags in the CC/CXX variable is allowed and hence should work also for boost, which it does with such a change: boost/all/conanfile.py:

-            contents += f" \"{cxx_fwd_slahes}\""
+            contents += f" {cxx_fwd_slahes}"

The reason why I want to discuss this first is because the change above might undo the fix for someone else. 😢

dornbirndevelops commented 1 year ago

FTR: I updated the main description above for easier reproducability.

upsilona commented 1 year ago

I'm facing the same issue, sounds like we are more and more using the Yocto SDK with Conan!

I can confirm your fix is needed for Yocto SDK use case

jwillikers commented 1 year ago

@SpaceIm The Conan profile example you provided doesn't actually work because the Boost recipe doesn't consider the tools.build.sysroot option. I've submitted #17315 to address this, which allows cross-compiling the Boost recipe again.

dornbirndevelops commented 1 year ago

hello @jwillikers, I tested your fix to determine whether or not it would also solve this issue. unfortunately it didn't work out.

warning: toolset gcc initialization:
warning: can not find user-provided command 'aarch64-poky-linux-g++ --sysroot=/usr/local/pokysdk-x86_64/sysroots/cortexa53-crypto-poky-linux'
warning: initialized from /workspaces/product-build-test/.conan/data/boost/1.81.0/_/_/source/src/tools/build/user-config.jam:5
/workspaces/product-build-test/.conan/data/b2/4.9.6/_/_/package/166d2a90346126aadca4204c1d127c5ff2a48bff/bin/.b2/tools/common.jam:1104: in common.find-compiler from module common
error: toolset gcc initialization:
error: provided command '"aarch64-poky-linux-g++ --sysroot=/usr/local/pokysdk-x86_64/sysroots/cortexa53-crypto-poky-linux"' not found
error: initialized from /workspaces/product-build-test/.conan/data/boost/1.81.0/_/_/source/src/tools/build/user-config.jam:5

the main difference I can see between the previous issue and this one is that the spaces were in a different place: e.g. /path/with spaces/to/clang vs. gcc --sysroot=/path/to/sysroot

jwillikers commented 1 year ago

hello @jwillikers, I tested your fix to determine whether or not it would also solve this issue. unfortunately it didn't work out.

warning: toolset gcc initialization:
warning: can not find user-provided command 'aarch64-poky-linux-g++ --sysroot=/usr/local/pokysdk-x86_64/sysroots/cortexa53-crypto-poky-linux'
warning: initialized from /workspaces/product-build-test/.conan/data/boost/1.81.0/_/_/source/src/tools/build/user-config.jam:5
/workspaces/product-build-test/.conan/data/b2/4.9.6/_/_/package/166d2a90346126aadca4204c1d127c5ff2a48bff/bin/.b2/tools/common.jam:1104: in common.find-compiler from module common
error: toolset gcc initialization:
error: provided command '"aarch64-poky-linux-g++ --sysroot=/usr/local/pokysdk-x86_64/sysroots/cortexa53-crypto-poky-linux"' not found
error: initialized from /workspaces/product-build-test/.conan/data/boost/1.81.0/_/_/source/src/tools/build/user-config.jam:5

the main difference I can see between the previous issue and this one is that the spaces were in a different place: e.g. /path/with spaces/to/clang vs. gcc --sysroot=/path/to/sysroot

@dornbirndevelops I've cross-compiled successfully with Yocto, but in order to do so you'll want to tweak your profile. You can leave CC, CXX, CPP and LD as they are. Add a tools.build.compiler_executables conf value like so:

[conf]
tools.build:compiler_executables={'asm': 'aarch64-poky-linux-as', 'c': 'aarch64-poky-linux-gcc', 'cpp': 'aarch64-poky-linux-g++'}

I also prepend the bin directory containing the cross-compilers to PATH in the buildenv section so that Boost can find them. My profile is heavily templated, but here's that snippet.

[buildenv]
PATH=+(path){{ os.path.join(sdk_build_sysroot, "sysroots", build_compiler_prefix, "usr", "bin", cross_compiler_prefix) }}

Here's my complete profile as a reference.

{% set cmake_toolchain_file = os.path.realpath(os.path.join(profile_dir, "..", "..", "toolchains", "yocto-toolchain.cmake")) %}
{% set yocto_sdk_directory = os.path.join("/", "usr", "local", "yocto-poky-sdk") %}
{% set sdk_target_sysroot = os.path.join(yocto_sdk_directory, "sysroots", "cortexa72-crypto-poky-linux") %}
{% set build_compiler_prefix = "x86_64-poky-linux" %}
{% set sdk_build_sysroot = os.path.join(yocto_sdk_directory, "sysroots", build_compiler_prefix) %}
{% set cross_compiler_prefix = "aarch64-poky-linux" %}
{% set architecture_compiler_flags = ["-march=armv8-a+crc+crypto", "-mtune=cortex-a72"] %}
{% set sysroot_compiler_flag = "--sysroot=" + sdk_target_sysroot %}
{% set compiler_flags = " ".join(architecture_compiler_flags) + " " + sysroot_compiler_flag %}

[settings]
os=Linux
arch=armv8
arch.extensions=crc+crypto
arch.processor=cortex-a72
compiler=gcc
compiler.version=11
compiler.libcxx=libstdc++11
compiler.cppstd=20

[env]
PATH=['{{ os.path.join(sdk_build_sysroot, "sysroots", build_compiler_prefix, "usr", "bin", cross_compiler_prefix) }}']
CONAN_CMAKE_TOOLCHAIN_FILE=["{{ cmake_toolchain_file }}"]

CC={{ cross_compiler_prefix }}-gcc {{ compiler_flags }}
CXX={{ cross_compiler_prefix }}-g++ {{ compiler_flags }}
CPP={{ cross_compiler_prefix }}-gcc -E {{ compiler_flags }}
AS={{ cross_compiler_prefix }}-as
LD={{ cross_compiler_prefix }}-ld {{ compiler_flags }}
GDB={{ cross_compiler_prefix }}-gdb
STRIP={{ cross_compiler_prefix }}-strip
RANLIB={{ cross_compiler_prefix }}-ranlib
OBJCOPY={{ cross_compiler_prefix }}-objcopy
OBJDUMP={{ cross_compiler_prefix }}-objdump
AR={{ cross_compiler_prefix }}-ar
NM={{ cross_compiler_prefix }}-nm
M4=m4
TARGET_PREFIX={{ cross_compiler_prefix }}-
ARCH=arm64
CONFIGURE_FLAGS=--target={{ cross_compiler_prefix }} --host={{ cross_compiler_prefix }} --build=x86_64-linux --with-libtool-sysroot={{ sdk_target_sysroot }}
OE_CMAKE_TOOLCHAIN_FILE={{ os.path.join(yocto_sdk_directory, "sysroots", build_compiler_prefix, "usr", "share", "cmake", "OEToolchainConfig.cmake") }}
OE_CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX="`echo lib | sed -e s/lib//`"
PKG_CONFIG_SYSROOT_MAP={{ sdk_target_sysroot }}
PKG_CONFIG_PATH={{ os.path.join(sdk_target_sysroot, "usr", "lib", "pkgconfig") }}:{{ os.path.join(sdk_target_sysroot, "usr", "share", "pkgconfig") }}
CONFIG_SITE={{ os.path.join(yocto_sdk_directory, "site-config-cortexa72-crypto-poky-linux") }}
OECORE_TARGET_ARCH="aarch64"
OECORE_TARGET_OS="linux"

[buildenv]
PATH=+(path){{ os.path.join(sdk_build_sysroot, "sysroots", build_compiler_prefix, "usr", "bin", cross_compiler_prefix) }}

CC={{ cross_compiler_prefix }}-gcc {{ compiler_flags }}
CXX={{ cross_compiler_prefix }}-g++ {{ compiler_flags }}
CPP={{ cross_compiler_prefix }}-gcc -E {{ compiler_flags }}
AS={{ cross_compiler_prefix }}-as
LD={{ cross_compiler_prefix }}-ld {{ compiler_flags }}
GDB={{ cross_compiler_prefix }}-gdb
STRIP={{ cross_compiler_prefix }}-strip
RANLIB={{ cross_compiler_prefix }}-ranlib
OBJCOPY={{ cross_compiler_prefix }}-objcopy
OBJDUMP={{ cross_compiler_prefix }}-objdump
AR={{ cross_compiler_prefix }}-ar
NM={{ cross_compiler_prefix }}-nm
M4=m4
TARGET_PREFIX={{ cross_compiler_prefix }}-
ARCH=arm64
CONFIGURE_FLAGS=--target={{ cross_compiler_prefix }} --host={{ cross_compiler_prefix }} --build=x86_64-linux --with-libtool-sysroot={{ sdk_target_sysroot }}
OE_CMAKE_TOOLCHAIN_FILE={{ os.path.join(yocto_sdk_directory, "sysroots", build_compiler_prefix, "usr", "share", "cmake", "OEToolchainConfig.cmake") }}
OE_CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX=`echo lib | sed -e s/lib//`
PKG_CONFIG_SYSROOT_MAP={{ sdk_target_sysroot }}
PKG_CONFIG_PATH={{ os.path.join(sdk_target_sysroot, "usr", "lib", "pkgconfig") }}:{{ os.path.join(sdk_target_sysroot, "usr", "share", "pkgconfig") }}
CONFIG_SITE={{ os.path.join(yocto_sdk_directory, "site-config-cortexa72-crypto-poky-linux") }}
OECORE_TARGET_ARCH=aarch64
OECORE_TARGET_OS=linux

[conf]
tools.build:compiler_executables={"asm": "{{ cross_compiler_prefix }}-as", "c": "{{ cross_compiler_prefix }}-gcc", "cpp": "{{ cross_compiler_prefix }}-g++"}
tools.build:cflags={{ architecture_compiler_flags }}
tools.build:cxxflags={{ architecture_compiler_flags }}
tools.build:exelinkflags={{ architecture_compiler_flags }}
tools.build:sharedlinkflags={{ architecture_compiler_flags }}
tools.build:sysroot={{ sdk_target_sysroot }}
tools.cmake.cmaketoolchain:system_processor=aarch64
tools.cmake.cmaketoolchain:user_toolchain=["{{ cmake_toolchain_file }}"]
jasal82 commented 10 months ago

Same issue here. A fix would be appreciated.