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

SwiftPM build plugin for producing Swift wrapper types for Java classes (Java2Swift direction) #16

Closed
DougGregor opened this issue Sep 30, 2024 · 2 comments

Comments

@DougGregor
Copy link
Member

The "Java2Swift" tool produces Swift wrapper types (using JavaKit) for Java classes. It's provided as a standalone executable that takes in an input module, some translation manifests, and either a Jar file or a list of class names, and produces Swift source files.

We should create a SwiftPM build plugin that runs the tool for us. For example, it should make it easy to declare a SwiftPM target and fill in some of the source files via the generator. For example, the JavaKitJar module is fully generated, but with a Makefile.

DougGregor added a commit to DougGregor/swift-java that referenced this issue Oct 15, 2024
Introduce the plugin `Java2SwiftPlugin`, which will invoke Java2Swift to
generate Swift wrappers for the specified Java classes. Each SwiftPM
target that uses this plugin must contain a file named `Java2Swift.config`
that specifies options for the Java2Swift tool. This is a JSON file
with a top-level dictionary that currently can contain keys for the
Java class path (`classPath`) and a dictionary called `classes` whose
keys are Java canonical class names (such as `java.util.Vector`) and
whose values are the corresponding Swift names. For example:

```swift
{
  "classes" : {
    "java.util.Vector" : "JavaVector"
  }
}

```

will translate the class `java.util.Vector` into the Swift type `JavaVector`.
The resulting Swift files will become part of the Swift module that uses
this plugin.

I've updated the JavaKitSampleApp to make use of this, albeit in a very
narrow way that is not at all compelling. The user guide also needs updating.

Fixes issue swiftlang#16
@DougGregor
Copy link
Member Author

This was mostly implemented in PR #77 , but we need to make sure that we're picking up the manifest files generated from other targets we depend on. Right now, we only get the manifest files if they are in the "pre-baked" location generated/<modulename>.swift2java.

@DougGregor
Copy link
Member Author

Done and documented

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

No branches or pull requests

2 participants