diff --git a/mobile/bazel/swift_static_framework.bzl b/mobile/bazel/swift_static_framework.bzl index 6f881457c3db..ed79cf0d31c5 100644 --- a/mobile/bazel/swift_static_framework.bzl +++ b/mobile/bazel/swift_static_framework.bzl @@ -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" @@ -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 = [] @@ -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( @@ -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", @@ -149,6 +158,7 @@ _swift_static_framework = rule( default = str(apple_common.platform_type.ios), ), ), + cfg = transition_support.static_framework_transition, fragments = [ "apple", ], @@ -163,10 +173,8 @@ 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 @@ -174,26 +182,20 @@ def swift_static_framework( 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( diff --git a/mobile/bazel/swift_test.bzl b/mobile/bazel/swift_test.bzl index 9eb9bb37859b..9cb3a383da5b 100644 --- a/mobile/bazel/swift_test.bzl +++ b/mobile/bazel/swift_test.bzl @@ -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"], ) diff --git a/mobile/library/objective-c/BUILD b/mobile/library/objective-c/BUILD index 526e89d23b0f..ee134136740b 100644 --- a/mobile/library/objective-c/BUILD +++ b/mobile/library/objective-c/BUILD @@ -16,6 +16,7 @@ objc_library( hdrs = [ "EnvoyEngine.h", ], + module_name = "EnvoyEngine", sdk_frameworks = [ "SystemConfiguration", "UIKit", diff --git a/mobile/library/swift/src/BUILD b/mobile/library/swift/src/BUILD index 20fb85c42609..026fd3c8a3b2 100644 --- a/mobile/library/swift/src/BUILD +++ b/mobile/library/swift/src/BUILD @@ -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"], ) diff --git a/mobile/library/swift/src/EnvoyClient.swift b/mobile/library/swift/src/EnvoyClient.swift index e71350b9b1ee..faa142a62b9b 100644 --- a/mobile/library/swift/src/EnvoyClient.swift +++ b/mobile/library/swift/src/EnvoyClient.swift @@ -1,3 +1,4 @@ +@_implementationOnly import EnvoyEngine import Foundation /// Envoy's implementation of `HTTPClient`, buildable using `EnvoyClientBuilder`. diff --git a/mobile/library/swift/src/EnvoyClientBuilder.swift b/mobile/library/swift/src/EnvoyClientBuilder.swift index 13b770d131fc..662f28624816 100644 --- a/mobile/library/swift/src/EnvoyClientBuilder.swift +++ b/mobile/library/swift/src/EnvoyClientBuilder.swift @@ -1,3 +1,4 @@ +@_implementationOnly import EnvoyEngine import Foundation /// Builder used for creating new instances of EnvoyClient. diff --git a/mobile/library/swift/src/EnvoyStreamEmitter.swift b/mobile/library/swift/src/EnvoyStreamEmitter.swift index e3c5f8b87da1..938e07b9f1c8 100644 --- a/mobile/library/swift/src/EnvoyStreamEmitter.swift +++ b/mobile/library/swift/src/EnvoyStreamEmitter.swift @@ -1,3 +1,4 @@ +@_implementationOnly import EnvoyEngine import Foundation /// Default implementation of the `StreamEmitter` interface. diff --git a/mobile/library/swift/src/ResponseHandler.swift b/mobile/library/swift/src/ResponseHandler.swift index 575e57dfc99a..ea1176d49453 100644 --- a/mobile/library/swift/src/ResponseHandler.swift +++ b/mobile/library/swift/src/ResponseHandler.swift @@ -1,3 +1,4 @@ +@_implementationOnly import EnvoyEngine import Foundation /// Callback interface for receiving stream events. diff --git a/mobile/library/swift/test/BUILD b/mobile/library/swift/test/BUILD index 7cd98e39f561..90b50a756e77 100644 --- a/mobile/library/swift/test/BUILD +++ b/mobile/library/swift/test/BUILD @@ -9,6 +9,9 @@ envoy_mobile_swift_test( "MockEnvoyEngine.swift", "MockEnvoyHTTPStream.swift", ], + deps = [ + "//library/objective-c:envoy_engine_objc_lib", + ], ) envoy_mobile_swift_test( @@ -18,6 +21,9 @@ envoy_mobile_swift_test( "MockEnvoyEngine.swift", "MockEnvoyHTTPStream.swift", ], + deps = [ + "//library/objective-c:envoy_engine_objc_lib", + ], ) envoy_mobile_swift_test( @@ -32,6 +38,9 @@ envoy_mobile_swift_test( srcs = [ "GRPCResponseHandlerTests.swift", ], + deps = [ + "//library/objective-c:envoy_engine_objc_lib", + ], ) envoy_mobile_swift_test( diff --git a/mobile/library/swift/test/EnvoyClientBuilderTests.swift b/mobile/library/swift/test/EnvoyClientBuilderTests.swift index 01e43f932927..c1cc36c232bc 100644 --- a/mobile/library/swift/test/EnvoyClientBuilderTests.swift +++ b/mobile/library/swift/test/EnvoyClientBuilderTests.swift @@ -1,4 +1,5 @@ @testable import Envoy +import EnvoyEngine import Foundation import XCTest diff --git a/mobile/library/swift/test/GRPCResponseHandlerTests.swift b/mobile/library/swift/test/GRPCResponseHandlerTests.swift index 8d4e7d64e694..7bc4e287168e 100644 --- a/mobile/library/swift/test/GRPCResponseHandlerTests.swift +++ b/mobile/library/swift/test/GRPCResponseHandlerTests.swift @@ -1,4 +1,5 @@ @testable import Envoy +import EnvoyEngine import Foundation import XCTest diff --git a/mobile/library/swift/test/MockEnvoyEngine.swift b/mobile/library/swift/test/MockEnvoyEngine.swift index 778c88aacac4..5af0ecb8f4bb 100644 --- a/mobile/library/swift/test/MockEnvoyEngine.swift +++ b/mobile/library/swift/test/MockEnvoyEngine.swift @@ -1,4 +1,5 @@ @testable import Envoy +import EnvoyEngine import Foundation final class MockEnvoyEngine: NSObject { diff --git a/mobile/library/swift/test/MockEnvoyHTTPStream.swift b/mobile/library/swift/test/MockEnvoyHTTPStream.swift index d38dce2041c5..384011589f00 100644 --- a/mobile/library/swift/test/MockEnvoyHTTPStream.swift +++ b/mobile/library/swift/test/MockEnvoyHTTPStream.swift @@ -1,4 +1,5 @@ import Envoy +import EnvoyEngine import Foundation final class MockEnvoyHTTPStream {