From 2b71d67bbac6656a024765ecca22333e548faa0e Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Mon, 3 Jun 2024 15:35:22 +0200 Subject: [PATCH 1/3] Added CC_FOR_BUILD env var --- .gitignore | 1 + conan/tools/gnu/autotoolstoolchain.py | 25 +++++++++++++------ .../toolchains/gnu/test_autotoolstoolchain.py | 2 ++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index cd3afe32d84..87824d1019e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ venv/ *.egg-info/ .installed.cfg *.egg +pip-wheel-metadata/ # PyInstaller # Usually these files are written by a python script from a template diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py index 6f961e4429b..d970a5f8438 100644 --- a/conan/tools/gnu/autotoolstoolchain.py +++ b/conan/tools/gnu/autotoolstoolchain.py @@ -60,8 +60,8 @@ def __init__(self, conanfile, namespace=None, prefix="/"): self._build = self._conanfile.conf.get("tools.gnu:build_triplet") self._target = None - is_cross_building = cross_building(self._conanfile) - if is_cross_building: + self._is_cross_building = cross_building(self._conanfile) + if self._is_cross_building: os_host = conanfile.settings.get_safe("os") arch_host = conanfile.settings.get_safe("arch") os_build = conanfile.settings_build.get_safe('os') @@ -84,11 +84,12 @@ def __init__(self, conanfile, namespace=None, prefix="/"): self.autoreconf_args = self._default_autoreconf_flags() self.make_args = [] # Apple stuff - is_cross_building_osx = (is_cross_building + is_cross_building_osx = (self._is_cross_building and conanfile.settings_build.get_safe('os') == "Macos" and is_apple_os(conanfile)) - min_flag, arch_flag, isysroot_flag = resolve_apple_flags(conanfile, - is_cross_building=is_cross_building_osx) + min_flag, arch_flag, isysroot_flag = ( + resolve_apple_flags(conanfile, is_cross_building=is_cross_building_osx) + ) # https://man.archlinux.org/man/clang.1.en#Target_Selection_Options self.apple_arch_flag = arch_flag # -isysroot makes all includes for your library relative to the build directory @@ -102,7 +103,8 @@ def _get_msvc_runtime_flag(self): return flag def _msvc_extra_flags(self): - if is_msvc(self._conanfile) and check_min_vs(self._conanfile, "180", raise_invalid=False): + if is_msvc(self._conanfile) and check_min_vs(self._conanfile, "180", + raise_invalid=False): return ["-FS"] return [] @@ -160,7 +162,8 @@ def environment(self): compilers_by_conf = self._conanfile.conf.get("tools.build:compiler_executables", default={}, check_type=dict) if compilers_by_conf: - compilers_mapping = {"c": "CC", "cpp": "CXX", "cuda": "NVCC", "fortran": "FC", "rc": "RC"} + compilers_mapping = {"c": "CC", "cpp": "CXX", "cuda": "NVCC", "fortran": "FC", + "rc": "RC"} for comp, env_var in compilers_mapping.items(): if comp in compilers_by_conf: compiler = compilers_by_conf[comp] @@ -172,6 +175,14 @@ def environment(self): env.append("CFLAGS", self.cflags) env.append("LDFLAGS", self.ldflags) env.prepend_path("PKG_CONFIG_PATH", self._conanfile.generators_folder) + # Issue related: https://github.com/conan-io/conan/issues/15486 + if self._is_cross_building and self._conanfile.conf_build: + compilers_build_mapping = ( + self._conanfile.conf_build.get("tools.build:compiler_executables", default={}, + check_type=dict) + ) + if "c" in compilers_build_mapping: + env.define("CC_FOR_BUILD", compilers_build_mapping["c"]) return env def vars(self): diff --git a/test/integration/toolchains/gnu/test_autotoolstoolchain.py b/test/integration/toolchains/gnu/test_autotoolstoolchain.py index c80468a7110..03be41d7f2a 100644 --- a/test/integration/toolchains/gnu/test_autotoolstoolchain.py +++ b/test/integration/toolchains/gnu/test_autotoolstoolchain.py @@ -266,6 +266,8 @@ def build(self): assert 'export CC="gcc"' in content assert 'export CXX="g++"' in content assert 'export RC="windres"' in content + # Issue: https://github.com/conan-io/conan/issues/15486 + assert 'export CC_FOR_BUILD="clang"' in content """) client = TestClient() client.save({ From 45f1ed188575883be191731fc3693ee97c1e053c Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Mon, 3 Jun 2024 15:49:32 +0200 Subject: [PATCH 2/3] Added conf_build to ConanFileMock --- conan/test/utils/mocks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/conan/test/utils/mocks.py b/conan/test/utils/mocks.py index 6c1a160ef76..bfed795b61b 100644 --- a/conan/test/utils/mocks.py +++ b/conan/test/utils/mocks.py @@ -92,6 +92,7 @@ def __init__(self, settings=None, options=None, runner=None, display_name=""): self.options = options or Options() self.generators = [] self.conf = Conf() + self.conf_build = Conf() self.folders = Folders() self.folders.set_base_source(".") self.folders.set_base_export_sources(".") From 4c412bef113f28ceac363662bd1866173c345faa Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Mon, 3 Jun 2024 19:29:12 +0200 Subject: [PATCH 3/3] Added CXX_FOR_BUILD too --- conan/tools/gnu/autotoolstoolchain.py | 2 ++ test/integration/toolchains/gnu/test_autotoolstoolchain.py | 1 + 2 files changed, 3 insertions(+) diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py index d970a5f8438..c0a8655d317 100644 --- a/conan/tools/gnu/autotoolstoolchain.py +++ b/conan/tools/gnu/autotoolstoolchain.py @@ -183,6 +183,8 @@ def environment(self): ) if "c" in compilers_build_mapping: env.define("CC_FOR_BUILD", compilers_build_mapping["c"]) + if "cpp" in compilers_build_mapping: + env.define("CXX_FOR_BUILD", compilers_build_mapping["cpp"]) return env def vars(self): diff --git a/test/integration/toolchains/gnu/test_autotoolstoolchain.py b/test/integration/toolchains/gnu/test_autotoolstoolchain.py index 03be41d7f2a..7364274ae59 100644 --- a/test/integration/toolchains/gnu/test_autotoolstoolchain.py +++ b/test/integration/toolchains/gnu/test_autotoolstoolchain.py @@ -268,6 +268,7 @@ def build(self): assert 'export RC="windres"' in content # Issue: https://github.com/conan-io/conan/issues/15486 assert 'export CC_FOR_BUILD="clang"' in content + assert 'export CXX_FOR_BUILD="clang++"' in content """) client = TestClient() client.save({