[cinterop][tests] Add test for -Xcompile-source flag

This commit is contained in:
Sergey Bogolepov
2020-03-12 14:43:28 +07:00
committed by Sergey Bogolepov
parent 0715fa0369
commit da0e56edea
5 changed files with 38 additions and 0 deletions
+14
View File
@@ -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"
@@ -0,0 +1,7 @@
import auxiliaryCppSources.*
import kotlin.test.*
import kotlinx.cinterop.*
fun main() {
assertEquals(name()!!.toKString(), "Hello from C++")
}
@@ -0,0 +1,8 @@
#include <string>
#include "name.h"
static std::string _name = "Hello from C++";
const char* name() {
return _name.c_str();
}
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif
const char* name();
#ifdef __cplusplus
}
#endif