Skip to content

Commit 32a84ac

Browse files
allevatoluispadron
authored andcommitted
Bump the minimum OS versions where we no longer need to run swift-stdlib-tool.
Some Swift `Span` APIs back-deploy before 26.0, so 26.0 is now the new minimum to ensure that `libswiftCompatibilitySpan.dylib` is included in bundles that target older OSes. Cherry-pick: e8a44d2
1 parent 3f02aab commit 32a84ac

5 files changed

Lines changed: 125 additions & 14 deletions

File tree

apple/internal/partials/swift_dylibs.bzl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ File object that represents a directory containing the Swift dylibs to package f
5757
},
5858
)
5959

60-
# Minimum OS versions for which we no longer need to potentially bundle any
61-
# Swift dylibs with the application. The first cutoff point was when the
62-
# platforms bundled the standard libraries, the second was when they started
63-
# bundling the Concurrency library. There may be future libraries that require
64-
# us to continue bumping these values. The tool is smart enough only to bundle
65-
# those libraries required by the minimum OS version of the scanned binaries.
60+
# For each platform, the minimum OS version at which we no longer need to bundle
61+
# any Swift dylibs with the application -- either the pre-ABI-stable runtime or
62+
# back-deployed runtimes (e.g., Concurrency and Span). We do not need to
63+
# consider each of these cases individually; `swift-stdlib-tool` will only
64+
# bundle the libraries required based on the minimum OS version of the scanned
65+
# binaries.
6666
#
67-
# Values are the first version where bundling is no longer required and should
68-
# correspond with the Swift compilers values for these which is the source of
69-
# truth https://github.com/apple/swift/blob/998d3518938bd7229e7c5e7b66088d0501c02051/lib/Basic/Platform.cpp#L82-L105
67+
# These values should be kept in sync with the values in
68+
# `swift::tripleRequiresRPathForSwiftLibrariesInOS` defined in:
69+
# https://github.com/apple/swift/blob/main/lib/Basic/Platform.cpp.
7070
_MIN_OS_PLATFORM_SWIFT_PRESENCE = {
71-
"ios": apple_common.dotted_version("15.0"),
72-
"macos": apple_common.dotted_version("12.0"),
73-
"tvos": apple_common.dotted_version("15.0"),
74-
"visionos": apple_common.dotted_version("1.0"),
75-
"watchos": apple_common.dotted_version("8.0"),
71+
"ios": apple_common.dotted_version("26.0"),
72+
"macos": apple_common.dotted_version("26.0"),
73+
"tvos": apple_common.dotted_version("26.0"),
74+
"visionos": apple_common.dotted_version("26.0"),
75+
"watchos": apple_common.dotted_version("26.0"),
7676
}
7777

7878
# swift-stdlib-tool currently bundles an unnecessary copy of the Swift runtime

test/starlark_tests/ios_application_tests.bzl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,54 @@ def ios_application_test_suite(name):
269269
tags = [name],
270270
)
271271

272+
archive_contents_test(
273+
name = "{}_device_swift_span_compatibility_dylib_present_on_older_os".format(name),
274+
build_type = "device",
275+
target_under_test = "//test/starlark_tests/targets_under_test/ios:swift_app_using_span_pre_26",
276+
contains = [
277+
"$BUNDLE_ROOT/Frameworks/libswiftCompatibilitySpan.dylib",
278+
"$ARCHIVE_ROOT/SwiftSupport/iphoneos/libswiftCompatibilitySpan.dylib",
279+
],
280+
tags = [
281+
name,
282+
],
283+
)
284+
archive_contents_test(
285+
name = "{}_simulator_swift_span_compatibility_dylib_present_on_older_os".format(name),
286+
build_type = "simulator",
287+
target_under_test = "//test/starlark_tests/targets_under_test/ios:swift_app_using_span_pre_26",
288+
contains = [
289+
"$BUNDLE_ROOT/Frameworks/libswiftCompatibilitySpan.dylib",
290+
],
291+
tags = [
292+
name,
293+
],
294+
)
295+
296+
archive_contents_test(
297+
name = "{}_device_swift_span_compatibility_dylib_not_present_on_newer_os".format(name),
298+
build_type = "device",
299+
target_under_test = "//test/starlark_tests/targets_under_test/ios:swift_app_using_span_post_26",
300+
not_contains = [
301+
"$BUNDLE_ROOT/Frameworks/libswiftCompatibilitySpan.dylib",
302+
"$ARCHIVE_ROOT/SwiftSupport/iphoneos/libswiftCompatibilitySpan.dylib",
303+
],
304+
tags = [
305+
name,
306+
],
307+
)
308+
archive_contents_test(
309+
name = "{}_simulator_swift_span_compatibility_dylib_not_present_on_newer_os".format(name),
310+
build_type = "simulator",
311+
target_under_test = "//test/starlark_tests/targets_under_test/ios:swift_app_using_span_post_26",
312+
not_contains = [
313+
"$BUNDLE_ROOT/Frameworks/libswiftCompatibilitySpan.dylib",
314+
],
315+
tags = [
316+
name,
317+
],
318+
)
319+
272320
apple_verification_test(
273321
name = "{}_imported_fmwk_codesign_test".format(name),
274322
build_type = "simulator",

test/starlark_tests/resources/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ swift_library(
333333
tags = common.fixture_tags,
334334
)
335335

336+
swift_library(
337+
name = "swift_span_main_lib",
338+
srcs = ["span_main.swift"],
339+
tags = common.fixture_tags,
340+
)
341+
336342
swift_library(
337343
name = "watchkit_ext_main_lib",
338344
srcs = ["WatchKitExtMain.swift"],
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
16+
@main
17+
struct App {
18+
static func main() {
19+
// Many back-deployed functions are `@_alwaysEmitIntoClient` so referencing them won't
20+
// necessarily require the dylib to be linked. Type metadata, on the other hand, will always
21+
// require the dylib to be linked.
22+
print(Span<Int>.self)
23+
}
24+
}

test/starlark_tests/targets_under_test/ios/BUILD

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5696,3 +5696,36 @@ ios_application(
56965696
"//test/starlark_tests/resources:swift_concurrency_main_lib",
56975697
],
56985698
)
5699+
5700+
# ---------------------------------------------------------------------------------------
5701+
# Targets for Swift span support
5702+
5703+
ios_application(
5704+
name = "swift_app_using_span_pre_26",
5705+
bundle_id = "com.google.example",
5706+
families = ["iphone"],
5707+
infoplists = [
5708+
"//test/starlark_tests/resources:Info.plist",
5709+
],
5710+
minimum_os_version = common.min_os_ios.oldest_supported,
5711+
provisioning_profile = "//test/testdata/provisioning:integration_testing_ios.mobileprovision",
5712+
tags = common.fixture_tags,
5713+
deps = [
5714+
"//test/starlark_tests/resources:swift_span_main_lib",
5715+
],
5716+
)
5717+
5718+
ios_application(
5719+
name = "swift_app_using_span_post_26",
5720+
bundle_id = "com.google.example",
5721+
families = ["iphone"],
5722+
infoplists = [
5723+
"//test/starlark_tests/resources:Info.plist",
5724+
],
5725+
minimum_os_version = common.min_os_ios.span_in_os,
5726+
provisioning_profile = "//test/testdata/provisioning:integration_testing_ios.mobileprovision",
5727+
tags = common.fixture_tags,
5728+
deps = [
5729+
"//test/starlark_tests/resources:swift_span_main_lib",
5730+
],
5731+
)

0 commit comments

Comments
 (0)