jextract: Move Foundation support into a common package#684
jextract: Move Foundation support into a common package#684sidepelican wants to merge 13 commits intoswiftlang:mainfrom
Conversation
Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaBindingsPrinting.swift
Show resolved
Hide resolved
Samples/SwiftJavaExtractFFMSampleApp/src/main/java/com/example/swift/HelloJava2Swift.java
Show resolved
Hide resolved
Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaBindingsPrinting.swift
Outdated
Show resolved
Hide resolved
Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaTranslation.swift
Outdated
Show resolved
Hide resolved
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import org.swift.swiftkit.core.annotations.*; | ||
|
|
||
| public final class Data implements JNISwiftInstance, DataProtocol { |
There was a problem hiding this comment.
Very nice, let's add some docs onto it that this is Foundation.Data and link to https://developer.apple.com/documentation/foundation/data
There was a problem hiding this comment.
Hmmm on the other hand, shouldn't this be generated? We can use the jextract --single-type mode perhaps and point it at https://github.com/swiftlang/swift-foundation/blob/main/Sources/FoundationEssentials/Data/Data.swift
We should have some script in scripts/ (there's a few, maybe one of them) that does that and generates this file perhaps? We can use the filterInclude to pick which exact pieces of Data we want etc
There was a problem hiding this comment.
Ah damn we can't because we're adding helper methods to it...
We'd need an extra feature to "add extra methods to imported type"... that would be great though 🤔
| import java.lang.invoke.*; | ||
| import java.util.*; | ||
|
|
||
| public final class Data extends FFMSwiftInstance implements SwiftValue { |
There was a problem hiding this comment.
Same as on the other type; can we find a way to generate those using a script and not just by hand paste the generated code?
There was a problem hiding this comment.
I actually tried that approach at first, but I ran into quite a few minor issues.
It needs more custom logics into the generater.
Since Date and Data had their own dedicated code generation logic (printSpecificTypeHelpers), I thought it would be easier to manage the source code manually rather than dealing with the maintenance overhead of the generator.
|
I'll look into code generation a bit more |
|
Thank you! I think we maybe we need some extra setting that is |
Instead of generating
Date,Data, andDataProtocolimplementations within each user module, I will bundle these as part of SwiftJava's standard library.Fixed implementations are now located under
org.swift.swiftkit.core.foundationandorg.swift.swiftkit.ffm.foundation.Removed
printSpecificTypeHelpersfrom the code generation process.This ensures that when multiple modules utilize swift-java, they all share a single, unified set of Foundation classes.