Skip to content

Commit

Permalink
fix: support xcframeworks that use archive files (XXX.a) (#975)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
cgrindel authored Mar 23, 2024
1 parent 6608ce7 commit 9814455
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 6 deletions.
1 change: 1 addition & 0 deletions examples/resources_example/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use_repo(
"swiftpkg_app_lovin_sdk",
"swiftpkg_googlesignin_ios",
"swiftpkg_package_with_resources",
"swiftpkg_recaptcha_enterprise_mobile_sdk",
"swiftpkg_sdwebimageswiftui",
)
# swift_deps END
1 change: 1 addition & 0 deletions examples/resources_example/Sources/MyApp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ swift_library(
"@swiftpkg_another_package_with_resources//:MoreCoolUI",
"@swiftpkg_googlesignin_ios//:GoogleSignInSwift",
"@swiftpkg_package_with_resources//:CoolUI",
"@swiftpkg_recaptcha_enterprise_mobile_sdk//:RecaptchaEnterprise",
"@swiftpkg_sdwebimageswiftui//:SDWebImageSwiftUI",
],
)
Expand Down
1 change: 1 addition & 0 deletions examples/resources_example/Sources/MyApp/MyApp.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CoolUI
import GoogleSignInSwift
import MoreCoolUI
import RecaptchaEnterprise
import SDWebImageSwiftUI
import SwiftUI

Expand Down
18 changes: 18 additions & 0 deletions examples/resources_example/swift/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@
"version" : "2.0.0"
}
},
{
"identity" : "interop-ios-for-google-sdks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/interop-ios-for-google-sdks.git",
"state" : {
"revision" : "2d12673670417654f08f5f90fdd62926dc3a2648",
"version" : "100.0.0"
}
},
{
"identity" : "recaptcha-enterprise-mobile-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk",
"state" : {
"revision" : "54f4584f85144cac8288210da556a10b32067081",
"version" : "18.4.2"
}
},
{
"identity" : "sdwebimage",
"kind" : "remoteSourceControl",
Expand Down
4 changes: 4 additions & 0 deletions examples/resources_example/swift/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ let package = Package(
.package(path: "../third_party/package_with_resources"),
.package(url: "https://github.com/SDWebImage/SDWebImageSwiftUI.git", from: "3.0.1"),
.package(url: "https://github.com/google/GoogleSignIn-iOS", from: "7.0.0"),
.package(
url: "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk",
from: "18.4.2"
),
]
)
61 changes: 61 additions & 0 deletions examples/resources_example/swift_deps_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"app_lovin_sdk",
"googlesignin-ios",
"package_with_resources",
"recaptcha-enterprise-mobile-sdk",
"sdwebimageswiftui"
],
"modules": [
Expand Down Expand Up @@ -134,6 +135,16 @@
"GTMAppAuth"
]
},
{
"name": "RecaptchaInterop",
"c99name": "RecaptchaInterop",
"src_type": "objc",
"label": "@swiftpkg_interop_ios_for_google_sdks//:RecaptchaInterop.rspm",
"package_identity": "interop-ios-for-google-sdks",
"product_memberships": [
"RecaptchaInterop"
]
},
{
"name": "CoolUI",
"c99name": "CoolUI",
Expand All @@ -144,6 +155,26 @@
"CoolUI"
]
},
{
"name": "RecaptchaEnterprise",
"c99name": "RecaptchaEnterprise",
"src_type": "binary",
"label": "@swiftpkg_recaptcha_enterprise_mobile_sdk//:RecaptchaEnterprise.rspm",
"package_identity": "recaptcha-enterprise-mobile-sdk",
"product_memberships": [
"RecaptchaEnterprise"
]
},
{
"name": "recaptcha-enterprise",
"c99name": "recaptcha_enterprise",
"src_type": "clang",
"label": "@swiftpkg_recaptcha_enterprise_mobile_sdk//:recaptcha-enterprise.rspm",
"package_identity": "recaptcha-enterprise-mobile-sdk",
"product_memberships": [
"RecaptchaEnterprise"
]
},
{
"name": "SDWebImage",
"c99name": "SDWebImage",
Expand Down Expand Up @@ -249,12 +280,24 @@
"type": "library",
"label": "@swiftpkg_gtmappauth//:GTMAppAuth"
},
{
"identity": "interop-ios-for-google-sdks",
"name": "RecaptchaInterop",
"type": "library",
"label": "@swiftpkg_interop_ios_for_google_sdks//:RecaptchaInterop"
},
{
"identity": "package_with_resources",
"name": "CoolUI",
"type": "library",
"label": "@swiftpkg_package_with_resources//:CoolUI"
},
{
"identity": "recaptcha-enterprise-mobile-sdk",
"name": "RecaptchaEnterprise",
"type": "library",
"label": "@swiftpkg_recaptcha_enterprise_mobile_sdk//:RecaptchaEnterprise"
},
{
"identity": "sdwebimageswiftui",
"name": "SDWebImageSwiftUI",
Expand Down Expand Up @@ -325,13 +368,31 @@
"version": "2.0.0"
}
},
{
"name": "swiftpkg_interop_ios_for_google_sdks",
"identity": "interop-ios-for-google-sdks",
"remote": {
"commit": "2d12673670417654f08f5f90fdd62926dc3a2648",
"remote": "https://github.com/google/interop-ios-for-google-sdks.git",
"version": "100.0.0"
}
},
{
"name": "swiftpkg_package_with_resources",
"identity": "package_with_resources",
"local": {
"path": "third_party/package_with_resources"
}
},
{
"name": "swiftpkg_recaptcha_enterprise_mobile_sdk",
"identity": "recaptcha-enterprise-mobile-sdk",
"remote": {
"commit": "54f4584f85144cac8288210da556a10b32067081",
"remote": "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk",
"version": "18.4.2"
}
},
{
"name": "swiftpkg_sdwebimage",
"identity": "sdwebimage",
Expand Down
56 changes: 50 additions & 6 deletions swiftpkg/internal/artifact_infos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ https://github.com/cgrindel/rules_swift_package_manager/issues/new/choose. path:
""".format(path))
return name

def _new_framework_info_from_files(repository_ctx, path):
def _new_framework_info_from_framework_dir(repository_ctx, path):
"""Create a `struct` representing an Apple framework from the files at the \
specified path.
Expand Down Expand Up @@ -96,6 +96,25 @@ def _new_framework_info_from_files(repository_ctx, path):
link_type = link_type,
)

