You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-19Lines changed: 32 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,8 @@
2
2
3
3
This repository contains two approaches to Swift/Java interoperability.
4
4
5
-
- 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.
6
-
- The `jextract-swift` tool which is similar to the JDK's `jextract` which allows to extract Java sources which are used
7
-
to efficiently call into Swift _from Java_.
5
+
- 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.
6
+
- The `swift-java` tool which which offers automated ways to import or "extract" bindings to sources or libraries in either language. The results are bindings for Swift or Java.
8
7
9
8
## :construction::construction::construction: Early Development :construction::construction::construction:
10
9
@@ -16,34 +15,48 @@ The primary purpose of this repository is to create an environment for collabora
16
15
17
16
## Dependencies
18
17
19
-
### Required Swift Development Toolchains
18
+
### Required JDK versions
20
19
21
-
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:
20
+
This project consists of different modules which have different Swift and Java runtime requirements.
22
21
23
-
**Required toolchain download:**
22
+
## JavaKit macros
24
23
25
-
Currently this project supports Swift `6.0.x` and we are working on supporting later releases.
24
+
JavaKit is a Swift library offering macros which simplify writing JNI code "by hand" but also calling Java code from Swift.
26
25
27
-
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.
26
+
It is possible to generate Swift bindings to Java libraries using JavaKit by using the `swift-java wrap-java` command.
28
27
29
-
### Required JDK versions
28
+
Required language/runtime versions:
29
+
-**JDK 17+**, any recent JDK installation should be sufficient, as only general reflection and JNI APIs are used by this integration
30
+
-**Swift 6.0.x**, because the library uses modern Swift macros
30
31
31
-
This project consists of different modules which have different Swift and Java runtime requirements.
32
+
**swift-java jextract**
32
33
33
-
**JavaKit** – the Swift macros allowing the invocation of Java libraries from Swift
34
+
Is a source generator which will **generate Java bindings to existing Swift libraries**.
35
+
Its inputs are Swift sources or packages, and outputs are generated Swift and Java code necessary to call these functions efficiently from Java.
34
36
35
-
-**JDK 17+**, any recent JDK installation should be sufficient, as only general reflection and JNI APIs are used by this integration
36
-
-**Swift 6.0.x**, because the library uses modern Swift macros
37
+
## swift-java jextract --mode=ffm (default)
38
+
39
+
This mode provides the most flexibility and performance, and allows to decrease the amount of data being copied between Swift and Java.
40
+
This does require the use of the relatively recent [JEP-454: Foreign Function & Memory API](https://openjdk.org/jeps/454), which is only available since JDK22, and will become part of JDK LTS releases with JDK 25 (depending on your JDK vendor).
41
+
42
+
This is the primary way we envision calling Swift code from server-side Java libraries and applications.
43
+
44
+
Required language/runtime versions:
45
+
-**Swift 6.1**, because of dependence on rich swift interface files
46
+
-**JDK 24+**
47
+
- We are validating the implementation using the currently supported non-LTE release, which at present means JDK-24.
48
+
49
+
## swift-java jextract --mode=jni
37
50
38
-
**jextract-swift** – the source generator that ingests .swiftinterface files and makes them available to be called from generated Java sources
51
+
In this mode, the generated sources will use the legacy JNI approach to calling native code.
39
52
40
-
-**Swift 6.0.x development snapshots**, because of dependence on rich swift interface files
41
-
-**JDK 22+** because of dependence on [JEP-454: Foreign Function & Memory API](https://openjdk.org/jeps/454)
42
-
- We are validating the implementation using the currently supported non-LTE release, which at present means JDK-23.
53
+
This mode is more limited in some performance and flexibility that it can offer, however it is the most compatible, since even very old JVM's as well as even Android systems can be supported by this mode.
54
+
We recommend this mode when FFM is not available, or wide ranging deployment compatibility is your priority. When performance is paramaunt, we recommend the FFM mode instead.
43
55
44
-
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.
56
+
Required language/runtime versions:
57
+
-**Swift 6.1**, because of dependence on rich swift interface files
58
+
-**Java 7+**, including
45
59
46
-
Support for more recent Swift versions will be provided, for now please stick to 6.0 while evaluating this early version of swift-java.
0 commit comments