Skip to content

Commit 90f56de

Browse files
luispadroncgrindelmergify[bot]
authored
fix: support binary artifacts in nested dirs (#1376)
This brings the rules more in line with what SPM seems to support (though I couldn't find any spec on this specifically). The current binary artifact generation logic in rules_swift_package_manager assumes the binary target is at most one level deep in the archive directory while [SPM seems to just find all `.xcframework` directories it can](https://github.com/swiftlang/swift-package-manager/blob/c26c12f54357fb7246c0bdbe3483105389f056b8/Sources/Workspace/Workspace%2BBinaryArtifacts.swift#L699-L724). This PR adds an example where the current behavior (e.g. `-max-depth 1`) causes the `.rspm` targets to not be generated for most of the products of the Yoti package. --------- Co-authored-by: Chuck Grindel <[email protected]> Co-authored-by: Chuck Grindel <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 1066713 commit 90f56de

File tree

11 files changed

+106
-89
lines changed

11 files changed

+106
-89
lines changed

.bazelrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# To update these lines, execute
22
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
3-
build --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Sources/System,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/aaa_test,examples/grpc_example/protos,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/grpc_example/sources/test,examples/grpc_package_example,examples/grpc_package_example/aaa_test,examples/grpc_package_example/protos,examples/grpc_package_example/protos/echo_service,examples/grpc_package_example/sources,examples/grpc_package_example/sources/client,examples/grpc_package_example/sources/server,examples/grpc_package_example/sources/test,examples/interesting_deps,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources,examples/messagekit_example/UITests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example
4-
query --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Sources/System,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/aaa_test,examples/grpc_example/protos,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/grpc_example/sources/test,examples/grpc_package_example,examples/grpc_package_example/aaa_test,examples/grpc_package_example/protos,examples/grpc_package_example/protos/echo_service,examples/grpc_package_example/sources,examples/grpc_package_example/sources/client,examples/grpc_package_example/sources/server,examples/grpc_package_example/sources/test,examples/interesting_deps,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources,examples/messagekit_example/UITests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example
3+
build --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Sources/System,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/aaa_test,examples/grpc_example/protos,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/grpc_example/sources/test,examples/grpc_package_example,examples/grpc_package_example/aaa_test,examples/grpc_package_example/protos,examples/grpc_package_example/protos/echo_service,examples/grpc_package_example/sources,examples/grpc_package_example/sources/client,examples/grpc_package_example/sources/server,examples/grpc_package_example/sources/test,examples/interesting_deps,examples/interesting_deps/ios,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources,examples/messagekit_example/UITests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example
4+
query --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Sources/System,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/aaa_test,examples/grpc_example/protos,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/grpc_example/sources/test,examples/grpc_package_example,examples/grpc_package_example/aaa_test,examples/grpc_package_example/protos,examples/grpc_package_example/protos/echo_service,examples/grpc_package_example/sources,examples/grpc_package_example/sources/client,examples/grpc_package_example/sources/server,examples/grpc_package_example/sources/test,examples/interesting_deps,examples/interesting_deps/ios,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources,examples/messagekit_example/UITests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example
55

66
# Import Shared settings
77
import %workspace%/shared.bazelrc

.github/actions/set_up_macos/action.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ runs:
1414
steps:
1515
- uses: maxim-lobanov/setup-xcode@v1
1616
with:
17-
xcode-version: '15.0.1'
17+
xcode-version: '15.2'
1818
- name: Override Xcode Version
1919
shell: bash
2020
run: |
@@ -25,9 +25,8 @@ runs:
2525
[[ "${{ inputs.test_target }}" = "@@//examples:shake_ios_example_test_bazel_.bazelversion" ]]; then
2626
sudo xcode-select -s /Applications/Xcode_14.3.1.app/Contents/Developer
2727
fi
28-
# TODO: Migrate all CI jobs to Xcode 15.2
29-
if [[ "${{ inputs.test_target }}" = "@@//examples:stripe_example_test_bazel_.bazelversion" ]]; then
30-
sudo xcode-select -s /Applications/Xcode_15.2.app/Contents/Developer
28+
if [[ "${{ inputs.test_target }}" = "@@//examples:firebase_example_test_bazel_.bazelversion" ]]; then
29+
sudo xcode-select -s /Applications/Xcode_15.0.1.app/Contents/Developer
3130
fi
3231
- name: Confirm Xcode Version
3332
shell: bash

examples/interesting_deps/MODULE.bazel

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ bazel_dep(name = "bazel_skylib", version = "1.7.1")
1818
# The apple_support bazel_dep must come before the rules_cc.
1919
# https://github.com/bazelbuild/apple_support#incompatible-toolchain-resolution
2020
bazel_dep(name = "apple_support", version = "1.17.1")
21+
bazel_dep(name = "platforms", version = "0.0.6")
2122
bazel_dep(
2223
name = "rules_swift",
2324
version = "2.2.4",
@@ -78,4 +79,5 @@ use_repo(
7879
"swiftpkg_ocmock",
7980
"swiftpkg_opencombine",
8081
"swiftpkg_swift_log",
82+
"swiftpkg_yoti_doc_scan_ios",
8183
)

examples/interesting_deps/Package.resolved

+9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@
6262
"revision" : "96a2f8a0fa41e9e09af4585e2724c4e825410b91",
6363
"version" : "1.6.2"
6464
}
65+
},
66+
{
67+
"identity" : "yoti-doc-scan-ios",
68+
"kind" : "remoteSourceControl",
69+
"location" : "https://github.com/getyoti/yoti-doc-scan-ios.git",
70+
"state" : {
71+
"revision" : "f7bacd2c42aaa92db0272ce9d9e9b25bf69ee4bc",
72+
"version" : "6.0.0"
73+
}
6574
}
6675
],
6776
"version" : 2

examples/interesting_deps/Package.swift

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ let package = Package(
1111
.package(url: "https://github.com/SDWebImage/libwebp-Xcode.git", from: "1.3.2"),
1212
.package(url: "https://github.com/apple/swift-log", from: "1.6.2"),
1313
.package(url: "https://github.com/erikdoe/ocmock", from: "3.9.4"),
14+
.package(url: "https://github.com/getyoti/yoti-doc-scan-ios.git", from: "6.0.0"),
1415
]
1516
)
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application")
2+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
3+
4+
swift_library(
5+
name = "simple_ios_app.lib",
6+
srcs = ["ios_main.swift"],
7+
tags = ["manual"],
8+
target_compatible_with = ["@platforms//os:ios"],
9+
visibility = ["//swift:__subpackages__"],
10+
deps = ["@swiftpkg_yoti_doc_scan_ios//:YotiDocumentScan"],
11+
)
12+
13+
ios_application(
14+
name = "simple_ios_app",
15+
bundle_id = "com.example.simple_ios_app",
16+
families = [
17+
"iphone",
18+
"ipad",
19+
],
20+
infoplists = ["Info.plist"],
21+
minimum_os_version = "14.0",
22+
deps = [":simple_ios_app.lib"],
23+
)
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>LSRequiresIPhoneOS</key>
24+
<true/>
25+
<key>UILaunchStoryboardName</key>
26+
<string>LaunchScreen</string>
27+
<key>UIRequiredDeviceCapabilities</key>
28+
<array>
29+
<string>armv7</string>
30+
</array>
31+
<key>UISupportedInterfaceOrientations</key>
32+
<array>
33+
<string>UIInterfaceOrientationPortrait</string>
34+
<string>UIInterfaceOrientationLandscapeLeft</string>
35+
<string>UIInterfaceOrientationLandscapeRight</string>
36+
</array>
37+
</dict>
38+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import SwiftUI
2+
import YotiDocumentScan
3+
4+
@main
5+
struct Main: App {
6+
var body: some Scene {
7+
WindowGroup {
8+
Text("Hello, World!")
9+
}
10+
}
11+
}

examples/interesting_deps/set_up_clean_test

-72
This file was deleted.

swiftpkg/internal/repo_rules.bzl

+13-1
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,21 @@ def _artifact_infos_from_path(repository_ctx, path):
136136
xcframework_dirs = repository_files.list_directories_under(
137137
repository_ctx,
138138
path,
139-
max_depth = 1,
140139
by_name = "*.xcframework",
141140
)
141+
142+
# If multiple found, use the last one which is what SPM currently does:
143+
# https://github.com/swiftlang/swift-package-manager/blob/c26c12f54357fb7246c0bdbe3483105389f056b8/Sources/Workspace/Workspace%2BBinaryArtifacts.swift#L699-L723
144+
if len(xcframework_dirs) > 1:
145+
# buildifier: disable=print
146+
print("""\
147+
WARNING: Found multiple XCFramework binary artifacts in the downloaded artifact: \
148+
{xcframework_dirs}, using the last one.
149+
""".format(
150+
xcframework_dirs = xcframework_dirs,
151+
))
152+
xcframework_dirs = xcframework_dirs[-1:]
153+
142154
return [
143155
artifact_infos.new_xcframework_info_from_files(repository_ctx, xf)
144156
for xf in xcframework_dirs

swiftpkg/internal/swiftpkg_build_files.bzl

+4-10
Original file line numberDiff line numberDiff line change
@@ -694,16 +694,10 @@ expected: {expected}\
694694
expected = ", ".join([link_types.static, link_types.dynamic]),
695695
),
696696
)
697-
if target.path.endswith(".xcframework"):
698-
glob = scg.new_fn_call(
699-
"glob",
700-
["{tpath}/**".format(tpath = target.path)],
701-
)
702-
else:
703-
glob = scg.new_fn_call(
704-
"glob",
705-
["{tpath}/*.xcframework/**".format(tpath = target.path)],
706-
)
697+
glob = scg.new_fn_call(
698+
"glob",
699+
["{xcframework_path}/**".format(xcframework_path = artifact_info.path)],
700+
)
707701
decls = [
708702
build_decls.new(
709703
kind = kind,

0 commit comments

Comments
 (0)