-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug
The values in self.conf_info
set in the package_info
method of a build-require package do not take effect during the installation of host context dependencies, resulting in (silently) mis-configured packages and/or build failures.
I'm using Conan to package a toolchain as described in https://docs.conan.io/2/examples/cross_build/toolchain_packages.html. The toolchain's package_info
sets tools.build:compiler_executables
and tools.build.cross_building:cross_build
:
def package_info(self):
...
compilers = {
"c": f"{target}-gcc",
"cpp": f"{target}-g++",
"fortran": f"{target}-gfortran",
}
self.conf_info.update("tools.build:compiler_executables", compilers)
self.conf_info.define("tools.build.cross_building:cross_build", True)
Other packages, such as OpenBLAS rely on these values (using conan.tools.build.cross_building
and self.conf.get("tools.build:compiler_executables")
).
However, Conan does not always correctly set these values when building host packages.
This results in build failures, for example, because a conanfile for a host package might see cross_building=False
, even though it was set to true by the toolchain, or in linker errors in OpenBLAS because libgfortran
is not included due to compiler_executables["fortran"]
being empty, even though it was set by the toolchain.
How to reproduce it
Add some print statements to the OpenBLAS recipe (or any other recipe):
diff --git a/recipes/openblas/all/conanfile.py b/recipes/openblas/all/conanfile.py
index 6fcc5d830..432b4f006 100644
--- a/recipes/openblas/all/conanfile.py
+++ b/recipes/openblas/all/conanfile.py
@@ -101,6 +101,8 @@ class OpenblasConan(ConanFile):
@property
def _fortran_compiler(self):
comp_exe = self.conf.get("tools.build:compiler_executables")
+ print("Compiler executables:", comp_exe)
+ print("Cross-building:", cross_building(self))
if comp_exe and "fortran" in comp_exe:
return comp_exe["fortran"]
return None
Use the following profile:
[settings]
arch=x86_64
build_type=Debug
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=14
os=Linux
[tool_requires]
tttapa-toolchains/1.0.2
[options]
openblas/*:target=HASWELL
This uses this toolchain https://github.com/tttapa/conan-recipes/blob/main/recipes/tttapa-toolchains/binary/conanfile.py (but any build-require package that sets self.conf_info
will probably also demonstrate the issue).
Then build OpenBLAS:
conan create conan-center-index/recipes/openblas/all --version 0.3.27 --build=missing -pr test-profile
You'll see from the print statements that the conf_info
is incorrect:
openblas/0.3.27: Calling package()
openblas/0.3.27: Running CMake.install()
openblas/0.3.27: RUN: cmake --install "/home/pieter/.conan2/p/b/openbc9f5b69c5dfef/b/build/Debug" --prefix "/home/pieter/.conan2/p/b/openbc9f5b69c5dfef/p"
-- Install configuration: "Debug"
-- Installing: /home/pieter/.conan2/p/b/openbc9f5b69c5dfef/p/lib/libopenblas.a
[...]
openblas/0.3.27: Package folder /home/pieter/.conan2/p/b/openbc9f5b69c5dfef/p
Compiler executables: {'c': 'x86_64-bionic-linux-gnu-gcc', 'cpp': 'x86_64-bionic-linux-gnu-g++', 'fortran': 'x86_64-bionic-linux-gnu-gfortran'}
Cross-building: True
======== Launching test_package ========
======== Computing dependency graph ========
Graph root
openblas/0.3.27 (test package): /home/pieter/Downloads/conan-center-index/recipes/openblas/all/test_package/conanfile.py
Requirements
openblas/0.3.27#98109524ab5c1dee94d06fc816c83442 - Cache
Build requirements
tttapa-toolchains/1.0.2#73c6482fe9bf9a138c96619f083635bf - Cache
======== Computing necessary packages ========
Requirements
openblas/0.3.27#98109524ab5c1dee94d06fc816c83442:01ceb14e4b3bb26bc1152b145930df01741d996e#8cca61d8c4b7c53c8dcae31f7ddf1f43 - Cache
Build requirements
tttapa-toolchains/1.0.2#73c6482fe9bf9a138c96619f083635bf:fbe2cec9c27dea4585e3cc53888517dabd7ab58f#f9cfa7834c59ef749fdf09621418c7a7 - Cache
======== Installing packages ========
tttapa-toolchains/1.0.2: Already installed! (1 of 2)
openblas/0.3.27: Already installed! (2 of 2)
Compiler executables: None
Cross-building: False
Note how during the installation of the dependencies of the test_package
, there are no compiler executables set, and cross_building
returns false, even though these values were set by the tttapa-toolchains
package!
Inspecting the conan-center-index/recipes/openblas/all/test_package/build/gcc-14-x86_64-gnu17-debug/generators/OpenBLAS-debug-x86_64-data.cmake
file indeed reveals that Conan incorrectly configured the dependencies: the gfortran
library is missing from the openblas_SYSTEM_LIBS_DEBUG
variable, which causes linker errors as described above.
mold: error: undefined symbol: _gfortran_compare_string
>>> referenced by ilaenv.f
>>> /home/runner/work/.conan2/p/b/openbbb6b930d00c7e/p/lib/libopenblas.a(ilaenv.f.o):(ilaenv_)
>>> referenced by ilaenv.f
>>> /home/runner/work/.conan2/p/b/openbbb6b930d00c7e/p/lib/libopenblas.a(ilaenv.f.o):(ilaenv_)
>>> referenced by ilaenv.f
>>> /home/runner/work/.conan2/p/b/openbbb6b930d00c7e/p/lib/libopenblas.a(ilaenv.f.o):(ilaenv_)