Skip to content

Commit

Permalink
Merge pull request #208 from woshimaliang/master
Browse files Browse the repository at this point in the history
Add **XCFramework** support to PodToBUILD
  • Loading branch information
woshimaliang authored Jun 9, 2022
2 parents cb874da + 3b0e2a0 commit ab41249
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 26 deletions.
7 changes: 7 additions & 0 deletions BazelExtensions/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def _impl(repository_ctx):
_cli_bool(False),
"--is_dynamic_framework",
_cli_bool(repository_ctx.attr.is_dynamic_framework),
"--is_xcframework",
_cli_bool(repository_ctx.attr.is_xcframework),
])
substitutions[INIT_REPO_PLACEHOLDER] = " ".join(entry)
else:
Expand Down Expand Up @@ -212,6 +214,7 @@ pod_repo_ = repository_rule(
"generate_module_map": attr.bool(default=False, mandatory=True),
"header_visibility": attr.string(),
"is_dynamic_framework": attr.bool(default=False, mandatory=False),
"is_xcframework": attr.bool(default=False, mandatory=False),
}
)

Expand All @@ -231,6 +234,7 @@ def new_pod_repository(name,
generate_module_map=None,
header_visibility="pod_support",
is_dynamic_framework=False,
is_xcframework=False,
):
"""Declare a repository for a Pod
Args:
Expand Down Expand Up @@ -295,6 +299,8 @@ def new_pod_repository(name,
https://github.com/bazelbuild/bazel/pull/3712
is_dynamic_framework: set to True if the pod uses prebuilt dynamic framework(s)
is_xcframework: set To True if the the pod uses prebuild xcframework
"""
if generate_module_map == None:
generate_module_map = enable_modules
Expand Down Expand Up @@ -324,4 +330,5 @@ def new_pod_repository(name,
generate_module_map=generate_module_map,
header_visibility=header_visibility,
is_dynamic_framework=is_dynamic_framework,
is_xcframework=is_xcframework,
)
20 changes: 20 additions & 0 deletions Examples/AmazonIVSPlayer/AmazonIVSPlayer.podspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "AmazonIVSPlayer",
"version": "1.8.1",
"summary": "Amazon AWS Interactive Video Service Player",
"homepage": "https://aws.amazon.com/ivs/",
"license": {
"type": "Custom",
"text": "https://player.live-video.net/LICENSE.txt"
},
"authors": "Amazon.com, Inc.",
"social_media_url": "https://twitter.com/awscloud",
"platforms": {
"ios": "10.0"
},
"source": {
"http": "https://player.live-video.net/1.8.1/AmazonIVSPlayer.xcframework.zip",
"type": "zip",
},
"vendored_frameworks": "AmazonIVSPlayer.xcframework"
}
29 changes: 29 additions & 0 deletions Examples/AmazonIVSPlayer/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application")
load("@rules_cc//cc:defs.bzl", "objc_library")

# This is needed for implicit entitlement rules created for
# files.
package(default_visibility = ["//visibility:public"])

ios_application(
name = "ios-app",
bundle_id = "com.lma",
families = ["iphone"],
infoplists = ["Info.plist"],
visibility = ["//visibility:public"],
deps = ["ios-app-bin"],
minimum_os_version = "9.3"
)

objc_library(
name = "ios-app-bin",
srcs = [
"main.m",
],
enable_modules = True,
deps = [
"//Vendor/AmazonIVSPlayer:AmazonIVSPlayer",
],
sdk_frameworks = ["UIKit", "CoreGraphics"]
)

28 changes: 28 additions & 0 deletions Examples/AmazonIVSPlayer/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>ios-app</string>
<key>CFBundleExecutable</key>
<string>ios-app</string>
<key>CFBundleIdentifier</key>
<string>com.lma</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>ios-app</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
</dict>
</plist>
1 change: 1 addition & 0 deletions Examples/AmazonIVSPlayer/Makefile
7 changes: 7 additions & 0 deletions Examples/AmazonIVSPlayer/Pods.WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
new_pod_repository(
name = "AmazonIVSPlayer",
url = "https://player.live-video.net/1.8.1/AmazonIVSPlayer.xcframework.zip",
podspec_url = "AmazonIVSPlayer.podspec.json",
is_dynamic_framework = True, # AmazonIVSPlayer is dynamic XCFramework
is_xcframework = True,
)
43 changes: 43 additions & 0 deletions Examples/AmazonIVSPlayer/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_pods",
urls = ["https://note-this-is-overridden"],
)

load("@rules_pods//BazelExtensions:workspace.bzl", "new_pod_repository")

