rules_swift
rules_swift copied to clipboard
Documentation to use bridging headers
Hi, I'm trying to build a fairly complex app, which has a mix of Swift and Objective-C.
The Swift code relies heavily on a bridging header, which itself imports a number of headers. Here's a snippet of App-Bridging-Header.h:
#import "Constants.h"
#import "CJAMacros.h"
... (many more headers)
Each of the imported headers lives in a different directory. Xcode makes that work (I'm not sure how), but I'm not sure how to do this with Bazel.
How can this header, and all its dependencies, be declared with Bazel? How can they be used from a swift_library target?
Thank you 🙃
same for me
I wasn't able to find official documentation that covers this, but this is what I've found that works:
- Set the
module_nameon yourobjc_librarytargets (or rely on the default value as described in theobjc_librarydocumentation) - List the
objc_librarytargets asdepsof yourswift_library - Use
import [obj_module_name]in your.swiftcode
For example:
objc_library(
name = "foo_lib",
srcs = ["Bar.m"],
hdrs = ["Bar.h"],
module_name = "FooLib",
)
swift_library(
name = "baz_lib",
srcs = ["Baz.swift"],
deps = [":foo_lib"],
)
// Baz.swift
import FooLib
let bar = Bar()