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

[AutotoolsToolchain] Added [CC|CXX]_FOR_BUILD env var #16391

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions conan/test/utils/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(".")
Expand Down
27 changes: 20 additions & 7 deletions conan/tools/gnu/autotoolstoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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 []

Expand Down Expand Up @@ -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]
Expand All @@ -172,6 +175,16 @@ 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"])
if "cpp" in compilers_build_mapping:
env.define("CXX_FOR_BUILD", compilers_build_mapping["cpp"])
return env

def vars(self):
Expand Down
3 changes: 3 additions & 0 deletions test/integration/toolchains/gnu/test_autotoolstoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ 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
assert 'export CXX_FOR_BUILD="clang++"' in content
""")
client = TestClient()
client.save({
Expand Down