Skip to content

Commit 6a0e1dd

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

68 files changed

Lines changed: 322 additions & 11064 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-closure-requirements")
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,
@@ -65,11 +73,6 @@ let package = Package(
6573
targets: ["SwiftJavaAnnotations"]
6674
),
6775

68-
.library(
69-
name: "SwiftExtractConfigurationShared",
70-
targets: ["SwiftExtractConfigurationShared"]
71-
),
72-
7376
.library(
7477
name: "JavaUtil",
7578
targets: ["JavaUtil"]
@@ -135,11 +138,6 @@ let package = Package(
135138
targets: ["SwiftRuntimeFunctions"]
136139
),
137140

138-
.library(
139-
name: "SwiftExtract",
140-
targets: ["SwiftExtract"]
141-
),
142-
143141
.library(
144142
name: "CodePrinting",
145143
targets: ["CodePrinting"]
@@ -172,11 +170,14 @@ let package = Package(
172170
],
173171
dependencies: [
174172
swiftJavaJNICoreDep,
173+
swiftBindingGeneratorCoreDep,
175174
.package(url: "https://github.com/swiftlang/swift-syntax", from: "603.0.0"),
176175
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.8.0"),
177176
.package(url: "https://github.com/apple/swift-system", from: "1.4.0"),
178177
.package(url: "https://github.com/apple/swift-log", from: "1.2.0"),
179-
.package(url: "https://github.com/apple/swift-collections", from: "1.3.0"), // primarily for ordered collections
178+
// primarily for ordered collections
179+
// FIXME: swift-collections 1.7.0 raised its minimum toolchain to Swift 6.2; stay below it while we still support Swift 6.1
180+
.package(url: "https://github.com/apple/swift-collections", "1.3.0"..<"1.7.0"),
180181
.package(url: "https://github.com/swiftlang/swift-subprocess.git", "0.4.0"..<"0.5.0", traits: ["SubprocessFoundation"]),
181182

182183
// Benchmarking
@@ -317,14 +318,10 @@ let package = Package(
317318
.target(
318319
name: "SwiftJavaConfigurationShared",
319320
dependencies: [
320-
"SwiftExtractConfigurationShared"
321+
.product(name: "SwiftExtractConfigurationShared", package: "swift-binding-generator-core")
321322
]
322323
),
323324

324-
.target(
325-
name: "SwiftExtractConfigurationShared"
326-
),
327-
328325
.target(
329326
name: "SwiftJavaShared"
330327
),
@@ -365,6 +362,7 @@ let package = Package(
365362
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
366363
.product(name: "ArgumentParser", package: "swift-argument-parser"),
367364
.product(name: "SystemPackage", package: "swift-system"),
365+
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
368366
"SwiftJava",
369367
"JavaUtilJar",
370368
"JavaNet",
@@ -388,32 +386,6 @@ let package = Package(
388386
]
389387
),
390388

391-
.target(
392-
name: "SwiftExtract",
393-
dependencies: [
394-
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
395-
.product(name: "SwiftIfConfig", package: "swift-syntax"),
396-
.product(name: "SwiftLexicalLookup", package: "swift-syntax"),
397-
.product(name: "SwiftParser", package: "swift-syntax"),
398-
.product(name: "SwiftSyntax", package: "swift-syntax"),
399-
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
400-
"SwiftExtractConfigurationShared",
401-
],
402-
path: "Sources/SwiftExtract",
403-
resources: [
404-
// Holds the `dummy.json` placeholder so SwiftPM emits a `Bundle.module`
405-
// for this target. The real `static-build-config.json` is generated at
406-
// build time by the `_StaticBuildConfigPlugin` build tool below.
407-
.process("Resources")
408-
],
409-
swiftSettings: [
410-
.swiftLanguageMode(.v5)
411-
],
412-
plugins: [
413-
.plugin(name: "_StaticBuildConfigPlugin")
414-
]
415-
),
416-
417389
.target(
418390
name: "JExtractSwiftLib",
419391
dependencies: [
@@ -425,7 +397,7 @@ let package = Package(
425397
.product(name: "ArgumentParser", package: "swift-argument-parser"),
426398
.product(name: "OrderedCollections", package: "swift-collections"),
427399
.product(name: "SwiftJavaJNICore", package: "swift-java-jni-core"),
428-
"SwiftExtract",
400+
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
429401
"SwiftJavaShared",
430402
"SwiftJavaConfigurationShared",
431403
"CodePrinting",
@@ -436,14 +408,6 @@ let package = Package(
436408
]
437409
),
438410

439-
.executableTarget(
440-
name: "StaticBuildConfigPluginExecutable",
441-
dependencies: [
442-
.product(name: "Subprocess", package: "swift-subprocess"),
443-
.product(name: "SwiftIfConfig", package: "swift-syntax"),
444-
]
445-
),
446-
447411
// Dev-time tool: regenerates the "Supported configuration options" table in
448412
// `Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaConfigFile.md`
449413
// straight from the doc comments on `Configuration.swift` and the enums it
@@ -461,14 +425,6 @@ let package = Package(
461425
path: "Sources/GenerateConfigDocs"
462426
),
463427

464-
.plugin(
465-
name: "_StaticBuildConfigPlugin",
466-
capability: .buildTool(),
467-
dependencies: [
468-
"StaticBuildConfigPluginExecutable"
469-
]
470-
),
471-
472428
.plugin(
473429
name: "JExtractSwiftPlugin",
474430
capability: .buildTool(),
@@ -526,23 +482,14 @@ let package = Package(
526482
name: "JExtractSwiftTests",
527483
dependencies: [
528484
"JExtractSwiftLib",
529-
"SwiftExtract",
485+
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
530486
"CodePrinting",
531487
],
532488
swiftSettings: [
533489
.swiftLanguageMode(.v5)
534490
]
535491
),
536492

537-
.testTarget(
538-
name: "SwiftExtractTests",
539-
dependencies: [
540-
"SwiftExtract",
541-
.product(name: "SwiftSyntax", package: "swift-syntax"),
542-
.product(name: "SwiftParser", package: "swift-syntax"),
543-
]
544-
),
545-
546493
.testTarget(
547494
name: "CodePrintingTests",
548495
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)