http_archive(
name = "build_bazel_rules_apple",
sha256 = "12865e5944f09d16364aa78050366aca9dc35a32a018fa35f5950238b08bf744",
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.34.2/rules_apple.0.34.2.tar.gz",
)

load(
"@build_bazel_rules_apple//apple:repositories.bzl",
"apple_rules_dependencies",
)

apple_rules_dependencies()

load(
"@build_bazel_apple_support//lib:repositories.bzl",
"apple_support_dependencies",
)

apple_support_dependencies()

load(
"@build_bazel_rules_swift//swift:repositories.bzl",
"swift_rules_dependencies",
)

swift_rules_dependencies()


load(
"@build_bazel_rules_swift//swift:extras.bzl",
"swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()
9 changes: 9 additions & 0 deletions Examples/AmazonIVSPlayer/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#import <AmazonIVSPlayer/AmazonIVSPlayer.h>

int main(int argc, char * argv[]) {

IVSPlayer *obj = [[IVSPlayer alloc] init];
NSLog(@"%@", obj);

return 0;
}
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ build-test: pod_test build archive init-sandbox
cd Examples/React && make all
cd Examples/SwiftSubspec && make all
cd Examples/FBSDK && make all
cd Examples/SnapSDK && make all
cd Examples/AmazonIVSPlayer && make all

build-example: EXAMPLE=Examples/PINCache.podspec.json
build-example: CONFIG = debug
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ there is no need to add an entry for them.

`header_visibility`: DEPRECATED: This is replaced by headermaps: https://github.com/Bazelbuild/Bazel/pull/3712

`is_dynamic_framework`: set to True if the pod uses prebuilt dynamic framework(s)
`is_dynamic_framework`: set to True if the pod uses prebuilt dynamic framework(s)

`is_xcframework`: set to True if the pod uses prebuilt xcframework

### Known Complications

Expand Down Expand Up @@ -372,4 +374,3 @@ swift package generate-xcodeproj
```

PRs welcome :)!

5 changes: 2 additions & 3 deletions Sources/PodToBUILD/BuildFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ public func makeLoadNodes(forConvertibles skylarkConvertibles: [SkylarkConvertib
let hasAppleBundleImport = skylarkConvertibles.first(where: { $0 is AppleBundleImport }) != nil
let hasAppleResourceBundle = skylarkConvertibles.first(where: { $0 is AppleResourceBundle }) != nil
let hasAppleFrameworkImport = skylarkConvertibles.first(where: { $0 is AppleFrameworkImport }) != nil
let isDynamicFramework = GetBuildOptions().isDynamicFramework
let appleFrameworkImport = appleFrameworkImport(isDynamicFramework: GetBuildOptions().isDynamicFramework, isXCFramework: GetBuildOptions().isXCFramework)

return .lines( [
hasSwift ? SkylarkNode.skylark("load('@build_bazel_rules_swift//swift:swift.bzl', 'swift_library')") : nil,
hasAppleBundleImport ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_bundle_import')") : nil,
hasAppleResourceBundle ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:resources.bzl', 'apple_resource_bundle')") : nil,
hasAppleFrameworkImport && isDynamicFramework ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:apple.bzl', 'apple_dynamic_framework_import')") : nil,
hasAppleFrameworkImport && !isDynamicFramework ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:apple.bzl', 'apple_static_framework_import')") : nil,
hasAppleFrameworkImport ? SkylarkNode.skylark("load('@build_bazel_rules_apple//apple:apple.bzl', '\(appleFrameworkImport)')") : nil,
].compactMap { $0 }
)
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/PodToBUILD/BuildOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public protocol BuildOptions {
var vendorize: Bool { get }
var childPaths: [String] { get }
var isDynamicFramework: Bool { get }
var isXCFramework: Bool { get }
}

public struct BasicBuildOptions: BuildOptions {
Expand All @@ -42,6 +43,7 @@ public struct BasicBuildOptions: BuildOptions {
public let vendorize: Bool
public let childPaths: [String]
public let isDynamicFramework: Bool
public let isXCFramework: Bool

public init(podName: String = "",
path: String = ".",
Expand All @@ -55,7 +57,8 @@ public struct BasicBuildOptions: BuildOptions {
alwaysSplitRules: Bool = true,
vendorize: Bool = true,
childPaths: [String] = [],
isDynamicFramework: Bool = false
isDynamicFramework: Bool = false,
isXCFramework: Bool = false
) {
self.podName = podName
self.path = path
Expand All @@ -70,6 +73,7 @@ public struct BasicBuildOptions: BuildOptions {
self.vendorize = vendorize
self.childPaths = childPaths
self.isDynamicFramework = isDynamicFramework
self.isXCFramework = isXCFramework
}

public static let empty = BasicBuildOptions(podName: "")
Expand Down
9 changes: 5 additions & 4 deletions Sources/PodToBUILD/ObjcLibrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,14 @@ public struct AppleFrameworkImport: BazelTarget {
// visibility = ["visibility:public"]
// )
public func toSkylark() -> SkylarkNode {
let isDynamicFramework = GetBuildOptions().isDynamicFramework

let isXCFramework = GetBuildOptions().isXCFramework
let appleFrameworkImport = appleFrameworkImport(isDynamicFramework: GetBuildOptions().isDynamicFramework, isXCFramework: isXCFramework)

return SkylarkNode.functionCall(
name: isDynamicFramework ? "apple_dynamic_framework_import" : "apple_static_framework_import",
name: appleFrameworkImport,
arguments: [SkylarkFunctionArgument]([
.named(name: "name", value: .string(name)),
.named(name: "framework_imports",
.named(name: isXCFramework ? "xcframework_imports": "framework_imports",
value: frameworkImports.map {
GlobNode(include: Set($0.map { $0 + "/**" }))
}.toSkylark()),
Expand Down
9 changes: 9 additions & 0 deletions Sources/PodToBUILD/RuleUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,12 @@ public func bazelLabel(fromString string: String) -> String {
}


/// framework import for apple framework import
/// - Parameters:
/// - isDynamicFramework: whether internal framework is dynamic or static
/// - isXCFramework: if it is XCFramework
/// - Returns: apple framework import string such as "apple_static_xcframework_import"
public func appleFrameworkImport(isDynamicFramework: Bool, isXCFramework: Bool) -> String {
return "apple_" + (isDynamicFramework ? "dynamic_" : "static_") + (isXCFramework ? "xcframework_" : "framework_") + "import"
}

6 changes: 4 additions & 2 deletions Sources/RepoToolsCore/RepoActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public enum SerializedRepoToolsAction {
static func tryParseInit(args: [String]) -> BasicBuildOptions {
// First arg is the path, we don't care about it
// The right most option will be the winner.
var options: [String: CLIArgumentType] = [
let options: [String: CLIArgumentType] = [
"--path": .string,
"--user_option": .stringList,
"--global_copt": .string,
Expand All @@ -107,6 +107,7 @@ public enum SerializedRepoToolsAction {
"--header_visibility": .string,
"--child_path": .stringList,
"--is_dynamic_framework": .bool,
"--is_xcframework": .bool,
]

var idx = 0
Expand Down Expand Up @@ -166,7 +167,8 @@ public enum SerializedRepoToolsAction {
alwaysSplitRules: false,
vendorize: parsed["--vendorize"]?.first as? Bool ?? true,
childPaths: parsed["--child_path"] as? [String] ?? [],
isDynamicFramework: parsed["--is_dynamic_framework"]?.first as? Bool ?? false
isDynamicFramework: parsed["--is_dynamic_framework"]?.first as? Bool ?? false,
isXCFramework: parsed["--is_xcframework"]?.first as? Bool ?? false
)
}
}
Expand Down
15 changes: 4 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "build_bazel_rules_apple",
sha256 = "77e8bf6fda706f420a55874ae6ee4df0c9d95da6c7838228b26910fc82eea5a2",
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.32.0/rules_apple.0.32.0.tar.gz",
sha256 = "12865e5944f09d16364aa78050366aca9dc35a32a018fa35f5950238b08bf744",
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.34.2/rules_apple.0.34.2.tar.gz",
)

http_archive(
name = "build_bazel_rules_swift",
url = "https://github.com/bazelbuild/rules_swift/releases/download/0.24.0/rules_swift.0.24.0.tar.gz",
sha256 = "4f167e5dbb49b082c5b7f49ee688630d69fb96f15c84c448faa2e97a5780dbbc",
url = "https://github.com/bazelbuild/rules_swift/releases/download/0.27.0/rules_swift.0.27.0.tar.gz",
sha256 = "a2fd565e527f83fb3f9eb07eb9737240e668c9242d3bc318712efa54a7deda97",
)

load(
Expand All @@ -33,13 +33,6 @@ load(

swift_rules_extra_dependencies()

load(
"@com_google_protobuf//:protobuf_deps.bzl",
"protobuf_deps",
)

protobuf_deps()

load("//third_party:repositories.bzl", "podtobuild_dependencies")

podtobuild_dependencies()
Loading

0 comments on commit ab41249

Please sign in to comment.