icerockdev / moko-kswift

Swift-friendly api generator for Kotlin/Native frameworks
https://moko.icerock.dev
Apache License 2.0
348 stars 21 forks source link

Resolve mangled names automatically #48

Open Alex009 opened 2 years ago

Alex009 commented 2 years ago

Kotlin/Native use mangling of conflicted names. For example with code:

interface A {
    fun test(value: Int)
}

interface B {
    fun test(value: String)
}

we got after compilation:

protocol A {
    func test(value: Int)
}

protocol B {
    func test(value_: String)
}

same will be with same classnames some.package.A, some.other.package.A will be A and A_.

now generated Swift code can't detect what name will be mangled. but we can use @KSwiftOverrideName annotation to give new name manually.

maybe we can resolve mangling automatically?

this code:

echo "import shared\n:type lookup shared" | \
    xcrun --sdk macosx swift -F../shared/build/cocoapods/framework/ | \
    tail -n+2 >| ./Sources/Shared/Shared.swift

generates swift api for compiled kotlin framework. and maybe we can find new name of kotlin definition using this generated swift code and swift-ast