Skip to content

Commit 9bb2ca4

Browse files
piercifaniclaude
andcommitted
Merge main into jextract-async-throwing-stream: SwiftExtract moved to swift-binding-generator-core
swiftlang#957 moved SwiftExtract out of this repository. This branch's analysis changes are now jextract-async-throwing-stream on piercifani/swift-binding-generator-core, which Package.swift depends on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 parents 139d88f + 793e154 commit 9bb2ca4

76 files changed

Lines changed: 469 additions & 10499 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CONTRIBUTING.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ In the case of formatting issues, `git add` the formatting changes and attempt t
106106

107107
Some documentation is generated from source and checked in, so CI can catch it drifting out of date. If you changed `Configuration.swift` or a CLI command's flags/help text, run `scripts/generate-docs.sh` and commit the generated changes.
108108

109+
### Developing against local dependency checkouts
110+
111+
swift-java depends on [swift-java-jni-core](https://github.com/swiftlang/swift-java-jni-core) and [swift-binding-generator-core](https://github.com/swiftlang/swift-binding-generator-core) (home of the `SwiftExtract` library) from their `main` branches. To develop against local checkouts instead, clone the repositories next to your swift-java checkout and point the corresponding environment variables at them:
112+
113+
```bash
114+
export PROJECT_ROOT= # the directory containing your checkouts
115+
cd $PROJECT_ROOT
116+
ls
117+
> swift-java
118+
> swift-java-jni-core
119+
> swift-binding-generator-core
120+
> # ...and all the others here
121+
122+
export SWIFT_JAVA_JNI_CORE_PATH=$PROJECT_ROOT/swift-java-jni-core
123+
export SWIFT_BINDING_GENERATOR_CORE_PATH=$PROJECT_ROOT/swift-binding-generator-core
124+
swift build
125+
```
126+
109127
## How to contribute your work
110128

111129
Please open a pull request at https://github.com/swiftlang/swift-java. Make sure the CI passes, and then wait for code review.

‎Package.swift‎

Lines changed: 16 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ if let localPath = Context.environment["SWIFT_JAVA_JNI_CORE_PATH"] {
1111
swiftJavaJNICoreDep = .package(url: "https://github.com/swiftlang/swift-java-jni-core", branch: "main")
1212
}
1313

14+
let swiftBindingGeneratorCoreDep: Package.Dependency
15+
if let localPath = Context.environment["SWIFT_BINDING_GENERATOR_CORE_PATH"] {
16+
swiftBindingGeneratorCoreDep = .package(path: localPath)
17+
} else {
18+
// The analysis part of this branch: the same branch of the core fork.
19+
swiftBindingGeneratorCoreDep = .package(url: "https://github.com/piercifani/swift-binding-generator-core", branch: "jextract-async-throwing-stream")
20+
}
21+
1422
// Set SWIFTJAVA_DOCC_PLUGIN_INSTALL=1 to install the docc-plugin automatically,
1523
// or DOCC_PLUGIN_PATH=<path> to point at a local checkout.
1624
// This is a workaround because swift-subprocess includes the plugin explicitly,
@@ -59,11 +67,6 @@ let package = Package(
5967
targets: ["SwiftJavaConfigurationShared"]
6068
),
6169

62-
.library(
63-
name: "SwiftExtractConfigurationShared",
64-
targets: ["SwiftExtractConfigurationShared"]
65-
),
66-
6770
.library(
6871
name: "JavaUtil",
6972
targets: ["JavaUtil"]
@@ -129,11 +132,6 @@ let package = Package(
129132
targets: ["SwiftRuntimeFunctions"]
130133
),
131134

132-
.library(
133-
name: "SwiftExtract",
134-
targets: ["SwiftExtract"]
135-
),
136-
137135
.library(
138136
name: "CodePrinting",
139137
targets: ["CodePrinting"]
@@ -166,11 +164,14 @@ let package = Package(
166164
],
167165
dependencies: [
168166
swiftJavaJNICoreDep,
167+
swiftBindingGeneratorCoreDep,
169168
.package(url: "https://github.com/swiftlang/swift-syntax", from: "603.0.0"),
170169
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.8.0"),
171170
.package(url: "https://github.com/apple/swift-system", from: "1.4.0"),
172171
.package(url: "https://github.com/apple/swift-log", from: "1.2.0"),
173-
.package(url: "https://github.com/apple/swift-collections", from: "1.3.0"), // primarily for ordered collections
172+
// primarily for ordered collections
173+
// FIXME: swift-collections 1.7.0 raised its minimum toolchain to Swift 6.2; stay below it while we still support Swift 6.1
174+
.package(url: "https://github.com/apple/swift-collections", "1.3.0"..<"1.7.0"),
174175
.package(url: "https://github.com/swiftlang/swift-subprocess.git", "0.4.0"..<"0.5.0", traits: ["SubprocessFoundation"]),
175176

176177
// Benchmarking
@@ -304,14 +305,10 @@ let package = Package(
304305
.target(
305306
name: "SwiftJavaConfigurationShared",
306307
dependencies: [
307-
"SwiftExtractConfigurationShared"
308+
.product(name: "SwiftExtractConfigurationShared", package: "swift-binding-generator-core")
308309
]
309310
),
310311

311-
.target(
312-
name: "SwiftExtractConfigurationShared"
313-
),
314-
315312
.target(
316313
name: "SwiftJavaShared"
317314
),
@@ -352,6 +349,7 @@ let package = Package(
352349
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
353350
.product(name: "ArgumentParser", package: "swift-argument-parser"),
354351
.product(name: "SystemPackage", package: "swift-system"),
352+
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
355353
"SwiftJava",
356354
"JavaUtilJar",
357355
"JavaNet",
@@ -375,32 +373,6 @@ let package = Package(
375373
]
376374
),
377375

378-
.target(
379-
name: "SwiftExtract",
380-
dependencies: [
381-
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
382-
.product(name: "SwiftIfConfig", package: "swift-syntax"),
383-
.product(name: "SwiftLexicalLookup", package: "swift-syntax"),
384-
.product(name: "SwiftParser", package: "swift-syntax"),
385-
.product(name: "SwiftSyntax", package: "swift-syntax"),
386-
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
387-
"SwiftExtractConfigurationShared",
388-
],
389-
path: "Sources/SwiftExtract",
390-
resources: [
391-
// Holds the `dummy.json` placeholder so SwiftPM emits a `Bundle.module`
392-
// for this target. The real `static-build-config.json` is generated at
393-
// build time by the `_StaticBuildConfigPlugin` build tool below.
394-
.process("Resources")
395-
],
396-
swiftSettings: [
397-
.swiftLanguageMode(.v5)
398-
],
399-
plugins: [
400-
.plugin(name: "_StaticBuildConfigPlugin")
401-
]
402-
),
403-
404376
.target(
405377
name: "JExtractSwiftLib",
406378
dependencies: [
@@ -412,7 +384,7 @@ let package = Package(
412384
.product(name: "ArgumentParser", package: "swift-argument-parser"),
413385
.product(name: "OrderedCollections", package: "swift-collections"),
414386
.product(name: "SwiftJavaJNICore", package: "swift-java-jni-core"),
415-
"SwiftExtract",
387+
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
416388
"SwiftJavaShared",
417389
"SwiftJavaConfigurationShared",
418390
"CodePrinting",
@@ -423,14 +395,6 @@ let package = Package(
423395
]
424396
),
425397

426-
.executableTarget(
427-
name: "StaticBuildConfigPluginExecutable",
428-
dependencies: [
429-
.product(name: "Subprocess", package: "swift-subprocess"),
430-
.product(name: "SwiftIfConfig", package: "swift-syntax"),
431-
]
432-
),
433-
434398
// Dev-time tool: regenerates the "Supported configuration options" table in
435399
// `Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaConfigFile.md`
436400
// straight from the doc comments on `Configuration.swift` and the enums it
@@ -448,14 +412,6 @@ let package = Package(
448412
path: "Sources/GenerateConfigDocs"
449413
),
450414

451-
.plugin(
452-
name: "_StaticBuildConfigPlugin",
453-
capability: .buildTool(),
454-
dependencies: [
455-
"StaticBuildConfigPluginExecutable"
456-
]
457-
),
458-
459415
.plugin(
460416
name: "JExtractSwiftPlugin",
461417
capability: .buildTool(),
@@ -512,23 +468,14 @@ let package = Package(
512468
name: "JExtractSwiftTests",
513469
dependencies: [
514470
"JExtractSwiftLib",
515-
"SwiftExtract",
471+
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
516472
"CodePrinting",
517473
],
518474
swiftSettings: [
519475
.swiftLanguageMode(.v5)
520476
]
521477
),
522478

523-
.testTarget(
524-
name: "SwiftExtractTests",
525-
dependencies: [
526-
"SwiftExtract",
527-
.product(name: "SwiftSyntax", package: "swift-syntax"),
528-
.product(name: "SwiftParser", package: "swift-syntax"),
529-
]
530-
),
531-
532479
.testTarget(
533480
name: "CodePrintingTests",
534481
dependencies: [

‎Plugins/PluginsShared/SwiftExtractConfigurationShared‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

Sources/SwiftExtractConfigurationShared/AccessLevelMode.swift renamed to Plugins/PluginsShared/SwiftExtractConfigurationShared/AccessLevelMode.swift

File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
DO NOT EDIT THESE FILES IN THIS REPOSITORY.
2+
3+
The files in this directory are vendored, byte-identical copies of:
4+
5+
https://github.com/swiftlang/swift-binding-generator-core
6+
Sources/SwiftExtractConfigurationShared/
7+
8+
They exist because SwiftPM package plugins cannot take sources from a package
9+
dependency, so the plugins in this repository compile these files directly.
10+
11+
Make any changes in swift-binding-generator-core instead, and then copy the
12+
updated files here. The swift-java compatibility CI job in
13+
swift-binding-generator-core diffs these copies against its own sources and
14+
will flag any drift.

Sources/SwiftExtractConfigurationShared/LogLevel.swift renamed to Plugins/PluginsShared/SwiftExtractConfigurationShared/LogLevel.swift

File renamed without changes.

‎Plugins/_StaticBuildConfigPlugin/_StaticBuildConfigPlugin.swift‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ In this mode the generated sources use JNI to call native code.
9797
This mode offers less performance and flexibility than FFM, but it is the most compatible: it works on older JVMs as well as on Android.
9898
Use it when FFM is not available, or when wide deployment compatibility is your priority. When performance is paramount, prefer FFM.
9999

100+
For Android-specific guidance, see also the [Android documentation](Sources/SwiftJavaDocumentation/Documentation.docc/Android.md).
101+
100102
Required language/runtime versions:
101103
- **Swift 6.2**, because of dependence on rich swift interface files
102104
- **JDK 17+**; the generated Java sources target the `javaSourceLevel` setting, which supports 17 through 25 (default 22)

‎Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary/CallbackProtcol.swift‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,11 @@ public func outputCallbacks(
105105
optionalString: callbacks.withOptionalString(optionalString)
106106
)
107107
}
108+
109+
public struct CallbackHolder {
110+
public init(callback: any CallbackProtocol) {
111+
self.callback = callback
112+
}
113+
114+
public var callback: any CallbackProtocol
115+
}

‎Sources/GenerateConfigDocs/GenerateConfigDocs.swift‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,29 @@ struct GenerateConfigDocs: ParsableCommand {
4949
.appendingPathComponent("Documentation.docc", isDirectory: true)
5050
.appendingPathComponent("SwiftJavaConfigFile.md", isDirectory: false)
5151

52+
// `SwiftExtractConfigurationShared` lives in the swift-binding-generator-core
53+
// package since `SwiftExtract` was split out of this repo. Scan every location
54+
// it may be found in.
5255
let scanDirs: [URL] = [
5356
repoRoot
5457
.appendingPathComponent("Sources", isDirectory: true)
5558
.appendingPathComponent("SwiftJavaConfigurationShared", isDirectory: true),
59+
// Legacy in-repo location (pre-split layout).
5660
repoRoot
5761
.appendingPathComponent("Sources", isDirectory: true)
5862
.appendingPathComponent("SwiftExtractConfigurationShared", isDirectory: true),
63+
// Resolved swift-binding-generator-core checkout.
64+
repoRoot
65+
.appendingPathComponent(".build", isDirectory: true)
66+
.appendingPathComponent("checkouts", isDirectory: true)
67+
.appendingPathComponent("swift-binding-generator-core", isDirectory: true)
68+
.appendingPathComponent("Sources", isDirectory: true)
69+
.appendingPathComponent("SwiftExtractConfigurationShared", isDirectory: true),
70+
// Vendored copy shared with the build plugins.
71+
repoRoot
72+
.appendingPathComponent("Plugins", isDirectory: true)
73+
.appendingPathComponent("PluginsShared", isDirectory: true)
74+
.appendingPathComponent("SwiftExtractConfigurationShared", isDirectory: true),
5975
]
6076

6177
// Parse enums and structs referenced by Configuration.

0 commit comments

Comments
 (0)