Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Samples/SwiftJavaExtractFFMSampleApp/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ let package = Package(
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
],
plugins: [
.plugin(name: "JExtractSwiftPlugin", package: "swift-java"),
// .plugin(name: "JExtractSwiftPlugin", package: "swift-java"),
]
),
]
Expand Down
197 changes: 0 additions & 197 deletions Samples/SwiftJavaExtractFFMSampleApp/build.gradle

This file was deleted.

111 changes: 111 additions & 0 deletions Samples/SwiftJavaExtractFFMSampleApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 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 kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import org.swift.swiftkit.gradle.BuildUtils
import java.io.ByteArrayOutputStream
import java.io.File

import java.nio.file.*
import kotlin.concurrent.thread

plugins {
id("build-logic.java-application-conventions")
id("me.champeau.jmh") version "0.7.2"
id("swiftpm-import-plugin")
}

group = "org.swift.swiftkit"
version = "1.0-SNAPSHOT"

repositories {
mavenCentral()
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(25))
}
}

// Add the java-swift generated Java sources


val cleanSwift = tasks.register("cleanSwift", Exec::class.java) {
workingDir = layout.projectDirectory.asFile
commandLine = listOf("swift")
args("package", "clean")
}
tasks.clean {
dependsOn("cleanSwift")
}

dependencies {
implementation(project(":SwiftKitCore"))
implementation(project(":SwiftKitFFM"))

testRuntimeOnly("org.junit.platform:junit-platform-launcher") // TODO: workaround for not finding junit: https://github.com/gradle/gradle/issues/34512 // TODO: workaround for not finding junit: https://github.com/gradle/gradle/issues/34512
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.named("test", Test::class.java) {
useJUnitPlatform()
}

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(25))
}

application {
mainClass = "com.example.swift.HelloJava2Swift"
}

val jmhIncludes = findProperty("jmhIncludes") as? String

jmh {
if (jmhIncludes != null) {
includes.set(setOf(jmhIncludes))
}

jvmArgsAppend = listOf(
"--enable-native-access=ALL-UNNAMED",

"-Djava.library.path=" +
((BuildUtils.javaLibraryPaths(rootDir) as Iterable<String>) +
(BuildUtils.javaLibraryPaths(project.projectDir) as Iterable<String>)).joinToString(":"),

// Enable tracing downcalls (to Swift)
"-Djextract.trace.downcalls=false"
)
}

swiftPMDependencies {
`package`(
url = url("https://github.com/abdulowork/SwiftPMImport.git"),
version = exact("1.0.12"),
products = listOf(product("SwiftPMImport", importedModules = setOf("SwiftTarget", "TargetWithAlgorithms"))),
)

localPackage(
path = projectDir,
products = listOf("MySwiftLibrary")
)

swiftJavaRepository.set(rootDir)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

// Import javakit/swiftkit support libraries

import com.example.swift.TargetWithAlgorithms.TargetWithAlgorithms;
import org.swift.swiftkit.core.CallTraces;
import org.swift.swiftkit.core.SwiftLibraries;
import org.swift.swiftkit.ffm.AllocatingSwiftArena;
import org.swift.swiftkit.ffm.SwiftRuntime;
import com.example.swift.MySwiftLibrary.*;
import com.example.swift.SwiftTarget.*;

import java.util.Optional;
import java.util.OptionalLong;
Expand Down Expand Up @@ -57,6 +60,15 @@ static void examples() {
try (var arena = AllocatingSwiftArena.ofConfined()) {
MySwiftClass obj = MySwiftClass.init(2222, 7777, arena);

SwiftApi objFromAnotherLibrary = SwiftApi.init(1, arena);
objFromAnotherLibrary.printFoo();

var data = TargetWithAlgorithms.randomSampleWrapper("hello world hello world hello world", 10, arena);
data.withUnsafeBytes((retBytes) -> {
var str = retBytes.getString(0);
CallTraces.trace("Use API with transitive Algorithms usage = " + str);
});

// just checking retains/releases work
CallTraces.trace("retainCount = " + SwiftRuntime.retainCount(obj));
SwiftRuntime.retain(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.example.swift;

import com.example.swift.MySwiftLibrary.*;
import org.junit.jupiter.api.Test;
import org.swift.swiftkit.ffm.AllocatingSwiftArena;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import static org.junit.jupiter.api.Assertions.*;

import com.example.swift.MySwiftLibrary.*;

public class MultipleTypesFromSingleFileTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import static org.junit.jupiter.api.Assertions.*;

import com.example.swift.MySwiftLibrary.*;

public class MySwiftClassTest {

void checkPaths(Throwable throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

import static org.junit.jupiter.api.Assertions.*;

import com.example.swift.MySwiftLibrary.*;

public class MySwiftLibraryTest {

static {
System.loadLibrary(MySwiftLibrary.LIB_NAME);
// System.loadLibrary(MySwiftLibrary.LIB_NAME);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import static org.junit.jupiter.api.Assertions.*;

import com.example.swift.MySwiftLibrary.*;

public class OptionalImportTest {
@Test
void test_Optional_receive() {
Expand Down
Loading
Loading