Skip to content

Commit e17005d

Browse files
committed
remove jextract generated files and use new src/generated target dir
1 parent 24d99be commit e17005d

File tree

11 files changed

+57
-814
lines changed

11 files changed

+57
-814
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ BuildLogic/out/
2525
.gradletasknamecache
2626

2727
# Ignore generated sources
28-
JavaSwiftKitDemo/src/main/java/com/example/swift/generated/*
29-
JavaSwiftKitDemo/src/generated/**
28+
JavaSwiftKitDemo/src/generated/*
29+
SwiftKitExample/src/generated/**/*
File renamed without changes.
File renamed without changes.

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ generate-all: generate-JavaKit generate-JavaKitReflection generate-JavaKitJar ge
7171
jextract-swift
7272
clean:
7373
rm -rf .build
74+
rm -rf
7475

7576
format:
76-
swift format --recursive . -i
77+
swift format --recursive . -i \
78+
rm -rf SwiftKitExample/src/generated/java
7779

7880
#################################################
7981
### "SwiftKit" is the "call swift from java" ###
@@ -105,10 +107,10 @@ generate-JExtract-interface-files: $(BUILD_DIR)/debug/libJavaKit.$(LIB_SUFFIX)
105107
jextract-run: jextract-swift generate-JExtract-interface-files
106108
swift run jextract-swift \
107109
--package-name com.example.swift.generated \
108-
--swift-module JavaKitExample \
109-
--output-directory JavaSwiftKitDemo/src/main/java \
110-
$(BUILD_DIR)/jextract/JavaKitExample/MySwiftLibrary.swiftinterface \
111-
$(BUILD_DIR)/jextract/JavaKitExample/SwiftKit.swiftinterface
110+
--swift-module SwiftKitExample \
111+
--output-directory SwiftKitExample/src/generated/java \
112+
$(BUILD_DIR)/jextract/ExampleSwiftLibrary/MySwiftLibrary.swiftinterface \
113+
$(BUILD_DIR)/jextract/ExampleSwiftLibrary/SwiftKit.swiftinterface
112114

113115

114116
jextract-run-java: jextract-swift generate-JExtract-interface-files

