Skip to content

Commit

Permalink
bazel: Update swift_static_framework to use swiftinterfaces (#815)
Browse files Browse the repository at this point in the history
Signed-off-by: JP Simard <jp@jpsim.com>
  • Loading branch information
keith authored and jpsim committed Nov 29, 2022
1 parent f0c1272 commit 5863510
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 20 deletions.
30 changes: 16 additions & 14 deletions mobile/bazel/swift_static_framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ static_framework_import

load("@build_bazel_apple_support//lib:apple_support.bzl", "apple_support")
load("@build_bazel_rules_swift//swift:swift.bzl", "SwiftInfo", "swift_library")
load("@build_bazel_rules_apple//apple/internal:transition_support.bzl", "transition_support")

MINIMUM_IOS_VERSION = "10.0"

Expand Down Expand Up @@ -66,6 +67,10 @@ def _swift_static_framework_impl(ctx):

swiftdoc = swift_info.direct_swiftdocs[0]
swiftmodule = swift_info.direct_swiftmodules[0]
swiftinterfaces = swift_info.transitive_swiftinterfaces.to_list()
if len(swiftinterfaces) != 1:
fail("Expected a single swiftinterface file, got: {}".format(swiftinterfaces))
swiftinterface = swiftinterfaces[0]

libraries = archive[CcInfo].linking_context.libraries_to_link
archives = []
Expand All @@ -91,10 +96,11 @@ def _swift_static_framework_impl(ctx):

input_archives.append(platform_archive)

input_modules_docs += [swiftdoc, swiftmodule]
input_modules_docs += [swiftdoc, swiftmodule, swiftinterface]
zip_args += [
_zip_swift_arg(module_name, swiftmodule_identifier, swiftdoc),
_zip_swift_arg(module_name, swiftmodule_identifier, swiftmodule),
_zip_swift_arg(module_name, swiftmodule_identifier, swiftinterface),
]

ctx.actions.run(
Expand Down Expand Up @@ -130,6 +136,9 @@ _swift_static_framework = rule(
cfg = "host",
executable = True,
),
_whitelist_function_transition = attr.label(
default = "@build_bazel_rules_apple//tools/whitelists/function_transition_whitelist",
),
_zipper = attr.label(
default = "@bazel_tools//tools/zip:zipper",
cfg = "host",
Expand All @@ -149,6 +158,7 @@ _swift_static_framework = rule(
default = str(apple_common.platform_type.ios),
),
),
cfg = transition_support.static_framework_transition,
fragments = [
"apple",
],
Expand All @@ -163,37 +173,29 @@ def swift_static_framework(
name,
module_name = None,
srcs = [],
deps = [],
objc_includes = [],
private_deps = [],
copts = [],
swiftc_inputs = [],
visibility = []):
"""Create a static library, and static framework target for a swift module
Args:
name: The name of the module, the framework's name will be this name
appending Framework so you can depend on this from other modules
srcs: Custom source paths for the swift files
objc_includes: Header files for any objective-c dependencies (required for linking)
copts: Any custom swiftc opts passed through to the swift_library
swiftc_inputs: Any labels that require expansion for copts (would also apply to linkopts)
deps: Any deps the swift_library requires
private_deps: Any deps the swift_library requires. They must be imported
with @_implementationOnly and not exposed publicly.
"""
archive_name = name + "_archive"
module_name = module_name or name + "_framework"
if objc_includes:
locations = ["$(location {})".format(x) for x in objc_includes]
copts = copts + ["-import-objc-header"] + locations
swiftc_inputs = swiftc_inputs + objc_includes

swift_library(
name = archive_name,
srcs = srcs,
copts = copts,
swiftc_inputs = swiftc_inputs,
module_name = module_name,
private_deps = private_deps,
visibility = ["//visibility:public"],
deps = deps,
features = ["swift.enable_library_evolution"],
)

_swift_static_framework(
Expand Down
4 changes: 2 additions & 2 deletions mobile/bazel/swift_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
# ],
# )
#
def envoy_mobile_swift_test(name, srcs):
def envoy_mobile_swift_test(name, srcs, deps = []):
test_lib_name = name + "_lib"
swift_library(
name = test_lib_name,
srcs = srcs,
deps = [
"//library/swift/src:ios_framework_archive",
],
] + deps,
linkopts = ["-lresolv.9"],
visibility = ["//visibility:private"],
)
Expand Down
1 change: 1 addition & 0 deletions mobile/library/objective-c/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ objc_library(
hdrs = [
"EnvoyEngine.h",
],
module_name = "EnvoyEngine",
sdk_frameworks = [
"SystemConfiguration",
"UIKit",
Expand Down
5 changes: 1 addition & 4 deletions mobile/library/swift/src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ swift_static_framework(
"grpc/*.swift",
]),
module_name = "Envoy",
objc_includes = [
"//library/objective-c:EnvoyEngine.h",
],
private_deps = ["//library/objective-c:envoy_engine_objc_lib"],
visibility = ["//visibility:public"],
deps = ["//library/objective-c:envoy_engine_objc_lib"],
)
1 change: 1 addition & 0 deletions mobile/library/swift/src/EnvoyClient.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@_implementationOnly import EnvoyEngine
import Foundation

/// Envoy's implementation of `HTTPClient`, buildable using `EnvoyClientBuilder`.
Expand Down
1 change: 1 addition & 0 deletions mobile/library/swift/src/EnvoyClientBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@_implementationOnly import EnvoyEngine
import Foundation

/// Builder used for creating new instances of EnvoyClient.
Expand Down
1 change: 1 addition & 0 deletions mobile/library/swift/src/EnvoyStreamEmitter.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@_implementationOnly import EnvoyEngine
import Foundation

/// Default implementation of the `StreamEmitter` interface.
Expand Down
1 change: 1 addition & 0 deletions mobile/library/swift/src/ResponseHandler.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@_implementationOnly import EnvoyEngine
import Foundation

/// Callback interface for receiving stream events.
Expand Down
9 changes: 9 additions & 0 deletions mobile/library/swift/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ envoy_mobile_swift_test(
"MockEnvoyEngine.swift",
"MockEnvoyHTTPStream.swift",
],
deps = [
"//library/objective-c:envoy_engine_objc_lib",
],
)

envoy_mobile_swift_test(
Expand All @@ -18,6 +21,9 @@ envoy_mobile_swift_test(
"MockEnvoyEngine.swift",
"MockEnvoyHTTPStream.swift",
],
deps = [
"//library/objective-c:envoy_engine_objc_lib",
],
)

envoy_mobile_swift_test(
Expand All @@ -32,6 +38,9 @@ envoy_mobile_swift_test(
srcs = [
"GRPCResponseHandlerTests.swift",
],
deps = [
"//library/objective-c:envoy_engine_objc_lib",
],
)

envoy_mobile_swift_test(
Expand Down
1 change: 1 addition & 0 deletions mobile/library/swift/test/EnvoyClientBuilderTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import Envoy
import EnvoyEngine
import Foundation
import XCTest

Expand Down
1 change: 1 addition & 0 deletions mobile/library/swift/test/GRPCResponseHandlerTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import Envoy
import EnvoyEngine
import Foundation
import XCTest

Expand Down
1 change: 1 addition & 0 deletions mobile/library/swift/test/MockEnvoyEngine.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import Envoy
import EnvoyEngine
import Foundation

final class MockEnvoyEngine: NSObject {
Expand Down
1 change: 1 addition & 0 deletions mobile/library/swift/test/MockEnvoyHTTPStream.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Envoy
import EnvoyEngine
import Foundation

final class MockEnvoyHTTPStream {
Expand Down

0 comments on commit 5863510

Please sign in to comment.