https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
k

Kris Wong

01/29/2020, 5:13 PM
has anyone added a cinterop (Obj-C framework) to a test executable?
s

Sam Schilling

01/29/2020, 5:28 PM
I’ve imported the framework into an Xcode project that uses it to run its unit tests, not sure if that fits what you are describing
k

Kris Wong

01/29/2020, 5:36 PM
that's kind of the opposite
MPP output -> iOS unit tests instead of iOS framework -> MPP unit tests
i managed to accomplish this by building both a dynamic and static framework, grabbing the headers from the dynamic framework, and throwing them in a directory with the static framework library
kind of kludgy, but whatever
d

dambakk

01/29/2020, 6:18 PM
We're looking at testing now as well. Can you post your build file to do what you described?
k

Kris Wong

01/29/2020, 6:31 PM
i'll post the relevant section, but it's only one piece of the puzzle
Copy code
iosX64("ios") {
        compilations {
            "main" {
                dependencies {
                    implementation("suparnatural-kotlin-multiplatform:fs-iosx64:$suparnaturalVersion")
                }
            }
            "test" {
                cinterops.create("OHHTTPStubs") {
                    includeDirs("c_interop/OHHTTPStubs/Headers")
                }
            }
        }
        binaries.getTest(DEBUG).linkerOpts("-Lc_interop/OHHTTPStubs")
    }
k

kpgalligan

01/29/2020, 6:39 PM
I’ve built a test framework in the past, but don’t currently have that wired up. If you pass “-tr” into the compiler it’ll generate a test runner. You can call that entry point from swift/objc, and it’ll run the tests.
k

Kris Wong

01/29/2020, 6:57 PM
to be clear, I just wanted to link my existing text executable (the default one) to an obj-c framework
it needs to be static