Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only generates Swift interface for mixed source #5

Open
tjprescott opened this issue Aug 23, 2021 · 7 comments
Open

Only generates Swift interface for mixed source #5

tjprescott opened this issue Aug 23, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@tjprescott
Copy link

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)?

@minuscorp
Copy link
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.

@minuscorp minuscorp added the enhancement New feature or request label Aug 23, 2021
@tjprescott
Copy link
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.

@minuscorp
Copy link
Owner

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

@tjprescott
Copy link
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

@4brunu
Copy link

4brunu commented Aug 24, 2021

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

@tjprescott tjprescott reopened this Aug 24, 2021
@tjprescott
Copy link
Author

I agree :)

@minuscorp
Copy link
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
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants