diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt index 30907e6f48e..44182794919 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.gradle.plugin.sources.SourceSetConsistencyChecks import org.jetbrains.kotlin.gradle.util.checkBytecodeContains import org.jetbrains.kotlin.gradle.util.isWindows import org.jetbrains.kotlin.gradle.util.modify +import org.jetbrains.kotlin.konan.target.CompilerOutputKind import org.jetbrains.kotlin.konan.target.HostManager import org.junit.Assert import org.junit.Test @@ -398,7 +399,12 @@ class NewMultiplatformIT : BaseGradleIT() { @Test fun testPublishingOnlySupportedNativeTargets() = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) { - val (publishedVariant, nonPublishedVariant) = listOf("mingw64", "linux64").let { if (!isWindows) it.reversed() else it } + val (publishedVariant, nonPublishedVariant) = when { + HostManager.hostIsMac -> "macos64" to "linux64" + HostManager.hostIsLinux -> "linux64" to "macos64" + HostManager.hostIsMingw -> "mingw64" to "linux64" + else -> error("Unknown host") + } build("publish") { assertSuccessful() @@ -445,4 +451,65 @@ class NewMultiplatformIT : BaseGradleIT() { assertContains("Declaration annotated with '@OptionalExpectation' can only be used in common module sources") } } + + @Test + fun testCanProduceNativeLibraries() = with(Project("new-mpp-native-libraries", gradleVersion)) { + val hostTargetName = when { + HostManager.hostIsMingw -> "mingw64" + HostManager.hostIsLinux -> "linux64" + HostManager.hostIsMac -> "macos64" + else -> error("Unknown host") + } + val baseName = "native_lib" + + val sharedPrefix = CompilerOutputKind.DYNAMIC.prefix(HostManager.host) + val sharedSuffix = CompilerOutputKind.DYNAMIC.suffix(HostManager.host) + val sharedPaths = listOf( + "build/bin/$hostTargetName/main/debug/shared/$sharedPrefix$baseName$sharedSuffix", + "build/bin/$hostTargetName/main/release/shared/$sharedPrefix$baseName$sharedSuffix" + ) + + val staticPrefix = CompilerOutputKind.STATIC.prefix(HostManager.host) + val staticSuffix = CompilerOutputKind.STATIC.suffix(HostManager.host) + val staticPaths = listOf( + "build/bin/$hostTargetName/main/debug/static/$staticPrefix$baseName$staticSuffix", + "build/bin/$hostTargetName/main/release/static/$staticPrefix$baseName$staticSuffix" + ) + + val headerPaths = listOf( + "build/bin/$hostTargetName/main/debug/shared/$sharedPrefix${baseName}_api.h", + "build/bin/$hostTargetName/main/release/shared/$sharedPrefix${baseName}_api.h", + "build/bin/$hostTargetName/main/debug/static/$staticPrefix${baseName}_api.h", + "build/bin/$hostTargetName/main/release/static/$staticPrefix${baseName}_api.h" + ) + + val taskSuffix = hostTargetName.capitalize() + val linkTasks = listOf( + ":linkMainDebugShared$taskSuffix", + ":linkMainReleaseShared$taskSuffix", + ":linkMainDebugStatic$taskSuffix", + ":linkMainReleaseStatic$taskSuffix" + ) + + build("assemble") { + assertSuccessful() + + sharedPaths.forEach { assertFileExists(it) } + staticPaths.forEach { assertFileExists(it) } + headerPaths.forEach { assertFileExists(it) } + } + + build("assemble") { + assertSuccessful() + assertTasksUpToDate(linkTasks) + } + + assertTrue(projectDir.resolve(headerPaths[0]).delete()) + + build("assemble") { + assertSuccessful() + assertTasksUpToDate(linkTasks.drop(1)) + assertTasksExecuted(linkTasks[0]) + } + } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-libraries/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-libraries/build.gradle new file mode 100644 index 00000000000..ff6bc7ef586 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-libraries/build.gradle @@ -0,0 +1,32 @@ +group 'com.example' +version '1.0' + +buildscript { + repositories { + mavenLocal() + jcenter() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin-multiplatform' + +repositories { + mavenLocal() + jcenter() + maven { url "http://dl.bintray.com/kotlin/kotlinx.html/" } +} + +kotlin { + targets { + fromPreset(presets.macosX64, 'macos64') + fromPreset(presets.linuxX64, 'linux64') + fromPreset(presets.mingwX64, 'mingw64') + + configure([linux64, mingw64, macos64]) { + compilations.main.outputKinds 'DYNAMIC', 'STATIC' + } + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-libraries/settings.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-libraries/settings.gradle new file mode 100644 index 00000000000..7f1e2a4075c --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-libraries/settings.gradle @@ -0,0 +1,3 @@ +enableFeaturePreview('GRADLE_METADATA') + +rootProject.name = 'native-lib' \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-libraries/src/commonMain/kotlin/main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-libraries/src/commonMain/kotlin/main.kt new file mode 100644 index 00000000000..e46a523bbeb --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-libraries/src/commonMain/kotlin/main.kt @@ -0,0 +1,6 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +fun answer() = 42 \ No newline at end of file