AI prompts
base on Java interopability support for Swift # Swift Java Interoperability Tools and Libraries
This repository contains two approaches to Swift/Java interoperability.
- A Swift library (`JavaKit`) and bindings generator that allows a Swift program to make use of Java libraries by wrapping Java classes in corresponding Swift types, allowing Swift to directly call any wrapped Java API.
- The `jextract-swift` tool which is similar to the JDK's `jextract` which allows to extract Java sources which are used
to efficiently call into Swift _from Java_.
## :construction: :construction: :construction: Early Development :construction: :construction: :construction:
**:construction: :construction: :construction: This is a *very early* prototype and everything is subject to change. :construction: :construction: :construction:**
Parts of this project are incomplete, not fleshed out, and subject to change without any notice.
The primary purpose of this repository is to create an environment for collaboration and joint exploration of the Swift/Java interoperability story. The project will transition to a more structured approach once key goals have been outlined.
## Dependencies
### Required Swift Development Toolchains
To build and use this project, currently, you will need to download a custom toolchain which includes some improvements in Swift that this project relies on:
**Required toolchain download:**
Currently this project supports Swift `6.0.x` and we are working on supporting later releases.
You can use Swiftly ([macOS](https://www.swift.org/install/macos/swiftly/) / [linux](https://www.swift.org/install/linux/swiftly/)) the Swift toolchain installer to install the necessary Swift versions.
### Required JDK versions
This project consists of different modules which have different Swift and Java runtime requirements.
**JavaKit** – the Swift macros allowing the invocation of Java libraries from Swift
- **JDK 17+**, any recent JDK installation should be sufficient, as only general reflection and JNI APIs are used by this integration
- **Swift 6.0.x**, because the library uses modern Swift macros
**jextract-swift** – the source generator that ingests .swiftinterface files and makes them available to be called from generated Java sources
- **Swift 6.0.x development snapshots**, because of dependence on rich swift interface files
- **JDK 22+** because of dependence on [JEP-454: Foreign Function & Memory API](https://openjdk.org/jeps/454)
- We are validating the implementation using the currently supported non-LTE release, which at present means JDK-23.
The extract tool may become able to generate legacy compatible sources, which would not require JEP-454 and would instead rely on existing JNI facilities. Currently though, efforts are focused on the forward-looking implementation using modern foreign function and memory APIs.
Support for more recent Swift versions will be provided, for now please stick to 6.0 while evaluating this early version of swift-java.
## Development and Testing
This project contains multiple builds, living side by side together.
Depending on which part you are developing, you may want to run just the swift tests:
```bash
> swift test
```
or the Java tests through the Gradle build. The Gradle build may also trigger some Swift compilation because of
interlinked dependencies of the two parts of Swift-Java. To run the Java build and tests use the Gradle wrapper script:
```bash
> ./gradlew test
```
Currently it is suggested to use Swift 6.0 and a Java 24+.
### Sample Apps
Sample apps are located in the `Samples/` directory, and they showcase full "roundtrip" usage of the library and/or tools.
#### JavaKit (Swift -> Java)
To run a simple app showcasing a Swift process calling into a Java library you can run:
```bash
cd Samples/JavaKitSampleApp
./ci-validate.sh # which is just `swift build` and a `java -cp ...` invocation of the compiled program
```
#### jextract (Java -> Swift)
To run a simple example app showcasing the jextract (Java calling Swift) approach you can:
```bash
./gradlew Samples:SwiftKitSampleApp:run
```
This will also generate the necessary sources (by invoking jextract, extracting the `Sources/ExampleSwiftLibrary`)
and generating Java sources in `src/generated/java`.
## Benchmarks
You can run Swift [ordo-one/package-benchmark](https://github.com/ordo-one/package-benchmark) and OpenJDK [JMH](https://github.com/openjdk/jmh) benchmarks in this project.
Swift benchmarks are located under `Benchmarks/` and JMH benchmarks are currently part of the SwiftKit sample project: `Samples/SwiftKitSampleApp/src/jmh` because they depend on generated sources from the sample.
To run **Swift benchmarks** you can:
```bash
cd Benchmarks
swift package benchmark
```
In order to run JMH benchmarks you can:
```bash
cd Samples/SwiftKitSampleApp
gradle jmh
```
Please read documentation of both performance testing tools and understand that results must be interpreted and not just taken at face value. Benchmarking is tricky and environment sensitive task, so please be careful when constructing and reading benchmarks and their results. If in doubt, please reach out on the forums.
## User Guide
More details about the project and how it can be used are available in [USER_GUIDE.md](USER_GUIDE.md)
", Assign "at most 3 tags" to the expected json: {"id":"14020","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"