Skip to content

Commit 9814455

Browse files
authored
fix: support xcframeworks that use archive files (XXX.a) (#975)
- Check frameworks that are provided as archive files (XXX.a). - See [xcframwork doc](https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle) for more information. - Add [GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk](https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk) to the `resources_example`. This package provides their frameworks as archive files. Closes #968.
1 parent 6608ce7 commit 9814455

File tree

7 files changed

+136
-6
lines changed

7 files changed

+136
-6
lines changed

examples/resources_example/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use_repo(
5353
"swiftpkg_app_lovin_sdk",
5454
"swiftpkg_googlesignin_ios",
5555
"swiftpkg_package_with_resources",
56+
"swiftpkg_recaptcha_enterprise_mobile_sdk",
5657
"swiftpkg_sdwebimageswiftui",
5758
)
5859
# swift_deps END

examples/resources_example/Sources/MyApp/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ swift_library(
1414
"@swiftpkg_another_package_with_resources//:MoreCoolUI",
1515
"@swiftpkg_googlesignin_ios//:GoogleSignInSwift",
1616
"@swiftpkg_package_with_resources//:CoolUI",
17+
"@swiftpkg_recaptcha_enterprise_mobile_sdk//:RecaptchaEnterprise",
1718
"@swiftpkg_sdwebimageswiftui//:SDWebImageSwiftUI",
1819
],
1920
)

examples/resources_example/Sources/MyApp/MyApp.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import CoolUI
22
import GoogleSignInSwift
33
import MoreCoolUI
4+
import RecaptchaEnterprise
45
import SDWebImageSwiftUI
56
import SwiftUI
67

examples/resources_example/swift/Package.resolved

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/resources_example/swift/Package.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ let package = Package(
1010
.package(path: "../third_party/package_with_resources"),
1111
.package(url: "https://github.com/SDWebImage/SDWebImageSwiftUI.git", from: "3.0.1"),
1212
.package(url: "https://github.com/google/GoogleSignIn-iOS", from: "7.0.0"),
13+
.package(
14+
url: "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk",
15+
from: "18.4.2"
16+
),
1317
]
1418
)

examples/resources_example/swift_deps_index.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"app_lovin_sdk",
55
"googlesignin-ios",
66
"package_with_resources",
7+
"recaptcha-enterprise-mobile-sdk",
78
"sdwebimageswiftui"
89
],
910
"modules": [
@@ -134,6 +135,16 @@
134135
"GTMAppAuth"
135136
]
136137
},
138+
{
139+
"name": "RecaptchaInterop",
140+
"c99name": "RecaptchaInterop",
141+
"src_type": "objc",
142+
"label": "@swiftpkg_interop_ios_for_google_sdks//:RecaptchaInterop.rspm",
143+
"package_identity": "interop-ios-for-google-sdks",
144+
"product_memberships": [
145+
"RecaptchaInterop"
146+
]
147+
},
137148
{
138149
"name": "CoolUI",
139150
"c99name": "CoolUI",
@@ -144,6 +155,26 @@
144155
"CoolUI"
145156
]
146157
},
158+
{
159+
"name": "RecaptchaEnterprise",
160+
"c99name": "RecaptchaEnterprise",
161+
"src_type": "binary",
162+
"label": "@swiftpkg_recaptcha_enterprise_mobile_sdk//:RecaptchaEnterprise.rspm",
163+
"package_identity": "recaptcha-enterprise-mobile-sdk",
164+
"product_memberships": [
165+
"RecaptchaEnterprise"
166+
]
167+
},
168+
{
169+
"name": "recaptcha-enterprise",
170+
"c99name": "recaptcha_enterprise",
171+
"src_type": "clang",
172+
"label": "@swiftpkg_recaptcha_enterprise_mobile_sdk//:recaptcha-enterprise.rspm",
173+
"package_identity": "recaptcha-enterprise-mobile-sdk",
174+
"product_memberships": [
175+
"RecaptchaEnterprise"
176+
]
177+
},
147178
{
148179
"name": "SDWebImage",
149180
"c99name": "SDWebImage",
@@ -249,12 +280,24 @@
249280
"type": "library",
250281
"label": "@swiftpkg_gtmappauth//:GTMAppAuth"
251282
},
283+
{
284+
"identity": "interop-ios-for-google-sdks",
285+
"name": "RecaptchaInterop",
286+
"type": "library",
287+
"label": "@swiftpkg_interop_ios_for_google_sdks//:RecaptchaInterop"
288+
},
252289
{
253290
"identity": "package_with_resources",
254291
"name": "CoolUI",
255292
"type": "library",
256293
"label": "@swiftpkg_package_with_resources//:CoolUI"
257294
},
295+
{
296+
"identity": "recaptcha-enterprise-mobile-sdk",
297+
"name": "RecaptchaEnterprise",
298+
"type": "library",
299+
"label": "@swiftpkg_recaptcha_enterprise_mobile_sdk//:RecaptchaEnterprise"
300+
},
258301
{
259302
"identity": "sdwebimageswiftui",
260303
"name": "SDWebImageSwiftUI",
@@ -325,13 +368,31 @@
325368
"version": "2.0.0"
326369
}
327370
},
371+
{
372+
"name": "swiftpkg_interop_ios_for_google_sdks",
373+
"identity": "interop-ios-for-google-sdks",
374+
"remote": {
375+
"commit": "2d12673670417654f08f5f90fdd62926dc3a2648",
376+
"remote": "https://github.com/google/interop-ios-for-google-sdks.git",
377+
"version": "100.0.0"
378+
}
379+
},
328380
{
329381
"name": "swiftpkg_package_with_resources",
330382
"identity": "package_with_resources",
331383
"local": {
332384
"path": "third_party/package_with_resources"
333385
}
334386
},
387+
{
388+
"name": "swiftpkg_recaptcha_enterprise_mobile_sdk",
389+
"identity": "recaptcha-enterprise-mobile-sdk",
390+
"remote": {
391+
"commit": "54f4584f85144cac8288210da556a10b32067081",
392+
"remote": "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk",
393+
"version": "18.4.2"
394+
}
395+
},
335396
{
336397
"name": "swiftpkg_sdwebimage",
337398
"identity": "sdwebimage",

swiftpkg/internal/artifact_infos.bzl

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ https://github.com/cgrindel/rules_swift_package_manager/issues/new/choose. path:
6161
""".format(path))
6262
return name
6363

64-
def _new_framework_info_from_files(repository_ctx, path):
64+
def _new_framework_info_from_framework_dir(repository_ctx, path):
6565
"""Create a `struct` representing an Apple framework from the files at the \
6666
specified path.
6767
@@ -96,6 +96,25 @@ def _new_framework_info_from_files(repository_ctx, path):
9696
link_type = link_type,
9797
)
9898

