Skip to content

Commit 5262722

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 c0c2710 commit 5262722

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
@@ -52,12 +52,12 @@ bzl_library(
5252
name = "apple_binary",
5353
srcs = ["apple_binary.bzl"],
5454
deps = [
55+
"//apple/internal:apple_toolchains",
5556
"//apple/internal:linking_support",
5657
"//apple/internal:providers",
5758
"//apple/internal:rule_attrs",
5859
"//apple/internal:rule_factory",
5960
"//apple/internal:transition_support",
60-
"//apple/internal/toolchains:apple_toolchains",
6161
"@build_bazel_apple_support//lib:apple_support",
6262
"@rules_cc//cc/common",
6363
],
@@ -266,6 +266,7 @@ bzl_library(
266266
name = "watchos",
267267
srcs = ["watchos.bzl"],
268268
deps = [
269+
"//apple/internal:required_minimum_os",
269270
"//apple/internal:watchos_rules",
270271
"//apple/internal/testing:apple_test_assembler",
271272
"//apple/internal/testing:build_test_rules",

apple/internal/BUILD

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

672+
bzl_library(
673+
name = "required_minimum_os",
674+
srcs = ["required_minimum_os.bzl"],
675+
visibility = [
676+
"//apple:__subpackages__",
677+
],
678+
)
679+
672680
bzl_library(
673681
name = "transition_support",
674682
srcs = ["transition_support.bzl"],
@@ -741,6 +749,7 @@ bzl_library(
741749
":platform_support",
742750
":processor",
743751
":providers",
752+
":required_minimum_os",
744753
":resources",
745754
":rule_attrs",
746755
":rule_factory",
@@ -827,7 +836,6 @@ bzl_library(
827836
"//apple/internal/aspects:resource_aspect_hint",
828837
"//apple/internal/aspects:swift_usage_aspect",
829838
"//apple/internal/providers:xcframework_deps_info",
830-
"//apple/internal/toolchains:apple_toolchains",
831839
"//apple/internal/utils:files",
832840
"@bazel_skylib//lib:partial",
833841
"@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("""
@@ -1011,6 +1031,11 @@ reproducible error case.".format(
10111031

10121032
def _watchos_extension_impl(ctx):
10131033
"""Implementation of watchos_extension."""
1034+
required_minimum_os.validate(
1035+
minimum_os_version = ctx.attr.minimum_os_version,
1036+
platform_type = ctx.attr.platform_type,
1037+
rule_label = ctx.label,
1038+
)
10141039

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

13331358
def _watchos_static_framework_impl(ctx):
13341359
"""Implementation of watchos_static_framework."""
1360+
required_minimum_os.validate(
1361+
minimum_os_version = ctx.attr.minimum_os_version,
1362+
platform_type = ctx.attr.platform_type,
1363+
rule_label = ctx.label,
1364+
)
1365+
13351366
rule_descriptor = rule_support.rule_descriptor(
13361367
platform_type = ctx.attr.platform_type,
13371368
product_type = apple_product_type.static_framework,
@@ -1489,7 +1520,6 @@ def _watchos_static_framework_impl(ctx):
14891520

14901521
def _watchos_single_target_application_impl(ctx):
14911522
"""Implementation of watchos_application for single target watch applications."""
1492-
14931523
minimum_os = apple_common.dotted_version(ctx.attr.minimum_os_version)
14941524
if minimum_os < apple_common.dotted_version("7.0"):
14951525
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)