Skip to content

Commit

Permalink
- Feature: add Apple Catalyst support (as new os.subsystem)
Browse files Browse the repository at this point in the history
Signed-off-by: SSE4 <tomskside@gmail.com>
  • Loading branch information
SSE4 committed Jan 13, 2021
1 parent ab55773 commit 597e6f7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions conans/client/build/autotools_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self, conanfile, win_bash=False, include_rpath_flags=False):
self._os = conanfile.settings.get_safe("os")
self._os_version = conanfile.settings.get_safe("os.version")
self._os_sdk = conanfile.settings.get_safe("os.sdk")
self._os_subsystem = conanfile.settings.get_safe("os.subsystem")
self._arch = conanfile.settings.get_safe("arch")
self._os_target, self._arch_target = get_target_os_arch(conanfile)

Expand Down Expand Up @@ -356,6 +357,7 @@ def append(*args):
tmp_compilation_flags.append(tools.apple_deployment_target_flag(self._os,
self._os_version,
self._os_sdk,
self._os_subsystem,
self._arch))

cxx_flags = append(tmp_compilation_flags, self.cxx_flags, self.cppstd_flag)
Expand Down
5 changes: 4 additions & 1 deletion conans/client/build/compiler_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ def architecture_flag(settings):
compiler_base = settings.get_safe("compiler.base")
arch = settings.get_safe("arch")
the_os = settings.get_safe("os")
subsystem = settings.get_safe("os.subsystem")
if not compiler or not arch:
return ""

if str(compiler) in ['gcc', 'apple-clang', 'clang', 'sun-cc']:
if str(arch) in ['x86_64', 'sparcv9', 's390x']:
if str(the_os) == 'Macos' and str(subsystem) == 'Catalyst' and str(arch) == 'x86_64':
return '-target=x86_64-apple-ios-macabi'
elif str(arch) in ['x86_64', 'sparcv9', 's390x']:
return '-m64'
elif str(arch) in ['x86', 'sparc']:
return '-m32'
Expand Down
1 change: 1 addition & 0 deletions conans/client/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
Macos:
version: [None, "10.6", "10.7", "10.8", "10.9", "10.10", "10.11", "10.12", "10.13", "10.14", "10.15", "11.0"]
sdk: [None, "macosx"]
subsystem: [None, "Catalyst"]
Android:
api_level: ANY
iOS:
Expand Down
1 change: 1 addition & 0 deletions conans/client/migrations_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,7 @@
Macos:
version: [None, "10.6", "10.7", "10.8", "10.9", "10.10", "10.11", "10.12", "10.13", "10.14", "10.15", "11.0"]
sdk: [None, "macosx"]
subsystem: [None, "Catalyst"]
Android:
api_level: ANY
iOS:
Expand Down
5 changes: 4 additions & 1 deletion conans/client/tools/apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def apple_deployment_target_env(os_, os_version):
return {env_name: os_version}


def apple_deployment_target_flag(os_, os_version, os_sdk=None, arch=None):
def apple_deployment_target_flag(os_, os_version, os_sdk=None, os_subsystem=None, arch=None):
"""compiler flag name which controls deployment target"""
os_sdk = os_sdk if os_sdk else _guess_apple_sdk_name(os_, arch)
flag = {'macosx': '-mmacosx-version-min',
Expand All @@ -65,6 +65,9 @@ def apple_deployment_target_flag(os_, os_version, os_sdk=None, arch=None):
'watchsimulator': '-mwatchos-simulator-version-min',
'appletvos': '-mtvos-version-min',
'appletvsimulator': '-mtvos-simulator-version-min'}.get(str(os_sdk))
if os_subsystem == 'Catalyst':
# especial case, despite Catalyst is macOS, it requires an iOS version argument
flag = '-mios-version-min'
if not flag:
return ''
return "%s=%s" % (flag, os_version)
Expand Down
7 changes: 7 additions & 0 deletions conans/test/unittests/client/build/compiler_flags_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ def test_arch_flag(self, compiler, arch, the_os, flag):
"os": the_os})
self.assertEqual(architecture_flag(settings), flag)

def test_catalyst(self):
settings = MockSettings({"compiler": "apple-clang",
"arch": "x86_64",
"os": "Macos",
"os.subsystem": "Catalyst"})
self.assertEqual(architecture_flag(settings), "-target=x86_64-apple-ios-macabi")

@parameterized.expand([("gcc", "x86", "-m32"),
("gcc", "x86_64", "-m64"),
("Visual Studio", "x86", "/Qm32"),
Expand Down
6 changes: 6 additions & 0 deletions conans/test/unittests/util/apple_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def test_deployment_target_flag_name(self):
self.assertEqual(tools.apple_deployment_target_flag('tvOS', "10.1", 'appletvsimulator'),
'-mtvos-simulator-version-min=10.1')

self.assertEqual(tools.apple_deployment_target_flag("Macos", "10.1", None, "Catalyst"),
'-mios-version-min=10.1')

self.assertEqual(tools.apple_deployment_target_flag("Macos", "10.1", "MacOSX", "Catalyst"),
'-mios-version-min=10.1')

self.assertEqual('', tools.apple_deployment_target_flag('Solaris', "10.1"))

@pytest.mark.skipif(platform.system() != "Darwin", reason="Requires OSX")
Expand Down

0 comments on commit 597e6f7

Please sign in to comment.