diff --git a/Package.swift b/Package.swift index f3f959d..8af85bd 100644 --- a/Package.swift +++ b/Package.swift @@ -6,14 +6,14 @@ let package = Package( defaultLocalization: "en", platforms: [.iOS(.v16), .macOS(.v13), .tvOS(.v16), .watchOS(.v9), .macCatalyst(.v16)], products: [ - .library(name: "SkipFFI", type: .dynamic, targets: ["SkipFFI"]), + .library(name: "SkipFFI", targets: ["SkipFFI"]), ], dependencies: [ - .package(url: "https://source.skip.tools/skip.git", from: "0.7.16"), - .package(url: "https://source.skip.tools/skip-lib.git", from: "0.5.0") + .package(url: "https://source.skip.tools/skip.git", from: "0.7.30"), + .package(url: "https://source.skip.tools/skip-foundation.git", from: "0.3.7") ], targets: [ - .target(name: "SkipFFI", dependencies: [.product(name: "SkipLib", package: "skip-lib")], plugins: [.plugin(name: "skipstone", package: "skip")]), + .target(name: "SkipFFI", dependencies: [.product(name: "SkipFoundation", package: "skip-foundation")], plugins: [.plugin(name: "skipstone", package: "skip")]), .testTarget(name: "SkipFFITests", dependencies: ["SkipFFI", .product(name: "SkipTest", package: "skip")], plugins: [.plugin(name: "skipstone", package: "skip")]), ] ) diff --git a/README.md b/README.md index e25d6e9..8c36a8b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ On the Kotlin side, SkipFFI uses the Java Native Access ([JNA](https://github.co library to simulate Swift types like `Swift.OpaquePointer` as `com.sun.jna.Pointer` pointer references, and implements `Swift.withUnsafeMutablePointer` using a `com.sun.jna.ptr.PointerByReference` on the Java side. -This capability is used by Skip frameworks like [SkipScript](https://source.skip.tools/skip-script) to +This capability is used by Skip frameworks like [SkipSQL](https://source.skip.tools/skip-sql) and [SkipScript](https://source.skip.tools/skip-script) to provide a unified API to underlying native C APIs on both Darwin and Android. ## Example diff --git a/Sources/SkipFFI/SkipFFI.swift b/Sources/SkipFFI/SkipFFI.swift index d878ff1..b39b49d 100644 --- a/Sources/SkipFFI/SkipFFI.swift +++ b/Sources/SkipFFI/SkipFFI.swift @@ -23,4 +23,5 @@ public func String(cString: OpaquePointer) -> String { cString.getString(0) } + #endif diff --git a/Tests/SkipFFITests/SkipFFITests.swift b/Tests/SkipFFITests/SkipFFITests.swift index f55d082..7c57666 100644 --- a/Tests/SkipFFITests/SkipFFITests.swift +++ b/Tests/SkipFFITests/SkipFFITests.swift @@ -47,6 +47,11 @@ final class SkipFFITests: XCTestCase { XCTAssertNil(Darwin.getenv("PATH_DOES_NOT_EXIST"), "non-existent key should not return a value for getenv") } + func testDarwinDirectMappingJNA() throws { + let dd = DarwinDirect() + XCTAssertEqual(12, dd.abs(-12)) + } + func testSQLiteJNA() throws { #if SKIP // You may set the system property jna.debug_load=true to make JNA print the steps of its library search to the console. @@ -117,6 +122,23 @@ final class SkipFFITests: XCTestCase { } } + +final class DarwinDirect { + init() { + #if SKIP + // Android JNA error: "java.lang.IllegalStateException: The SecurityManager implementation on this platform is broken; you must explicitly provide the class to register" + // com.sun.jna.Native.register("c") + com.sun.jna.Native.register((DarwinDirect.self as kotlin.reflect.KClass).java, "c") + #endif + } + + // @JvmName is needed for test cases, since otherwise it is mangled to 'abs$SkipFFI_debugUnitTest' + // SKIP INSERT: @JvmName("abs") + // SKIP EXTERN + func abs(_ value: Int32) -> Int32 { Darwin.abs(value) } +} + + #if SKIP // MARK: BionicDarwin @@ -135,6 +157,7 @@ private protocol BionicDarwin : com.sun.jna.Library { } + // MARK: LibXMLLibrary private func LibXMLLibrary() -> LibXMLLibrary {