Cinterop with C++

In the new kotlinx.datetime library the documentation states:


The implementation of date/time types, such as Instant, LocalDateTime, TimeZone and so on, relies on:

Indeed in the cinterop Gradle configuration code i noticed those lines:

    targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
        compilations["main"].cinterops {
            create("date") {
                val cinteropDir = "$projectDir/nativeMain/cinterop"
                val dateLibDir = "${project(":").projectDir}/thirdparty/date"
                // common options
                extraOpts("-Xsource-compiler-option", "-std=c++17")
                extraOpts("-Xsource-compiler-option", "-I$cinteropDir/public")
                extraOpts("-Xsource-compiler-option", "-include$cinteropDir/cpp/defines.hpp")
                // *nix support
                extraOpts("-Xcompile-source", "$dateLibDir/src/tz.cpp")
                extraOpts("-Xcompile-source", "$dateLibDir/src/")
                extraOpts("-Xsource-compiler-option", "-I$dateLibDir/include")
                extraOpts("-Xcompile-source", "$cinteropDir/cpp/cdate.cpp")
                // iOS support
                extraOpts("-Xcompile-source", "$cinteropDir/cpp/")
                // Windows support
                extraOpts("-Xcompile-source", "$cinteropDir/cpp/windows.cpp")

There are many .cpp file references and a manual cinterop compiler option to use C++17

Is there any documentation or roadmap for C++ cinterop-ing? :upside_down_face:

I remember reading that the headers for the time zone stuff is still plain C. So just the implementation part is C++. So you can use C++ as long as you only need access to C header files.

Yeah but what about

extraOpts("-Xsource-compiler-option", "-std=c++17")

My guess is that it compiles the code with a c++ compatible compiler but it exposes plain C functions so no interop between kotlin and c++ there.