Skip to content

Commit 5e0dc68

Browse files
piercifaniclaude
andcommitted
Merge main into jextract-export-control: SwiftExtract moved to swift-binding-generator-core
swiftlang#957 moved SwiftExtract out of this repository. This branch's analysis changes (ExtractDecider.mayExtractMembers(of:), isExported(_:) and isFromKnownModuleSource) now live in swift-binding-generator-core, so its edits to the deleted SwiftExtract files are dropped here. Until that change lands there, build with SWIFT_BINDING_GENERATOR_CORE_PATH pointing at a checkout that has it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 parents be9163e + 793e154 commit 5e0dc68

65 files changed

Lines changed: 294 additions & 10540 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: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ 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+
swiftBindingGeneratorCoreDep = .package(url: "https://github.com/swiftlang/swift-binding-generator-core", branch: "main")
19+
}
20+
1421
// Set SWIFTJAVA_DOCC_PLUGIN_INSTALL=1 to install the docc-plugin automatically,
1522
// or DOCC_PLUGIN_PATH=<path> to point at a local checkout.
1623
// This is a workaround because swift-subprocess includes the plugin explicitly,
@@ -65,11 +72,6 @@ let package = Package(
6572
targets: ["SwiftJavaAnnotations"]
6673
),
6774

68-
.library(
69-
name: "SwiftExtractConfigurationShared",
70-
targets: ["SwiftExtractConfigurationShared"]
71-
),
72-
7375
.library(
7476
name: "JavaUtil",
7577
targets: ["JavaUtil"]
@@ -135,11 +137,6 @@ let package = Package(
135137
targets: ["SwiftRuntimeFunctions"]
136138
),
137139

138-
.library(
139-
name: "SwiftExtract",
140-
targets: ["SwiftExtract"]
141-
),
142-
143140
.library(
144141
name: "CodePrinting",
145142
targets: ["CodePrinting"]
@@ -172,6 +169,7 @@ let package = Package(
172169
],
173170
dependencies: [
174171
swiftJavaJNICoreDep,
172+
swiftBindingGeneratorCoreDep,
175173
.package(url: "https://github.com/swiftlang/swift-syntax", from: "603.0.0"),
176174
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.8.0"),
177175
.package(url: "https://github.com/apple/swift-system", from: "1.4.0"),
@@ -319,14 +317,10 @@ let package = Package(
319317
.target(
320318
name: "SwiftJavaConfigurationShared",
321319
dependencies: [
322-
"SwiftExtractConfigurationShared"
320+
.product(name: "SwiftExtractConfigurationShared", package: "swift-binding-generator-core")
323321
]
324322
),
325323

326-
.target(
327-
name: "SwiftExtractConfigurationShared"
328-
),
329-
330324
.target(
331325
name: "SwiftJavaShared"
332326
),
@@ -367,6 +361,7 @@ let package = Package(
367361
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
368362
.product(name: "ArgumentParser", package: "swift-argument-parser"),
369363
.product(name: "SystemPackage", package: "swift-system"),
364+
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
370365
"SwiftJava",
371366
"JavaUtilJar",
372367
"JavaNet",
@@ -390,32 +385,6 @@ let package = Package(
390385
]
391386
),
392387

393-
.target(
394-
name: "SwiftExtract",
395-
dependencies: [
396-
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
397-
.product(name: "SwiftIfConfig", package: "swift-syntax"),
398-
.product(name: "SwiftLexicalLookup", package: "swift-syntax"),
399-
.product(name: "SwiftParser", package: "swift-syntax"),
400-
.product(name: "SwiftSyntax", package: "swift-syntax"),
401-
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
402-
"SwiftExtractConfigurationShared",
403-
],
404-
path: "Sources/SwiftExtract",
405-
resources: [
406-
// Holds the `dummy.json` placeholder so SwiftPM emits a `Bundle.module`
407-
// for this target. The real `static-build-config.json` is generated at
408-
// build time by the `_StaticBuildConfigPlugin` build tool below.
409-
.process("Resources")
410-
],
411-
swiftSettings: [
412-
.swiftLanguageMode(.v5)
413-
],
414-
plugins: [
415-
.plugin(name: "_StaticBuildConfigPlugin")
416-
]
417-
),
418-
419388
.target(
420389
name: "JExtractSwiftLib",
421390
dependencies: [
@@ -427,7 +396,7 @@ let package = Package(
427396
.product(name: "ArgumentParser", package: "swift-argument-parser"),
428397
.product(name: "OrderedCollections", package: "swift-collections"),
429398
.product(name: "SwiftJavaJNICore", package: "swift-java-jni-core"),
430-
"SwiftExtract",
399+
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
431400
"SwiftJavaShared",
432401
"SwiftJavaConfigurationShared",
433402
"CodePrinting",
@@ -438,14 +407,6 @@ let package = Package(
438407
]
439408
),
440409

441-
.executableTarget(
442-
name: "StaticBuildConfigPluginExecutable",
443-
dependencies: [
444-
.product(name: "Subprocess", package: "swift-subprocess"),
445-
.product(name: "SwiftIfConfig", package: "swift-syntax"),
446-
]
447-
),
448-
449410
// Dev-time tool: regenerates the "Supported configuration options" table in
450411
// `Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaConfigFile.md`
451412
// straight from the doc comments on `Configuration.swift` and the enums it
@@ -463,14 +424,6 @@ let package = Package(
463424
path: "Sources/GenerateConfigDocs"
464425
),
465426

466-
.plugin(
467-
name: "_StaticBuildConfigPlugin",
468-
capability: .buildTool(),
469-
dependencies: [
470-
"StaticBuildConfigPluginExecutable"
471-
]
472-
),
473-
474427
.plugin(
475428
name: "JExtractSwiftPlugin",
476429
capability: .buildTool(),
@@ -527,23 +480,14 @@ let package = Package(
527480
name: "JExtractSwiftTests",
528481
dependencies: [
529482
"JExtractSwiftLib",
530-
"SwiftExtract",
483+
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
531484
"CodePrinting",
532485
],
533486
swiftSettings: [
534487
.swiftLanguageMode(.v5)
535488
]
536489
),
537490

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

‎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.

Sources/SwiftExtract/Convenience/Collection+Extensions.swift renamed to Sources/JExtractSwiftLib/Convenience/Collection+SwiftExtract.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
extension Dictionary {
16-
/// Same values, corresponding to mapped keys.
17-
public func mapKeys<Transformed>(
18-
_ transform: (Key) throws -> Transformed
19-
) rethrows -> [Transformed: Value] {
20-
.init(
21-
uniqueKeysWithValues: try map {
22-
(try transform($0.key), $0.value)
23-
}
24-
)
25-
}
26-
27-
}
28-
2915
extension Collection {
3016
package typealias IsLastElement = Bool
3117
package var withIsLast: any Collection<(Element, IsLastElement)> {
@@ -39,13 +25,3 @@ extension Collection {
3925
}
4026
}
4127
}
42-
43-
extension Collection where Element == Int {
44-
var sum: Int {
45-
var s = 0
46-
for i in self {
47-
s += i
48-
}
49-
return s
50-
}
51-
}

0 commit comments

Comments
 (0)