Skip to content

Conversation

@ktoso
Copy link
Collaborator

@ktoso ktoso commented Oct 30, 2024

🚧 early work in progress 🚧

This is first steps to make an jextract-swift plugin.

If we're able to pull this off as a swiftpm plugin we would basically have a way to "make me a jar that exposes this swift module, that would be super simple to consume from Java.

Need to figure out how to actually make this work -- it can't be a build plugin, but preBuild also isn't quite enough.

We may have to make it a command plugin, since we need compilation OUTPUT of the module to then act on the swift interfaces.

arguments.append(sourceDir)

return [
.prebuildCommand(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can't work, since we need this to act on swiftinterface files of the module it's acting on. It has to be a "post build" plugin really.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: make this into a command plugin people would have to invoke manually swift package jextract which would generate the bindings.

We could also then swift package jextract jar to produce a jar or even publish it etc.

@ktoso ktoso marked this pull request as draft October 30, 2024 09:37
@ktoso
Copy link
Collaborator Author

ktoso commented Nov 1, 2024

Before weekend snapshot:

  • we now generate swift thunks (!)
  • first thunk is to "give me the Any.Type of this type" rather than using swift interfaces
    • these are done via public func swiftjava_getType_JExtractPluginSampleLib_MyCoolSwiftClass() -> Any /* Any.Type */ generated thunks
  • jextract is now a prebuild plugin so we can get seamless build integration

Screenshot 2024-11-01 at 19 16 14

Basically this means you "just" write some swift sources, add the extract plugin to the given target. Add a small task in gradle to trigger swiftpm and this way gradle/java immediately see the wrappers. Upon changing swift -> gradle triggers swift build again and it's all very seamless 🥳

@ktoso ktoso force-pushed the wip-jextract-plugin branch from cd1a2b4 to 354ea56 Compare November 6, 2024 02:49
@ktoso ktoso closed this Nov 9, 2024
@ktoso ktoso deleted the wip-jextract-plugin branch November 9, 2024 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant