Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ jobs:
name: Documentation check
runs-on: ubuntu-latest
container:
image: 'swift:6.1-noble'
image: 'swift:6.2-noble'
strategy:
fail-fast: true
matrix:
swift_version: ['6.1.3']
swift_version: ['6.2']
os_version: ['jammy']
jdk_vendor: ['corretto']
steps:
Expand All @@ -48,7 +48,7 @@ jobs:
strategy:
fail-fast: true
matrix:
swift_version: ['6.1.3', 'nightly']
swift_version: ['6.2', 'nightly']
os_version: ['jammy']
jdk_vendor: ['corretto']
container:
Expand All @@ -74,7 +74,7 @@ jobs:
strategy:
fail-fast: true
matrix:
swift_version: ['6.2.0']
swift_version: ['6.2']
os_version: ['macos']
jdk_vendor: ['corretto']
env:
Expand All @@ -98,7 +98,7 @@ jobs:
strategy:
fail-fast: true
matrix:
swift_version: ['6.2.0']
swift_version: ['6.2']
os_version: ['jammy']
jdk_vendor: ['corretto']
container:
Expand All @@ -118,7 +118,7 @@ jobs:
strategy:
fail-fast: true
matrix:
swift_version: ['6.2.0']
swift_version: ['6.2']
os_version: ['jammy']
jdk_vendor: ['corretto']
container:
Expand All @@ -140,7 +140,7 @@ jobs:
strategy:
fail-fast: false
matrix:
swift_version: ['6.1.3', 'nightly']
swift_version: ['6.2', 'nightly']
os_version: ['jammy']
jdk_vendor: ['corretto']
container:
Expand All @@ -162,7 +162,7 @@ jobs:
strategy:
fail-fast: false
matrix:
swift_version: ['6.2.0']
swift_version: ['6.2']
os_version: ['macos']
jdk_vendor: ['corretto']
env:
Expand All @@ -182,7 +182,7 @@ jobs:
strategy:
fail-fast: false
matrix:
swift_version: ['6.1.3', 'nightly']
swift_version: ['6.2', 'nightly']
os_version: ['jammy']
jdk_vendor: ['corretto']
sample_app: [ # TODO: use a reusable-workflow to generate those names
Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:
strategy:
fail-fast: false
matrix:
swift_version: ['6.2.0'] # no nightly testing on macOS
swift_version: ['6.2'] # no nightly testing on macOS
os_version: ['macos']
jdk_vendor: ['corretto']
sample_app: [ # TODO: use a reusable-workflow to generate those names
Expand Down
31 changes: 24 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 6.0
// swift-tools-version: 6.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import CompilerPluginSupport
Expand Down Expand Up @@ -169,9 +169,14 @@ let package = Package(

// Support library written in Swift for SwiftKit "Java"
.library(
name: "SwiftKitSwift",
name: "SwiftJavaRuntimeSupport",
targets: ["SwiftJavaRuntimeSupport"]
),

.library(
name: "SwiftRuntimeFunctions",
type: .dynamic,
targets: ["SwiftKitSwift"]
targets: ["SwiftRuntimeFunctions"]
),

.library(
Expand All @@ -197,7 +202,7 @@ let package = Package(

],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-syntax", from: "601.0.1"),
.package(url: "https://github.com/swiftlang/swift-syntax", from: "602.0.0"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
.package(url: "https://github.com/apple/swift-system", from: "1.4.0"),

Expand All @@ -213,7 +218,8 @@ let package = Package(
name: "SwiftJavaDocumentation",
dependencies: [
"SwiftJava",
"SwiftKitSwift",
"SwiftJavaRuntimeSupport",
"SwiftRuntimeFunctions",
]
),

Expand Down Expand Up @@ -351,8 +357,19 @@ let package = Package(
]
),
.target(
name: "SwiftKitSwift",
dependencies: [],
name: "SwiftJavaRuntimeSupport",
dependencies: [
"CSwiftJavaJNI",
"SwiftJava"
],
swiftSettings: [
.swiftLanguageMode(.v5),
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
]
),

.target(
name: "SwiftRuntimeFunctions",
swiftSettings: [
.swiftLanguageMode(.v5),
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ It is possible to generate Swift bindings to Java libraries using SwiftJava by u

Required language/runtime versions:
- **JDK 17+**, any recent JDK installation should be sufficient, as only general reflection and JNI APIs are used by this integratio
- **Swift 6.0.x**, because the library uses modern Swift macros
- **Swift 6.2.x**, because the library uses modern Swift macros

**swift-java jextract**

Expand All @@ -73,7 +73,7 @@ This does require the use of the relatively recent [JEP-454: Foreign Function &
This is the primary way we envision calling Swift code from server-side Java libraries and applications.

Required language/runtime versions:
- **Swift 6.1**, because of dependence on rich swift interface files
- **Swift 6.2**, because of dependence on rich swift interface files
- **JDK 25+**
- We are validating the implementation using the currently supported non-LTE release, which at present means JDK-25.

Expand All @@ -85,7 +85,7 @@ This mode is more limited in some performance and flexibility that it can offer,
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.

Required language/runtime versions:
- **Swift 6.1**, because of dependence on rich swift interface files
- **Swift 6.2**, because of dependence on rich swift interface files
- **Java 7+**, including


Expand All @@ -94,7 +94,7 @@ Required language/runtime versions:
This project contains multiple builds, living side by side together.

You will need to have:
- Swift (6.1.x+)
- Swift (6.2.x+)
- Java (25+ for FFM, even though we support lower JDK targets)
- Gradle (installed by "Gradle wrapper" automatically when you run gradle through `./gradlew`)

Expand All @@ -104,7 +104,7 @@ Install **Swift**, the easiest way to do this is to use **Swiftly**: [swift.org/
This should automatically install a recent Swift, but you can always make sure by running:

```bash
swiftly install 6.1.2 --use
swiftly install 6.2 --use
```

Install a recent enough Java distribution. We validate this project using Corretto so you can choose to use that as well,
Expand Down Expand Up @@ -229,4 +229,4 @@ xcrun docc preview Sources/SwiftJavaDocumentation/Documentation.docc

**This project is under active development. We welcome feedback about any issues you encounter.**

There is no guarantee about API stability until the project reaches a 1.0 release.
There is no guarantee about API stability until the project reaches a 1.0 release.
2 changes: 1 addition & 1 deletion Samples/SwiftAndJavaJarSampleLib/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let package = Package(
.target(
name: "MySwiftLibrary",
dependencies: [
.product(name: "SwiftKitSwift", package: "swift-java"),
.product(name: "SwiftRuntimeFunctions", package: "swift-java"),
],
exclude: [
"swift-java.config",
Expand Down
2 changes: 1 addition & 1 deletion Samples/SwiftJavaExtractFFMSampleApp/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let package = Package(
dependencies: [
.product(name: "SwiftJava", package: "swift-java"),
.product(name: "CSwiftJavaJNI", package: "swift-java"),
.product(name: "SwiftKitSwift", package: "swift-java"),
.product(name: "SwiftRuntimeFunctions", package: "swift-java"),
],
exclude: [
"swift-java.config",
Expand Down
4 changes: 2 additions & 2 deletions Samples/SwiftJavaExtractJNISampleApp/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 6.0
// swift-tools-version: 6.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import CompilerPluginSupport
Expand Down Expand Up @@ -62,7 +62,7 @@ let package = Package(
dependencies: [
.product(name: "SwiftJava", package: "swift-java"),
.product(name: "CSwiftJavaJNI", package: "swift-java"),
.product(name: "SwiftKitSwift", package: "swift-java"),
.product(name: "SwiftJavaRuntimeSupport", package: "swift-java"),
],
exclude: [
"swift-java.config"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import SwiftJava

public func asyncSum(i1: Int64, i2: Int64) async -> Int64 {
return i1 + i2
}

public func asyncSleep() async throws {
try await Task.sleep(for: .milliseconds(500))
}

public func asyncCopy(myClass: MySwiftClass) async throws -> MySwiftClass {
let new = MySwiftClass(x: myClass.x, y: myClass.y)
try await Task.sleep(for: .milliseconds(500))
return new
}

public func asyncOptional(i: Int64) async throws -> Int64? {
try await Task.sleep(for: .milliseconds(100))
return i
}

public func asyncThrows() async throws {
throw MySwiftError.swiftError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

enum MySwiftError: Error {
case swiftError
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public func optionalJavaKitLong(input: Optional<JavaLong>) -> Int64? {
}
}

public func optionalThrowing() throws -> Int64? {
throw MySwiftError.swiftError
}

public func multipleOptionals(
input1: Optional<Int8>,
input2: Optional<Int16>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

package com.example.swift;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.swift.swiftkit.core.ClosableSwiftArena;
import org.swift.swiftkit.core.ConfinedSwiftMemorySession;
import org.swift.swiftkit.core.SwiftArena;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 5, time = 200, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@State(Scope.Benchmark)
@Fork(value = 1, jvmArgsAppend = { "--enable-native-access=ALL-UNNAMED" })
public class AsyncBenchmark {
/**
* Parameter for the number of parallel tasks to launch.
*/
@Param({"100", "500", "1000"})
public int taskCount;

@Setup(Level.Trial)
public void beforeAll() {}

@TearDown(Level.Trial)
public void afterAll() {}

@Benchmark
public void asyncSum(Blackhole bh) {
CompletableFuture<Void>[] futures = new CompletableFuture[taskCount];

// Launch all tasks in parallel using supplyAsync on our custom executor
for (int i = 0; i < taskCount; i++) {
futures[i] = MySwiftLibrary.asyncSum(10, 5).thenAccept(bh::consume);
}

// Wait for all futures to complete.
CompletableFuture.allOf(futures).join();
}
}
Loading
Loading