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

Raise for toolchains different than CMakeToolchain if using universal binary syntax #15896

Merged
merged 3 commits into from
Mar 19, 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
6 changes: 6 additions & 0 deletions conan/internal/internal_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ def is_universal_arch(settings_value, valid_definitions):
valid_macos_values = [val for val in valid_definitions if ("arm" in val or "x86" in val)]

return all(part in valid_macos_values for part in parts)


def raise_on_universal_arch(conanfile):
if is_universal_arch(conanfile.settings.get_safe("arch"),
conanfile.settings.possible_values().get("arch")):
raise ConanException("Universal binaries not supported by toolchain.")
3 changes: 3 additions & 0 deletions conan/tools/gnu/autotoolstoolchain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from conan.internal import check_duplicated_generator
from conan.internal.internal_tools import raise_on_universal_arch
from conan.tools.apple.apple import apple_min_version_flag, is_apple_os, to_apple_arch, apple_sdk_path
from conan.tools.apple.apple import get_apple_sdk_fullname
from conan.tools.build import cmd_args_to_string, save_toolchain_args
Expand All @@ -24,6 +25,8 @@ def __init__(self, conanfile, namespace=None, prefix="/"):
helper so that it reads the information from the proper file.
:param prefix: Folder to use for ``--prefix`` argument ("/" by default).
"""
raise_on_universal_arch(conanfile)

self._conanfile = conanfile
self._namespace = namespace
self._prefix = prefix
Expand Down
3 changes: 3 additions & 0 deletions conan/tools/google/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from jinja2 import Template

from conan.internal import check_duplicated_generator
from conan.internal.internal_tools import raise_on_universal_arch
from conan.tools.apple import to_apple_arch, is_apple_os
from conan.tools.build.cross_building import cross_building
from conan.tools.build.flags import cppstd_flag
Expand Down Expand Up @@ -63,6 +64,8 @@ def __init__(self, conanfile):
"""
:param conanfile: ``< ConanFile object >`` The current recipe object. Always use ``self``.
"""
raise_on_universal_arch(conanfile)

self._conanfile = conanfile

# Bazel build parameters
Expand Down
2 changes: 2 additions & 0 deletions conan/tools/meson/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from conan.errors import ConanException
from conan.internal import check_duplicated_generator
from conan.internal.internal_tools import raise_on_universal_arch
from conan.tools.apple.apple import to_apple_arch, is_apple_os, apple_min_version_flag, \
apple_sdk_path, get_apple_sdk_fullname
from conan.tools.build.cross_building import cross_building
Expand Down Expand Up @@ -93,6 +94,7 @@ def __init__(self, conanfile, backend=None):
:param conanfile: ``< ConanFile object >`` The current recipe object. Always use ``self``.
:param backend: ``str`` ``backend`` Meson variable value. By default, ``ninja``.
"""
raise_on_universal_arch(conanfile)
self._conanfile = conanfile
self._os = self._conanfile.settings.get_safe("os")
self._is_apple_system = is_apple_os(self._conanfile)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from parameterized import parameterized

from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.tools import TestClient


@parameterized.expand(["AutotoolsToolchain", "MesonToolchain", "BazelToolchain"])
def test_create_universal_binary(toolchain):
client = TestClient()
conanfile = (GenConanfile().with_settings("os", "arch", "compiler", "build_type").with_generator(toolchain))
client.save({"conanfile.py": conanfile})

client.run('create . --name=foo --version=1.0 -s="arch=armv8|armv8.3|x86_64"',
assert_error=True)
assert f"Error in generator '{toolchain}': Universal binaries not supported by toolchain." in client.out
4 changes: 4 additions & 0 deletions conans/test/utils/mocks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import defaultdict
from io import StringIO

from conan import ConanFile
Expand Down Expand Up @@ -62,6 +63,9 @@ def __getattr__(self, name):
def rm_safe(self, name):
self.values.pop(name, None)

def possible_values(self):
return defaultdict(lambda: [])


class MockCppInfo(object):
def __init__(self):
Expand Down