From f05110f99bfaf1929f6c55b3317a955c244fd39d Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Tue, 6 Jul 2021 14:55:00 +0700 Subject: [PATCH] [K/N] Add some tests for https://youtrack.jetbrains.com/issue/KT-47605 --- .../backend.native/tests/build.gradle | 42 +++++++++++++++++++ .../tests/interop/mingw_dll_linkage/library.c | 5 +++ .../tests/interop/mingw_dll_linkage/library.h | 1 + .../tests/interop/mingw_dll_linkage/main.kt | 7 ++++ 4 files changed, 55 insertions(+) create mode 100644 kotlin-native/backend.native/tests/interop/mingw_dll_linkage/library.c create mode 100644 kotlin-native/backend.native/tests/interop/mingw_dll_linkage/library.h create mode 100644 kotlin-native/backend.native/tests/interop/mingw_dll_linkage/main.kt diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 9874d52a366..b1e513e9aac 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -4315,6 +4315,48 @@ interopTest("interop_cppSkia") { goldValue = "17 17\n" } +/** + * Check that compiler properly reports linker options that aren't supported by LLD. + * @param withImportLibrary create an import library if true. Thus, LLD shoudn't complain. + * @param shouldShowWarning compiler should show warning from LLD if true. + * @param compilerFlags additional flags that will be passed to Kotlin/Native. + */ +void driverCheckLldCompatibilityTest(String taskName, boolean withImportLibrary, boolean shouldShowWarning, List compilerFlags) { + tasks.register(taskName, KonanDriverTest) { + source = "interop/mingw_dll_linkage/main.kt" + + flags = ["-linker-option", "-lrary", "-linker-option", "-L", "-linker-option", "$buildDir/$taskName"] + + compilerFlags + + compilerMessages = true + goldValue = "lld doesn't support linking directly against" + outputChecker = { out -> + shouldShowWarning ? out.contains(goldValue) : !out.contains(goldValue) + } + + doBeforeBuild { + mkdir("$buildDir/$taskName") + execClangForCompilerTests(project.target) { + args "$projectDir/interop/mingw_dll_linkage/library.c" + args '-shared', '-o', "$buildDir/$taskName/library.dll" + if (withImportLibrary) { + args "-Wl,--out-implib", "-Wl,$buildDir/$taskName/library.dll.a" + } + } + copy { + from("$buildDir/$taskName/library.dll") + into("$testOutputLocal/$name/$target/") + } + } + } +} + +if (isWindowsTarget(project)) { + driverCheckLldCompatibilityTest("driver_lld_with_import_library", true, false, []) + driverCheckLldCompatibilityTest("driver_lld_without_import_library", false, true, []) + driverCheckLldCompatibilityTest("driver_lld_without_import_library_no_check", false, false, ["-Xcheck-compatibility-with-lld=disable"]) +} + /* TODO: This test isn't run automatically task interop_echo_server(type: RunInteropKonanTest) { diff --git a/kotlin-native/backend.native/tests/interop/mingw_dll_linkage/library.c b/kotlin-native/backend.native/tests/interop/mingw_dll_linkage/library.c new file mode 100644 index 00000000000..19a100dd427 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/mingw_dll_linkage/library.c @@ -0,0 +1,5 @@ +#include "library.h" + +int f() { + return 43; +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/mingw_dll_linkage/library.h b/kotlin-native/backend.native/tests/interop/mingw_dll_linkage/library.h new file mode 100644 index 00000000000..b8f5e87c81e --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/mingw_dll_linkage/library.h @@ -0,0 +1 @@ +int f(); \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/mingw_dll_linkage/main.kt b/kotlin-native/backend.native/tests/interop/mingw_dll_linkage/main.kt new file mode 100644 index 00000000000..755f4850eec --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/mingw_dll_linkage/main.kt @@ -0,0 +1,7 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +fun main() { +} \ No newline at end of file