Skip to content

Commit 7e4b05e

Browse files
authored
fix: filter out maccatalyst SPM platform (#829)
Bazel currently does not support `maccatalyst` as a platform. We were mapping it to `ios` as they are Mac apps that use iOS frameworks. However, this can lead to warnings if define values exist with the same name mapped for `ios` and `maccatalyst` (e.g. Firebase). This PR filters out `maccatalyst` conditions. Closes #801.
1 parent 1cc31be commit 7e4b05e

File tree

6 files changed

+88
-28
lines changed

6 files changed

+88
-28
lines changed

config_settings/spm/platform/platforms.bzl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ _PLATFORM_INFOS = [
4646
_platform_info(spm = p, bzl = None, os = p)
4747
for p in _NON_APPLE_PLATFORMS
4848
] + [
49-
# Treat `maccatalyst` as an alias of sorts for macos. This will be handled
50-
# in the `platforms.label` function.
51-
_platform_info(spm = "maccatalyst", bzl = None, os = None),
5249
# Map `driverkit` as `macos`. This will be handled in the
5350
# `platforms.label()` function.
5451
_platform_info(spm = "driverkit", bzl = None, os = None),
@@ -67,11 +64,17 @@ def _label(name):
6764
# There is currently no support Mac Catalyst in Bazel. These are Mac apps
6865
# that use iOS frameworks. Treat it like iOS for now.
6966
if name == "maccatalyst":
70-
name = "ios"
67+
fail("Unsupported swift package manager platform: maccatalyst.")
7168
if name == "driverkit":
7269
name = "macos"
7370
return "@rules_swift_package_manager//config_settings/spm/platform:{}".format(name)
7471

72+
def _is_supported(name):
73+
return name != "maccatalyst"
74+
75+
def _supported(names):
76+
return [n for n in names if _is_supported(n)]
77+
7578
platforms = struct(
7679
macos = "macos",
7780
maccatalyst = "maccatalyst",
@@ -86,4 +89,6 @@ platforms = struct(
8689
all_values = [pi.spm for pi in _PLATFORM_INFOS],
8790
all_platform_infos = _PLATFORM_INFOS,
8891
label = _label,
92+
is_supported = _is_supported,
93+
supported = _supported,
8994
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")
2+
load(":platforms_tests.bzl", "platforms_test_suite")
3+
4+
bzlformat_pkg(name = "bzlformat")
5+
6+
platforms_test_suite()
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""Tests for `platforms` module."""
2+
3+
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
4+
load("//config_settings/spm/platform:platforms.bzl", "platforms")
5+
6+
def _is_supported_test(ctx):
7+
env = unittest.begin(ctx)
8+
9+
tests = [
10+
struct(name = "maccatalyst", exp = False),
11+
] + [
12+
struct(name = name, exp = True)
13+
for name in platforms.all_values
14+
]
15+
for t in tests:
16+
actual = platforms.is_supported(t.name)
17+
msg = getattr(t, "msg", t.name)
18+
asserts.equals(env, t.exp, actual, msg)
19+
20+
return unittest.end(env)
21+
22+
is_supported_test = unittest.make(_is_supported_test)
23+
24+
def _supported_test(ctx):
25+
env = unittest.begin(ctx)
26+
27+
tests = [
28+
struct(
29+
msg = "all valid names",
30+
names = platforms.all_values,
31+
exp = platforms.all_values,
32+
),
33+
struct(
34+
msg = "some invalid names",
35+
names = [platforms.ios, platforms.maccatalyst, platforms.macos],
36+
exp = [platforms.ios, platforms.macos],
37+
),
38+
struct(
39+
msg = "only invalid names",
40+
names = [platforms.maccatalyst],
41+
exp = [],
42+
),
43+
]
44+
for t in tests:
45+
actual = platforms.supported(t.names)
46+
asserts.equals(env, t.exp, actual, t.msg)
47+
48+
return unittest.end(env)
49+
50+
supported_test = unittest.make(_supported_test)
51+
52+
def platforms_test_suite(name = "platforms_tests"):
53+
return unittest.suite(
54+
name,
55+
is_supported_test,
56+
supported_test,
57+
)

examples/firebase_example/MODULE.bazel.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swiftpkg/internal/bzl_selects.bzl

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,19 @@ def _new_from_build_setting(build_setting, values_map_fn = None):
6262
for v in values
6363
]
6464

65-
platforms_len = len(bsc.platforms)
65+
supported_platforms = spm_platforms.supported(bsc.platforms)
66+
platforms_len = len(supported_platforms)
6667
if platforms_len > 0 and bsc.configuration != None:
6768
conditions = [
6869
spm_platform_configurations.label(p, bsc.configuration)
69-
for p in bsc.platforms
70+
for p in supported_platforms
7071
]
7172
elif platforms_len > 0:
72-
conditions = [spm_platforms.label(p) for p in bsc.platforms]
73+
conditions = [spm_platforms.label(p) for p in supported_platforms]
7374
elif bsc.configuration != None:
7475
conditions = [spm_configurations.label(bsc.configuration)]
7576
else:
76-
fail("""\
77-
Found a build setting condition that had no platforms or a configuration. {}\
78-
""".format(build_setting))
77+
return []
7978

8079
return [
8180
_new(kind = build_setting.kind, value = v, condition = c)
@@ -97,13 +96,12 @@ def _new_from_target_dependency_condition(kind, labels, condition = None):
9796
"""
9897
if condition == None:
9998
return [_new(kind = kind, value = labels)]
100-
platforms_len = len(condition.platforms)
101-
if platforms_len > 0:
102-
conditions = [spm_platforms.label(p) for p in condition.platforms]
103-
else:
104-
fail("""\
105-
Found a target dependency condition that had no platforms. {}\
106-
""".format(condition))
99+
100+
conditions = [
101+
spm_platforms.label(p)
102+
for p in spm_platforms.supported(condition.platforms)
103+
]
104+
107105
return [
108106
_new(kind = kind, value = labels, condition = c)
109107
for c in conditions

swiftpkg/internal/pkginfos.bzl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,13 +1157,7 @@ def _new_build_setting_condition(platforms = [], configuration = None):
11571157
if platforms == [] and configuration == None:
11581158
return None
11591159

1160-
for platform in platforms:
1161-
validations.in_list(
1162-
spm_platforms.all_values,
1163-
platform,
1164-
"Unrecognized platform. platform:",
1165-
)
1166-
1160+
platforms = spm_platforms.supported(platforms)
11671161
if configuration != None:
11681162
validations.in_list(
11691163
spm_configurations.all_values,

0 commit comments

Comments
 (0)