Skip to content

Commit e9e9be5

Browse files
nglevinluispadron
authored andcommitted
Add a method to check assigned minimum OS versions to make sure that they fall within Apple-supported requirements.
Starting with watchOS top level rules rather than SDK rules or test rules, as that has fewer dependencies at the moment. Further take this opportunity to move iOS examples up to the recommended minimum OS version of 15.0. NOTE: updates test data and tests to match new Xcode 16 required min OS versions Cherry-pick: 2e938c0
1 parent cb44032 commit e9e9be5

31 files changed

Lines changed: 205 additions & 138 deletions

apple/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ bzl_library(
7373
name = "apple_binary",
7474
srcs = ["apple_binary.bzl"],
7575
deps = [
76+
"//apple/internal:apple_toolchains",
7677
"//apple/internal:linking_support",
7778
"//apple/internal:providers",
7879
"//apple/internal:rule_attrs",
7980
"//apple/internal:rule_factory",
8081
"//apple/internal:transition_support",
81-
"//apple/internal/toolchains:apple_toolchains",
8282
"@build_bazel_apple_support//lib:apple_support",
8383
"@rules_cc//cc/common",
8484
],
@@ -282,6 +282,7 @@ bzl_library(
282282
name = "watchos",
283283
srcs = ["watchos.bzl"],
284284
deps = [
285+
"//apple/internal:required_minimum_os",
285286
"//apple/internal:watchos_rules",
286287
"//apple/internal/testing:apple_test_assembler",
287288
"//apple/internal/testing:build_test_rules",

apple/internal/BUILD

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,14 @@ bzl_library(
668668
],
669669
)
670670

671+
bzl_library(
672+
name = "required_minimum_os",
673+
srcs = ["required_minimum_os.bzl"],
674+
visibility = [
675+
"//apple:__subpackages__",
676+
],
677+
)
678+
671679
bzl_library(
672680
name = "transition_support",
673681
srcs = ["transition_support.bzl"],
@@ -740,6 +748,7 @@ bzl_library(
740748
":platform_support",
741749
":processor",
742750
":providers",
751+
":required_minimum_os",
743752
":resources",
744753
":rule_attrs",
745754
":rule_factory",
@@ -826,7 +835,6 @@ bzl_library(
826835
"//apple/internal/aspects:resource_aspect_hint",
827836
"//apple/internal/aspects:swift_usage_aspect",
828837
"//apple/internal/providers:xcframework_deps_info",
829-
"//apple/internal/toolchains:apple_toolchains",
830838
"//apple/internal/utils:files",
831839
"@bazel_skylib//lib:partial",
832840
"@bazel_skylib//lib:paths",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2025 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Required minimum OS versions for Apple platforms."""
16+
17+
visibility([
18+
"//apple/...",
19+
"//test/...",
20+
])
21+
22+
# Based on https://developer.apple.com/support/xcode/ for Xcode 16 as of 2025-08-01.
23+
_REQUIRED_MINIMUM_OS_VERSION = {
24+
"ios": "15.0",
25+
"macos": "10.13", # TODO: b/433768882 - Move up to 11.0 for Xcode 26.
26+
"tvos": "12.0", # TODO: b/433768882 - Move up to 15.0 for Xcode 16.0.
27+
"visionos": "1.0",
28+
"watchos": "8.0",
29+
}
30+
31+
def _validate(*, minimum_os_version, platform_type, rule_label):
32+
"""Verifies that the given minimum OS version is supported for the given platform type."""
33+
if (apple_common.dotted_version(minimum_os_version) <
34+
apple_common.dotted_version(_REQUIRED_MINIMUM_OS_VERSION[platform_type])):
35+
fail("""
36+
Error: The declared minimum OS version for {rule_label} is "{minimum_os_version}", which is lower \
37+
than the required minimum OS version of "{required_minimum_os_version}".
38+
39+
Please update the minimum_os_version attribute to "{required_minimum_os_version}" or higher.
40+
""".format(
41+
rule_label = str(rule_label),
42+
minimum_os_version = minimum_os_version,
43+
required_minimum_os_version = _REQUIRED_MINIMUM_OS_VERSION[platform_type],
44+
))
45+
46+
required_minimum_os = struct(
47+
validate = _validate,
48+
)

apple/internal/watchos_rules.bzl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ load(
9797
"new_watchosapplicationbundleinfo",
9898
"new_watchosextensionbundleinfo",
9999
)
100+
load(
101+
"//apple/internal:required_minimum_os.bzl",
102+
"required_minimum_os",
103+
)
100104
load(
101105
"//apple/internal:resources.bzl",
102106
"resources",
@@ -149,6 +153,12 @@ load(
149153

150154
def _watchos_framework_impl(ctx):
151155
"""Experimental implementation of watchos_framework."""
156+
required_minimum_os.validate(
157+
minimum_os_version = ctx.attr.minimum_os_version,
158+
platform_type = ctx.attr.platform_type,
159+
rule_label = ctx.label,
160+
)
161+
152162
rule_descriptor = rule_support.rule_descriptor(
153163
platform_type = ctx.attr.platform_type,
154164
product_type = apple_product_type.framework,
@@ -404,6 +414,12 @@ def _watchos_framework_impl(ctx):
404414

405415
def _watchos_dynamic_framework_impl(ctx):
406416
"""Experimental implementation of watchos_dynamic_framework."""
417+
required_minimum_os.validate(
418+
minimum_os_version = ctx.attr.minimum_os_version,
419+
platform_type = ctx.attr.platform_type,
420+
rule_label = ctx.label,
421+
)
422+
407423
rule_descriptor = rule_support.rule_descriptor(
408424
platform_type = ctx.attr.platform_type,
409425
product_type = apple_product_type.framework,
@@ -707,6 +723,11 @@ def _watchos_dynamic_framework_impl(ctx):
707723

708724
def _watchos_application_impl(ctx):
709725
"""Implementation of watchos_application."""
726+
required_minimum_os.validate(
727+
minimum_os_version = ctx.attr.minimum_os_version,
728+
platform_type = ctx.attr.platform_type,
729+
rule_label = ctx.label,
730+
)
710731

711732
if ctx.attr.deps:
712733
return _watchos_single_target_application_impl(ctx)
@@ -715,7 +736,6 @@ def _watchos_application_impl(ctx):
715736

716737
def _watchos_extension_based_application_impl(ctx):
717738
"""Implementation of watchos_application for watchOS 2 extension-based application bundles."""
718-
719739
minimum_os = apple_common.dotted_version(ctx.attr.minimum_os_version)
720740
if minimum_os >= apple_common.dotted_version("9.0"):
721741
fail("""
@@ -1008,6 +1028,11 @@ reproducible error case.".format(
10081028

10091029
def _watchos_extension_impl(ctx):
10101030
"""Implementation of watchos_extension."""
1031+
required_minimum_os.validate(
1032+
minimum_os_version = ctx.attr.minimum_os_version,
1033+
platform_type = ctx.attr.platform_type,
1034+
rule_label = ctx.label,
1035+
)
10111036

10121037
# TODO(b/155313625): Set the product type as apple_product_type.extension if the attrs set on
10131038
# the rule match a criteria appropriate for watchOS extensions (i.e. SiriKit, Notification
@@ -1326,6 +1351,12 @@ def _watchos_extension_impl(ctx):
13261351

13271352
def _watchos_static_framework_impl(ctx):
13281353
"""Implementation of watchos_static_framework."""
1354+
required_minimum_os.validate(
1355+
minimum_os_version = ctx.attr.minimum_os_version,
1356+
platform_type = ctx.attr.platform_type,
1357+
rule_label = ctx.label,
1358+
)
1359+
13291360
rule_descriptor = rule_support.rule_descriptor(
13301361
platform_type = ctx.attr.platform_type,
13311362
product_type = apple_product_type.static_framework,
@@ -1483,7 +1514,6 @@ def _watchos_static_framework_impl(ctx):
14831514

14841515
def _watchos_single_target_application_impl(ctx):
14851516
"""Implementation of watchos_application for single target watch applications."""
1486-
14871517
minimum_os = apple_common.dotted_version(ctx.attr.minimum_os_version)
14881518
if minimum_os < apple_common.dotted_version("7.0"):
14891519
fail("Single-target watchOS applications require a minimum_os_version of 7.0 or greater.")

apple/ios.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Typical usage:
125125
```starlark
126126
ios_build_test(
127127
name = "my_build_test",
128-
minimum_os_version = "12.0",
128+
minimum_os_version = "15.0",
129129
targets = [
130130
"//some/package:my_library",
131131
],

apple/tvos.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Typical usage:
7777
```starlark
7878
tvos_build_test(
7979
name = "my_build_test",
80-
minimum_os_version = "12.0",
80+
minimum_os_version = "15.0",
8181
targets = [
8282
"//some/package:my_library",
8383
],

apple/watchos.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Typical usage:
7777
```starlark
7878
watchos_build_test(
7979
name = "my_build_test",
80-
minimum_os_version = "6.0",
80+
minimum_os_version = "8.0",
8181
targets = [
8282
"//some/package:my_library",
8383
],

doc/rules-ios.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Typical usage:
139139
```starlark
140140
ios_build_test(
141141
name = "my_build_test",
142-
minimum_os_version = "12.0",
142+
minimum_os_version = "15.0",
143143
targets = [
144144
"//some/package:my_library",
145145
],

doc/rules-tvos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Typical usage:
7979
```starlark
8080
tvos_build_test(
8181
name = "my_build_test",
82-
minimum_os_version = "12.0",
82+
minimum_os_version = "15.0",
8383
targets = [
8484
"//some/package:my_library",
8585
],

doc/rules-watchos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Typical usage:
7777
```starlark
7878
watchos_build_test(
7979
name = "my_build_test",
80-
minimum_os_version = "6.0",
80+
minimum_os_version = "8.0",
8181
targets = [
8282
"//some/package:my_library",
8383
],

0 commit comments

Comments
 (0)