Skip to content

Commit e32bb8a

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 09078a3 commit e32bb8a

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
@@ -218,6 +218,54 @@ def ios_application_test_suite(name):
218218
tags = [name],
219219
)
220220

221+
archive_contents_test(
222+
name = "{}_device_swift_span_compatibility_dylib_present_on_older_os".format(name),
223+
build_type = "device",
224+
target_under_test = "//test/starlark_tests/targets_under_test/ios:swift_app_using_span_pre_26",
225+
contains = [
226+
"$BUNDLE_ROOT/Frameworks/libswiftCompatibilitySpan.dylib",
227+
"$ARCHIVE_ROOT/SwiftSupport/iphoneos/libswiftCompatibilitySpan.dylib",
228+
],
229+
tags = [
230+
name,
231+
],
232+
)
233+
archive_contents_test(
234+
name = "{}_simulator_swift_span_compatibility_dylib_present_on_older_os".format(name),
235+
build_type = "simulator",
236+
target_under_test = "//test/starlark_tests/targets_under_test/ios:swift_app_using_span_pre_26",
237+
contains = [
238+
"$BUNDLE_ROOT/Frameworks/libswiftCompatibilitySpan.dylib",
239+
],
240+
tags = [
241+
name,
242+
],
243+
)
244+
245+
archive_contents_test(
246+
name = "{}_device_swift_span_compatibility_dylib_not_present_on_newer_os".format(name),
247+
build_type = "device",
248+
target_under_test = "//test/starlark_tests/targets_under_test/ios:swift_app_using_span_post_26",
249+
not_contains = [
250+
"$BUNDLE_ROOT/Frameworks/libswiftCompatibilitySpan.dylib",
251+
"$ARCHIVE_ROOT/SwiftSupport/iphoneos/libswiftCompatibilitySpan.dylib",
252+
],
253+
tags = [
254+
name,
255+
],
256+
)
257+
archive_contents_test(
258+
name = "{}_simulator_swift_span_compatibility_dylib_not_present_on_newer_os".format(name),
259+
build_type = "simulator",
260+
target_under_test = "//test/starlark_tests/targets_under_test/ios:swift_app_using_span_post_26",
261+
not_contains = [
262+
"$BUNDLE_ROOT/Frameworks/libswiftCompatibilitySpan.dylib",
263+
],
264+
tags = [
265+
name,
266+
],
267+
)
268+
221269
apple_verification_test(
222270
name = "{}_imported_fmwk_codesign_test".format(name),
223271
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
@@ -5678,3 +5678,36 @@ ios_application(
56785678
"//test/starlark_tests/resources:swift_concurrency_main_lib",
56795679
],
56805680
)
5681+
5682+
# ---------------------------------------------------------------------------------------
5683+
# Targets for Swift span support
5684+
5685+
ios_application(
5686+
name = "swift_app_using_span_pre_26",
5687+
bundle_id = "com.google.example",
5688+
families = ["iphone"],
5689+
infoplists = [
5690+
"//test/starlark_tests/resources:Info.plist",
5691+
],
5692+
minimum_os_version = common.min_os_ios.oldest_supported,
5693+
provisioning_profile = "//test/testdata/provisioning:integration_testing_ios.mobileprovision",
5694+
tags = common.fixture_tags,
5695+
deps = [
5696+
"//test/starlark_tests/resources:swift_span_main_lib",
5697+
],
5698+
)
5699+
5700+
ios_application(
5701+
name = "swift_app_using_span_post_26",
5702+
bundle_id = "com.google.example",
5703+
families = ["iphone"],
5704+
infoplists = [
5705+
"//test/starlark_tests/resources:Info.plist",
5706+
],
5707+
minimum_os_version = common.min_os_ios.span_in_os,
5708+
provisioning_profile = "//test/testdata/provisioning:integration_testing_ios.mobileprovision",
5709+
tags = common.fixture_tags,
5710+
deps = [
5711+
"//test/starlark_tests/resources:swift_span_main_lib",
5712+
],
5713+
)

0 commit comments

Comments
 (0)