diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index c2cc7625ce7..fa7cce225a4 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -3394,6 +3394,14 @@ createInterop("cmangling2") { it.defFile 'interop/basics/mangling2.def' } +createInterop("auxiliaryCppSources") { + // We need to provide empty def file to create correct `KonanInteropTask`. + it.defFile 'interop/auxiliary_sources/auxiliaryCppSources.def' + it.headers "$projectDir/interop/auxiliary_sources/name.h" + it.extraOpts "-Xcompile-source", "$projectDir/interop/auxiliary_sources/name.cpp" + it.extraOpts "-Xsource-compiler-option", "-std=c++17" +} + if (PlatformInfo.isAppleTarget(project)) { createInterop("objcSmoke") { it.defFile 'interop/objc/objcSmoke.def' @@ -3563,6 +3571,12 @@ interopTest("interop_mangling2") { interop = 'cmangling2' } +interopTest("interop_auxiliarySources") { + disabled = (project.testTarget == 'wasm32') // No interop for wasm yet. + source = "interop/auxiliary_sources/main.kt" + interop = 'auxiliaryCppSources' +} + interopTest("interop_values") { disabled = (project.testTarget == 'wasm32') // No interop for wasm yet. source = "interop/basics/values.kt" diff --git a/backend.native/tests/interop/auxiliary_sources/auxiliaryCppSources.def b/backend.native/tests/interop/auxiliary_sources/auxiliaryCppSources.def new file mode 100644 index 00000000000..e69de29bb2d diff --git a/backend.native/tests/interop/auxiliary_sources/main.kt b/backend.native/tests/interop/auxiliary_sources/main.kt new file mode 100644 index 00000000000..69873293e18 --- /dev/null +++ b/backend.native/tests/interop/auxiliary_sources/main.kt @@ -0,0 +1,7 @@ +import auxiliaryCppSources.* +import kotlin.test.* +import kotlinx.cinterop.* + +fun main() { + assertEquals(name()!!.toKString(), "Hello from C++") +} \ No newline at end of file diff --git a/backend.native/tests/interop/auxiliary_sources/name.cpp b/backend.native/tests/interop/auxiliary_sources/name.cpp new file mode 100644 index 00000000000..14f6b211d85 --- /dev/null +++ b/backend.native/tests/interop/auxiliary_sources/name.cpp @@ -0,0 +1,8 @@ +#include +#include "name.h" + +static std::string _name = "Hello from C++"; + +const char* name() { + return _name.c_str(); +} \ No newline at end of file diff --git a/backend.native/tests/interop/auxiliary_sources/name.h b/backend.native/tests/interop/auxiliary_sources/name.h new file mode 100644 index 00000000000..9235363abdb --- /dev/null +++ b/backend.native/tests/interop/auxiliary_sources/name.h @@ -0,0 +1,9 @@ +#ifdef __cplusplus +extern "C" { +#endif + +const char* name(); + +#ifdef __cplusplus +} +#endif \ No newline at end of file