Comments (3)
A different solution for this problem:
- Create a
swift_library
target that depends on yourswift_c_module
target. - Have the
swift_c_module
target's module.map declare the same module name as theswift_library
'smodule_name
- Pass the
copts = ["-import-underlying-module"]
attribute to theswift_library
to tell the compiler to look for a C/obj-c module with the same name
Then the C and Swift stuff both end up in the same module, and there's nothing extra to import.
This feels a little janky and rules_swift should probably do this implicitly. Either way, I feel that having a story about how C dependencies are handled is an important step towards allowing frameworks to be built with swift built under Bazel.
from rules_swift.
This is the hack mentioned in https://github.com/bazelbuild/rules_swift/blob/master/swift/internal/api.bzl#L765
from rules_swift.
Frameworks are a bit of a special case in Apple land, especially w.r.t. how they interact with modules. Frameworks really only support a single module due to the search/load logic used by the compiler (they assume that the .framework
name and the .swiftmodule
name match, and won't look for modules of different names inside that bundle. So the solution in your earlier comment of using -import-underlying-module
is really the only way to make that work.
Even if we exclude Objective-C and Apple platforms from the equation, there are situations where it's handy to have C code in the same module as Swift code (the Swift core libraries do this in a handful of places), but it's also rare enough that it hasn't been a high priority to figure out how to handle it generally when the hack above gets most of the way there, and when rules_apple is planning on handling the case there (where it is more common, especially due to the framework issue).
Since rules_apple is going to handle the common case, I'm going to close out this issueโI'll suggest following the issue over there to get a solution that handles your use case.
from rules_swift.
Related Issues (20)
- Integrating 3rd party framework with Bazel to iOS project HOT 21
- `private_deps` may lost `data` fields which could cause an unexpected resource lost HOT 3
- Multiple swift_library transitions results in duplicate linkopts HOT 11
- rules_swift is failing with Bazel@HEAD in CI HOT 7
- --incompatible_enable_cc_toolchain_resolution + universal tools fails to build HOT 17
- Compiling Sources/CNIOBoringSSL/ssl/tls_method.cc failed in rules_swift 1.11.0 HOT 5
- Error in fail: Compiling objc_library targets requires the Apple CC toolchain HOT 13
- Error index out of range for rules_swift with Bazel@HEAD HOT 6
- Swift Macro Test - build issue - when it depends on the universal plugin HOT 1
- Bug: Incremental compilation cache poisoning HOT 1
- It is not possible to use `@testable` when `compilation_mode=opt` HOT 3
- On Xcode 15, binaries depending on swift_proto_library fail to link with error: duplicate -rpath '/usr/lib/swift' HOT 6
- How to build shared libraries using rule_swift (.so)? HOT 6
- Error in new_objc_provider: Key 'linkopt' no longer supported in ObjcProvider HOT 1
- Error: There is no configuration fragment named 'swift'. Available fragments: 'platform', 'coverage', 'bazel_py', 'android', 'bazel_android', 'apple', 'cpp', 'java', 'j2objc', 'objc', 'proto', 'py' HOT 1
- Duplicate symbol error when migrating to bzlmod HOT 4
- Error adding "apple_core_data_model" dependency to "swift_library" HOT 10
- CC_Library without a tag does not generate a ModuleMap HOT 6
- 'apple_cc_toolchain' is not defined in CI at Bazel@HEAD HOT 1
- Swift Macro - cc_wrapper.sh failed: error executing CppLink command HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rules_swift.