Package.swift

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ let package = Package(
5050
.macCatalyst(.v13),
5151
],
5252
products: [
53+
// ==== JavaKit (i.e. calling Java directly Swift utilities)
5354
.library(
5455
name: "JavaKit",
5556
type: .dynamic,
@@ -74,12 +75,6 @@ let package = Package(
7475
targets: ["JavaKitReflection"]
7576
),
7677

77-
.library(
78-
name: "JavaKitExample",
79-
type: .dynamic,
80-
targets: ["JavaKitExample"]
81-
),
82-
8378
.library(
8479
name: "JavaKitVM",
8580
type: .dynamic,
@@ -92,21 +87,44 @@ let package = Package(
9287
targets: ["JavaTypes"]
9388
),
9489

95-
.library(
96-
name: "JExtractSwift",
97-
type: .dynamic,
98-
targets: ["JExtractSwift"]
99-
),
100-
10190
.executable(
10291
name: "Java2Swift",
10392
targets: ["Java2Swift"]
10493
),
10594

95+
// ==== jextract-swift (extract Java accessors from Swift interface files)
96+
10697
.executable(
10798
name: "jextract-swift",
10899
targets: ["JExtractSwiftTool"]
109100
),
101+
102+
// Support library written in Swift for SwiftKit "Java"
103+
.library(
104+
name: "SwiftKitSwift",
105+
type: .dynamic,
106+
targets: ["SwiftKitSwift"]
107+
),
108+
109+
.library(
110+
name: "JExtractSwift",
111+
type: .dynamic,
112+
targets: ["JExtractSwift"]
113+
),
114+
115+
// ==== Examples
116+
117+
.library(
118+
name: "JavaKitExample",
119+
type: .dynamic,
120+
targets: ["JavaKitExample"]
121+
),
122+
.library(
123+
name: "ExampleSwiftLibrary",
124+
type: .dynamic,
125+
targets: ["ExampleSwiftLibrary"]
126+
),
127+
110128
],
111129
dependencies: [
112130
.package(url: "https://github.com/swiftlang/swift-syntax.git", branch: "main"),
@@ -194,6 +212,22 @@ let package = Package(
194212
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
195213
]
196214
),
215+
.target(
216+
name: "ExampleSwiftLibrary",
217+
dependencies: [],
218+
swiftSettings: [
219+
.swiftLanguageMode(.v5),
220+
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
221+
]
222+
),
223+
.target(
224+
name: "SwiftKitSwift",
225+
dependencies: [],
226+
swiftSettings: [
227+
.swiftLanguageMode(.v5),
228+
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
229+
]
230+
),
197231

198232
.target(
199233
name: "JavaRuntime",
Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +0,0 @@
1-
//===----------------------------------------------------------------------===//
2-
//
3-
// This source file is part of the Swift.org open source project
4-
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift.org project authors
6-
// Licensed under Apache License v2.0
7-
//
8-
// See LICENSE.txt for license information
9-
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10-
//
11-
// SPDX-License-Identifier: Apache-2.0
12-
//
13-
//===----------------------------------------------------------------------===//
14-
15-
import JavaKit
16-
import JavaRuntime
17-
18-
enum SwiftWrappedError: Error {
19-
case message(String)
20-
}
21-
22-
@JavaClass("com.example.swift.HelloSwift")
23-
struct HelloSwift {
24-
@JavaMethod
25-
init(environment: JNIEnvironment)
26-
27-
@JavaMethod
28-
func sayHelloBack(_ i: Int32) -> Double
29-
30-
@JavaMethod
31-
func greet(_ name: String)
32-
33-
@JavaMethod
34-
func doublesToStrings(doubles: [Double]) -> [String]
35-
36-
@JavaMethod
37-
func throwMessage(message: String) throws
38-
39-
@JavaField
40-
var value: Double
41-
42-
@JavaField
43-
var name: String
44-
45-
@ImplementsJava
46-
func sayHello(i: Int32, _ j: Int32) -> Int32 {
47-
print("Hello from Swift!")
48-
let answer = self.sayHelloBack(i + j)
49-
print("Swift got back \(answer) from Java")
50-
51-
print("We expect the above value to be the initial value, \(self.javaClass.initialValue)")
52-
53-
print("Updating Java field value to something different")
54-
self.value = 2.71828
55-
56-
let newAnswer = self.sayHelloBack(17)
57-
print("Swift got back updated \(newAnswer) from Java")
58-
59-
let newHello = HelloSwift(environment: javaEnvironment)
60-
print("Swift created a new Java instance with the value \(newHello.value)")
61-
62-
let name = newHello.name
63-
print("Hello to \(name)")
64-
newHello.greet("Swift 👋🏽 How's it going")
65-
66-
self.name = "a 🗑️-collected language"
67-
_ = self.sayHelloBack(42)
68-
69-
let strings = doublesToStrings(doubles: [3.14159, 2.71828])
70-
print("Converting doubles to strings: \(strings)")
71-
72-
// Try downcasting
73-
if let helloSub = self.as(HelloSubclass.self) {
74-
print("Hello from the subclass!")
75-
helloSub.greetMe()
76-
77-
assert(helloSub.super.value == 2.71828)
78-
} else {
79-
fatalError("Expected subclass here")
80-
}
81-
82-
// Check "is" behavior
83-
assert(newHello.is(HelloSwift.self))
84-
assert(!newHello.is(HelloSubclass.self))
85-
86-
// Create a new instance.
87-
let helloSubFromSwift = HelloSubclass(greeting: "Hello from Swift", environment: javaEnvironment)
88-
helloSubFromSwift.greetMe()
89-
90-
do {
91-
try throwMessage(message: "I am an error")
92-
} catch {
93-
print("Caught Java error: \(error)")
94-
}
95-
96-
return i * j
97-
}
98-
99-
@ImplementsJava
100-
func throwMessageFromSwift(message: String) throws -> String {
101-
throw SwiftWrappedError.message(message)
102-
}
103-
}
104-
105-
extension JavaClass<HelloSwift> {
106-
@JavaField
107-
var initialValue: Double
108-
}
109-
110-
@JavaClass("com.example.swift.HelloSubclass", extends: HelloSwift.self)
111-
struct HelloSubclass {
112-
@JavaField
113-
var greeting: String
114-
115-
@JavaMethod
116-
func greetMe()
117-
118-
@JavaMethod
119-
init(greeting: String, environment: JNIEnvironment)
120-
}
File renamed without changes.

0 commit comments

Comments
 (0)