def _new_framework_info_from_framework_a_file(repository_ctx, framework_a_file):
"""Create a `struct` representing an Apple framework from an archive file \
(XXX.a).
Args:
repository_ctx: A `repository_ctx` instance.
framework_a_file: The path to a `XXX.a` file as a `string`.
Returns:
A `struct` representing an Apple framework as returned by
`artifact_infos.new_framework_info()`.
"""
path = paths.dirname(framework_a_file)
link_type = _link_type(repository_ctx, framework_a_file)
return _new_framework_info(
path = path,
link_type = link_type,
)

def _link_type(repository_ctx, path):
"""Determine the link type for the framework binary file.
Expand Down Expand Up @@ -134,21 +153,46 @@ def _new_xcframework_info_from_files(repository_ctx, path):
`artifact_infos.new_xcframework_info()`.
"""

# XC Frameworks have a structure like the following:
# XC Frameworks have one of two layouts:
#
# Layout: XXX.framework directory
# XXX.xcframework
# └─ ios-arm64/XXX.framework
# └─ ios-arm64_x86_64-maccatalyst/XXX.framework
# └─ macos-arm64_x86_64/XXX.framework
#
# Layout: XXX.a file
# XXX.xcframework
# └─ ios-arm64/XXX.a
# └─ ios-arm64_x86_64-maccatalyst/XXX.a
# └─ macos-arm64_x86_64/XXX.a
#
# We check for the XXX.framework layout first. If we do not find anything,
# we look for the XXX.a layout.
framework_paths = repository_files.list_directories_under(
repository_ctx,
path,
by_name = "*.framework",
depth = 2,
)
framework_infos = [
_new_framework_info_from_files(repository_ctx, fp)
for fp in framework_paths
]

if framework_paths:
framework_infos = [
_new_framework_info_from_framework_dir(repository_ctx, fp)
for fp in framework_paths
]
else:
framework_a_files = repository_files.list_files_under(
repository_ctx,
path,
by_name = "*.a",
depth = 2,
)
framework_infos = [
_new_framework_info_from_framework_a_file(repository_ctx, faf)
for faf in framework_a_files
]

return _new_xcframework_info(
path = path,
framework_infos = framework_infos,
Expand Down

0 comments on commit 9814455

Please sign in to comment.