Skip to content

Kotlin/Native: class/struct bridging and global variables🫪#4

Open
RandVid wants to merge 10 commits into
mainfrom
class-impl
Open

Kotlin/Native: class/struct bridging and global variables🫪#4
RandVid wants to merge 10 commits into
mainfrom
class-impl

Conversation

@RandVid

@RandVid RandVid commented Jun 29, 2026

Copy link
Copy Markdown
Owner

What was done

Custom class & struct support — each imported Swift nominal type becomes a
Kotlin/Native wrapper class holding an COpaquePointer to a Swift-allocated
box. Supported member surfaces:
constructors, instance methods, static methods, and stored-property get/set.
Custom types work as parameters and return values on both top-level functions
and members.

SwiftKitKN — new Kotlin/Native library (org.swift.swiftkit.kn)
that exports SwiftHandle: the opaque-pointer box that backs every wrapper
instance, guards the destroy thunk with a CAS AtomicInt, and fires exactly once
via deterministic close() or GC createCleaner.

Type support — constructors, instance/static
methods, and property accessors now handle all primitives, String,
[UInt8] (params via usePinned, returns via memScoped +
out-count), optionals and custom imported class/struct types (passed as opaque box
pointers)

Top-level global variables — Swift public var declarations at module scope
are emitted as Kotlin val (getter-only) or var (getter+setter) top-level
properties.

Lifetime test suite — covers exact-once destroy on close(), CAS
idempotency on double-close, no-leak across 100 cycles, shared-identity and
multi-owner lifetime, struct releasing a reference member, GC cleaner path, and
a Swift weak-reference probe that observes ARC deallocation independently of the
deinit counter.

Ilya Plisko added 6 commits June 18, 2026 13:36
…d type safety and clarity

- Replace `String`-based type mapping with `KotlinType` enum for consistency across primitive and reference types.
- Update `swiftTypeToKotlin` function to return `KotlinType?` and adjust type mapping logic accordingly.
- Introduce `KotlinType.swift` to define the `KotlinType` enum, associated cases, and descriptions.
- Refactor call argument handling to leverage `KotlinType` cases (e.g., `.string`, `.unit`).
- Update code to switch on `KotlinType` enum instead of raw strings for type checks.
- Ensure proper handling of `String` and other specific types with the new enum.
- Extend `swiftTypeToKotlin` and `KotlinType` to map `[UInt8]` to `UByteArray`.
- Add struct `Pinning` to encapsulate pinning information for parameters requiring `usePinned`.
- Extend `swiftTypeToKotlin` and `KotlinType` to handle primitive and `String?` optional types.
…ion of primitives, UByteArrays and optionals
@RandVid RandVid changed the title Kotlin/Native: class/struct bridging and global variables Kotlin/Native: class/struct bridging and global variables🫪 Jun 29, 2026
@RandVid

RandVid commented Jun 29, 2026

Copy link
Copy Markdown
Owner Author

😪

@RandVid RandVid requested a review from mMaxy June 29, 2026 13:25
@RandVid RandVid force-pushed the class-impl branch 2 times, most recently from 3e6dda4 to 6ab0866 Compare July 2, 2026 11:14
Ilya Plisko added 3 commits July 2, 2026 17:37
…well as global variables

- Extend `KotlinNativeSwift2KotlinGenerator` to generate Kotlin/Native wrapper classes for Swift nominal types.
- Ensure proper memory management via `SwiftHandle` with cleanup using GC `createCleaner` or explicit `close()`.
- Add global variable export with getter and setter wrappers
- Remove support for structs in Kotlin/Native wrapper generation.
- Migrate memory management from `SwiftHandle` to `NSObject` for improved interoperability.
- Update `Counter` test cases
- Modify `nativeThunkName` logic to sanitize Cinterop symbols for Kotlin/Native compatibility.
- Adjust Gradle build output structure to resolve IntelliJ indexing issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant