Coder Social home page Coder Social logo

Comments (3)

chronal-xnor avatar chronal-xnor commented on July 20, 2024

A different solution for this problem:

  1. Create a swift_library target that depends on your swift_c_module target.
  2. Have the swift_c_module target's module.map declare the same module name as the swift_library's module_name
  3. Pass the copts = ["-import-underlying-module"] attribute to the swift_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.

chronal-xnor avatar chronal-xnor commented on July 20, 2024

This is the hack mentioned in https://github.com/bazelbuild/rules_swift/blob/master/swift/internal/api.bzl#L765

from rules_swift.

allevato avatar allevato commented on July 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.