Repository: conan-io/conan
Pull request #15965 (2024-03-27 12:50:04)

feat: add build_triplet on conf
Changelog: Feature: Add `tools.gnu:build_triplet` to conf
Docs: Omit

Close: #14962




Patch:
diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py
index 314409171..41430e73b 100644
--- a/conan/tools/gnu/autotoolstoolchain.py
+++ b/conan/tools/gnu/autotoolstoolchain.py
@@ -56,7 +56,7 @@ class AutotoolsToolchain:
 
         # Cross build triplets
         self._host = self._conanfile.conf.get("tools.gnu:host_triplet")
-        self._build = None
+        self._build = self._conanfile.conf.get("tools.gnu:build_triplet")
         self._target = None
 
         self.apple_arch_flag = self.apple_isysroot_flag = None
@@ -78,7 +78,8 @@ class AutotoolsToolchain:
             if not self._host:
                 self._host = _get_gnu_triplet(os_host, arch_host, compiler=compiler)
             # Build triplet
-            self._build = _get_gnu_triplet(os_build, arch_build, compiler=compiler)
+            if not self._build:
+                self._build = _get_gnu_triplet(os_build, arch_build, compiler=compiler)
             # Apple Stuff
             if os_build == "Macos" and is_apple_os(conanfile):
                 # SDK path is mandatory for cross-building
diff --git a/conans/model/conf.py b/conans/model/conf.py
index d35ec8fa7..f74ee2107 100644
--- a/conans/model/conf.py
+++ b/conans/model/conf.py
@@ -86,6 +86,7 @@ BUILT_IN_CONFS = {
     "tools.gnu:make_program": "Indicate path to make program",
     "tools.gnu:define_libcxx11_abi": "Force definition of GLIBCXX_USE_CXX11_ABI=1 for libstdc++11",
     "tools.gnu:pkg_config": "Path to pkg-config executable used by PkgConfig build helper",
+    "tools.gnu:build_triplet": "Custom build triplet to pass to Autotools scripts",
     "tools.gnu:host_triplet": "Custom host triplet to pass to Autotools scripts",
     "tools.google.bazel:configs": "List of Bazel configurations to be used as 'bazel build --config=config1 ...'",
     "tools.google.bazel:bazelrc_path": "List of paths to bazelrc files to be used as 'bazel --bazelrc=rcpath1 ... build'",


Test patch:
diff --git a/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py b/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py
index 47650ab9a..d8fa16cf9 100644
--- a/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py
+++ b/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py
@@ -57,6 +57,7 @@ def test_invalid_target_triple():
     assert "Unknown 'UNKNOWN_ARCH' machine, Conan doesn't know how " \
            "to translate it to the GNU triplet," in str(excinfo)
 
+
 def test_custom_host_triple():
     conanfile = ConanFileMock()
     conanfile.settings = MockSettings({"os": "Linux", "arch": "x86"})
@@ -67,6 +68,18 @@ def test_custom_host_triple():
     obj = load_toolchain_args()
     assert "--host=i686-pc-linux-gnu" in obj["configure_args"]
 
+
+def test_custom_build_triple():
+    conanfile = ConanFileMock()
+    conanfile.settings = MockSettings({"os": "Linux", "arch": "x86"})
+    conanfile.settings_build = MockSettings({"os": "Linux", "arch": "x86_64"})
+    conanfile.conf.define("tools.gnu:build_triplet", "i686-pc-linux-gnu")
+    tc = AutotoolsToolchain(conanfile)
+    tc.generate_args()
+    obj = load_toolchain_args()
+    assert "--build=i686-pc-linux-gnu" in obj["configure_args"]
+
+
 def test_cppstd():
     # Using "cppstd" is discarded
     conanfile = ConanFileMock()