99+
def _new_framework_info_from_framework_a_file(repository_ctx, framework_a_file):
100+
"""Create a `struct` representing an Apple framework from an archive file \
101+
(XXX.a).
102+
103+
Args:
104+
repository_ctx: A `repository_ctx` instance.
105+
framework_a_file: The path to a `XXX.a` file as a `string`.
106+
107+
Returns:
108+
A `struct` representing an Apple framework as returned by
109+
`artifact_infos.new_framework_info()`.
110+
"""
111+
path = paths.dirname(framework_a_file)
112+
link_type = _link_type(repository_ctx, framework_a_file)
113+
return _new_framework_info(
114+
path = path,
115+
link_type = link_type,
116+
)
117+
99118
def _link_type(repository_ctx, path):
100119
"""Determine the link type for the framework binary file.
101120
@@ -134,21 +153,46 @@ def _new_xcframework_info_from_files(repository_ctx, path):
134153
`artifact_infos.new_xcframework_info()`.
135154
"""
136155

137-
# XC Frameworks have a structure like the following:
156+
# XC Frameworks have one of two layouts:
157+
#
158+
# Layout: XXX.framework directory
138159
# XXX.xcframework
139160
# └─ ios-arm64/XXX.framework
140161
# └─ ios-arm64_x86_64-maccatalyst/XXX.framework
141162
# └─ macos-arm64_x86_64/XXX.framework
163+
#
164+
# Layout: XXX.a file
165+
# XXX.xcframework
166+
# └─ ios-arm64/XXX.a
167+
# └─ ios-arm64_x86_64-maccatalyst/XXX.a
168+
# └─ macos-arm64_x86_64/XXX.a
169+
#
170+
# We check for the XXX.framework layout first. If we do not find anything,
171+
# we look for the XXX.a layout.
142172
framework_paths = repository_files.list_directories_under(
143173
repository_ctx,
144174
path,
145175
by_name = "*.framework",
146176
depth = 2,
147177
)
148-
framework_infos = [
149-
_new_framework_info_from_files(repository_ctx, fp)
150-
for fp in framework_paths
151-
]
178+
179+
if framework_paths:
180+
framework_infos = [
181+
_new_framework_info_from_framework_dir(repository_ctx, fp)
182+
for fp in framework_paths
183+
]
184+
else:
185+
framework_a_files = repository_files.list_files_under(
186+
repository_ctx,
187+
path,
188+
by_name = "*.a",
189+
depth = 2,
190+
)
191+
framework_infos = [
192+
_new_framework_info_from_framework_a_file(repository_ctx, faf)
193+
for faf in framework_a_files
194+
]
195+
152196
return _new_xcframework_info(
153197
path = path,
154198
framework_infos = framework_infos,

0 commit comments

Comments
 (0)