Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] GnuToolchain can not be generated when cross-building #17601

Open
uilianries opened this issue Jan 20, 2025 · 2 comments
Open

[bug] GnuToolchain can not be generated when cross-building #17601

uilianries opened this issue Jan 20, 2025 · 2 comments
Assignees
Labels
Milestone

Comments

@uilianries
Copy link
Member

uilianries commented Jan 20, 2025

DISCLAIMER: GnuToolchain is not documented yet and is considered under incubating state.

Describe the bug

Description

When trying to consume a Conan package using the GnuToolchain and the host profile is cross-building, the Conan client breaks with:

ERROR: Error in generator 'GnuToolchain': 'ConanFile' object has no attribute 'conf_build'

Environment

Conan version: 2.11.0
OS: GNU Linux 6.8.0
Linux Distro: Linux Mint 21.3 Virginia
Python: 3.12

Steps to reproduce

  1. Prepare a cross-build environment

In my case, I downloaded directly from ARM page: https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads. But it's not really needed, in case using a minimal Linux distribution, you still can use the system package manager to install a cross-toolchain

  1. Adapt your profile to use your toolchain

I created a separate Conan profile to build, but you can see it in the log below.

  1. Try to install zlib/1.3.1 using this new profile and with GnuToolchain. It also works for any other package.

    conan install -r conancenter --requires=zlib/1.3.1 -pr armv8 -g GnuToolchain

Issues logs

This log represents my environment, including the profile used and target package.

$ conan install --requires=zlib/1.3.1 -pr armv8 -of conan -g GnuToolchain

======== Input profiles ========
Profile host:
[settings]
arch=armv8
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux
[conf]
tools.build:compiler_executables={'c': '/opt/arm-gnu-toolchain-13/bin/aarch64-none-linux-gnu-gcc', 'cpp': '/opt/arm-gnu-toolchain-13/bin/aarch64-none-linux-gnu-g++', 'ar': '/opt/arm-gnu-toolchain-13/bin/aarch64-none-linux-gnu-ar', 'ld': '/opt/arm-gnu-toolchain-13/bin/aarch64-none-linux-gnu-ld', 'fortran': '/opt/arm-gnu-toolchain-13/bin/aarch64-none-linux-gnu-fortran'}
tools.build:verbosity=verbose
tools.cmake.cmaketoolchain:generator=Ninja
tools.compilation:verbosity=verbose
tools.system.package_manager:mode=install
tools.system.package_manager:sudo=true
[buildenv]
STRIP=/opt/arm-gnu-toolchain-13/bin/aarch64-none-linux-gnu-strip

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux
[conf]
tools.build:verbosity=verbose
tools.cmake.cmaketoolchain:generator=Ninja
tools.compilation:verbosity=verbose
tools.system.package_manager:mode=install
tools.system.package_manager:sudo=true


======== Computing dependency graph ========
Graph root
    cli
Requirements
    zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76 - Cache

======== Computing necessary packages ========
Requirements
    zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76:258056170a5add18e564ac86c77027634e725af3#2c689c81c1c8c14f176d40e79d558de7 - Cache

======== Installing packages ========
zlib/1.3.1: Already installed! (1 of 1)
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'cpp_info.names' used in: zlib/1.3.1

======== Finalizing install (deploy, generators) ========
cli: Writing generators to /tmp/conan
cli: ERROR: Traceback (most recent call last):
  File "/opt/pyenv/versions/3.12.4/lib/python3.12/site-packages/conan/internal/api/install/generators.py", line 104, in write_generators
    generator = generator_class(conanfile)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/pyenv/versions/3.12.4/lib/python3.12/site-packages/conan/tools/gnu/gnutoolchain.py", line 108, in __init__
    self._initialize_default_extra_env()
  File "/opt/pyenv/versions/3.12.4/lib/python3.12/site-packages/conan/tools/gnu/gnutoolchain.py", line 215, in _initialize_default_extra_env
    extra_env_vars.update(self._resolve_compilers_mapping_variables())
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/pyenv/versions/3.12.4/lib/python3.12/site-packages/conan/tools/gnu/gnutoolchain.py", line 189, in _resolve_compilers_mapping_variables
    if self._is_cross_building and self._conanfile.conf_build:
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ConanFile' object has no attribute 'conf_build'

ERROR: Error in generator 'GnuToolchain': 'ConanFile' object has no attribute 'conf_build'

How to reproduce it

No response

@franramirez688 franramirez688 self-assigned this Jan 20, 2025
@franramirez688 franramirez688 added this to the 2.12.0 milestone Jan 20, 2025
@franramirez688
Copy link
Contributor

Good catch! Thanks @uilianries

Also, this is just a reminder (for myself): #17470
I need to include those changes in the GnuToolchain too.

@valgur
Copy link
Contributor

valgur commented Jan 21, 2025

I have been using GnuToolchain for the better cross-compilation features with the latest Conan client in quite a few recipes without encountering this:
https://github.com/search?q=repo%3Avalgur%2Fconan-center-index+gnutoolchain&type=code

I wonder what you are doing differently. Could it be the command-line generator invocation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants