[Gradle, Wasm] Not add target listeners for wasi projects
^KT-66373 fixed
This commit is contained in:
committed by
Space Team
parent
0bb6359ac5
commit
6fb6f04509
+14
-1
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.gradle
|
|||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.Distribution
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.Distribution
|
||||||
import org.jetbrains.kotlin.gradle.testbase.*
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.jetbrains.kotlin.gradle.util.modify
|
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import kotlin.io.path.writeText
|
import kotlin.io.path.writeText
|
||||||
@@ -186,4 +185,18 @@ class KotlinWasmGradlePluginIT : KGPBaseTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("Check mix project with wasi only dependency works correctly")
|
||||||
|
@GradleTest
|
||||||
|
fun jsAndWasiTargetsWithDependencyOnWasiOnlyProject(gradleVersion: GradleVersion) {
|
||||||
|
project("wasm-wasi-js-with-wasi-only-dependency", gradleVersion) {
|
||||||
|
buildGradleKts.modify(::transformBuildScriptWithPluginsDsl)
|
||||||
|
|
||||||
|
build("build") {
|
||||||
|
assertTasksExecuted(":lib:compileKotlinWasmWasi")
|
||||||
|
assertTasksExecuted(":app:compileProductionExecutableKotlinWasmJs")
|
||||||
|
assertTasksExecuted(":app:compileProductionExecutableKotlinWasmWasi")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
|
||||||
|
wasmWasi {
|
||||||
|
binaries.executable()
|
||||||
|
nodejs {}
|
||||||
|
}
|
||||||
|
|
||||||
|
wasmJs {
|
||||||
|
binaries.executable()
|
||||||
|
nodejs {}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
wasmJsMain {
|
||||||
|
dependencies {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wasmWasiMain {
|
||||||
|
dependencies {
|
||||||
|
implementation(project(":lib"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class B {
|
||||||
|
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform").version("<pluginMarkerVersion>").apply(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
|
||||||
|
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "20.2.0"
|
||||||
|
|
||||||
|
tasks.named<org.jetbrains.kotlin.gradle.targets.js.npm.LockCopyTask>("kotlinStorePackageLock") {
|
||||||
|
//A little hacky way to make yarn results
|
||||||
|
inputFile.fileValue(projectDir.resolve("packageLockStub"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.d8.D8RootPlugin> {
|
||||||
|
// Test that we can set the version and it is a String.
|
||||||
|
// But use the default version since update this place every time anyway.
|
||||||
|
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.d8.D8RootExtension>().version = (version as String)
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects.forEach {
|
||||||
|
it.tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask>().configureEach {
|
||||||
|
args.add("--ignore-engines")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
|
||||||
|
wasmWasi {
|
||||||
|
nodejs {}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class A
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
rootProject.name = "kotlin-wasm"
|
||||||
|
|
||||||
|
include("lib")
|
||||||
|
include("app")
|
||||||
+8
-6
@@ -12,10 +12,12 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
|
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
|
||||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtensionOrNull
|
import org.jetbrains.kotlin.gradle.dsl.kotlinExtensionOrNull
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.KotlinNpmResolutionManager
|
import org.jetbrains.kotlin.gradle.targets.js.npm.KotlinNpmResolutionManager
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.withType
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
@@ -24,7 +26,7 @@ import kotlin.reflect.KClass
|
|||||||
*/
|
*/
|
||||||
class KotlinProjectNpmResolver(
|
class KotlinProjectNpmResolver(
|
||||||
project: Project,
|
project: Project,
|
||||||
var resolver: KotlinRootNpmResolver
|
var resolver: KotlinRootNpmResolver,
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
val projectPath by lazy { project.path }
|
val projectPath by lazy { project.path }
|
||||||
|
|
||||||
@@ -52,19 +54,19 @@ class KotlinProjectNpmResolver(
|
|||||||
?: error("NpmResolverPlugin should be applied after kotlin plugin")
|
?: error("NpmResolverPlugin should be applied after kotlin plugin")
|
||||||
|
|
||||||
when (kotlin) {
|
when (kotlin) {
|
||||||
is KotlinSingleTargetExtension<*> -> addTargetListeners(kotlin.target)
|
is KotlinSingleTargetExtension<*> -> addTargetListeners(kotlin.target as KotlinJsIrTarget)
|
||||||
is KotlinMultiplatformExtension -> kotlin.targets.all {
|
is KotlinMultiplatformExtension -> kotlin.targets.withType<KotlinJsIrTarget>().configureEach {
|
||||||
addTargetListeners(it)
|
addTargetListeners(it)
|
||||||
}
|
}
|
||||||
else -> error("Unsupported kotlin model: $kotlin")
|
else -> error("Unsupported kotlin model: $kotlin")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addTargetListeners(target: KotlinTarget) {
|
private fun addTargetListeners(target: KotlinJsIrTarget) {
|
||||||
check(resolution == null) { resolver.alreadyResolvedMessage("add target $target") }
|
check(resolution == null) { resolver.alreadyResolvedMessage("add target $target") }
|
||||||
|
|
||||||
if (target.platformType == KotlinPlatformType.js ||
|
if (target.platformType == KotlinPlatformType.js ||
|
||||||
target.platformType == KotlinPlatformType.wasm
|
target.platformType == KotlinPlatformType.wasm && target.wasmTargetType != KotlinWasmTargetType.WASI
|
||||||
) {
|
) {
|
||||||
target.compilations.all { compilation ->
|
target.compilations.all { compilation ->
|
||||||
if (compilation is KotlinJsIrCompilation) {
|
if (compilation is KotlinJsIrCompilation) {
|
||||||
|
|||||||
Reference in New Issue
Block a user