Skip to content

Only generates Swift interface for mixed source #5

Open

Description

@tjprescott

We have internal tooling that publishes Swift interfaces for comment and review. For Swift-only frameworks our tooling works fine simply getting the abstract syntax tree of the Swift source code. However, this approach doesn't work when the source contains, or is primarily, Objective-C.

We have an alternate process that will process *.swiftinterface files, but we have yet to find a process that works for generating these files from Objective-C or mixed source except for using the internal Xcode Generated interface. We are searching for a programmatic solution.

Based on comments here (jpsim/SourceKitten#405) I was hoping that this tool might solve our issue. However, when I run it on a simple dummy framework, which contains a SwiftClass object and an ObjCClass object, the generated interface only includes the SwiftClass interface even though the bridged ObjCClass is exposed.

Is ModuleInterface intended to work with mixed source, or is it strictly for Swift-only frameworks (or the Swift-only portion of mixed frameworks)?

Activity

  1. minuscorp commented on Aug 23, 2021

    @minuscorp
    Owner

    It was designed for Swift interfaces, as I didn't thought of the objc use case. I'd need to capture which request does SourceKit launch in order to create the Objc interface object, as I don't use the *.swiftinterface file to generate the module.

  2. tjprescott commented on Aug 23, 2021

    @tjprescott
    Author

    The generated module follows the *.swiftinterface format, but I found a way to get these from SourceKitten.

    import SourceKittenFramework
    
    if sourceUrl.absoluteString.hasSuffix("h") {
      let args = [String]()
      let generated = try Request.interface(file: sourceUrl.absoluteString, uuid: NSUUID().uuidString, arguments: args).send()
      if let match = generated.first(where: { key, _ in
        return key == "key.sourcetext"
    }) {
        let sourceCode = match.value as! String
        // do whatever with the swiftinterface code
    }

    Since this is not a use case for ModuleInterface, I'll close this issue.

  3. minuscorp commented on Aug 23, 2021

    @minuscorp
    Owner

    With this snippet I could add support for both kind of sources as an enhancement.

  4. tjprescott commented on Aug 23, 2021

    @tjprescott
    Author

    I think it would be a worthy enhancement. In our case, we process Swift source file-by-file and generate a final artifact. Using SourceKitten we can process *.h files individually, convert them to Swift interface (which we then have to process since Swift interface != swift source code) and it all works out. It might be tricky depending on how you combine things.

    Our finalized, combined representation looks like (for our demo package)

    image

  5. 4brunu commented on Aug 24, 2021

    @4brunu

    I think this would be a nice improvement to this library 👍

  6. tjprescott commented on Aug 24, 2021

    @tjprescott
    Author

    I agree :)

  7. minuscorp commented on Aug 24, 2021

    @minuscorp
    Owner

    PRs are welcome if you want to help with this!🤩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions