[Gradle, wasm] Hack for mixed mode with js, wasmJs and wasmWasi
^KT-61623 fixed
This commit is contained in:
committed by
Space Team
parent
cc60618e86
commit
0f40b2adce
+16
@@ -45,4 +45,20 @@ class KotlinWasmGradlePluginIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Check wasi and js target")
|
||||
@GradleTest
|
||||
fun wasiAndJsTarget(gradleVersion: GradleVersion) {
|
||||
project("new-mpp-wasm-wasi-js-test", gradleVersion) {
|
||||
buildGradleKts.modify(::transformBuildScriptWithPluginsDsl)
|
||||
|
||||
build("assemble") {
|
||||
assertTasksExecuted(":app:compileKotlinWasmWasi")
|
||||
assertTasksExecuted(":app:compileKotlinWasmJs")
|
||||
|
||||
assertTasksExecuted(":lib:compileKotlinWasmWasi")
|
||||
assertTasksExecuted(":lib:compileKotlinWasmJs")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
||||
wasmWasi {
|
||||
binaries.executable()
|
||||
nodejs {}
|
||||
}
|
||||
|
||||
wasmJs {
|
||||
binaries.executable()
|
||||
nodejs {}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val wasmJsMain by getting {
|
||||
dependencies {
|
||||
implementation(project(":lib"))
|
||||
}
|
||||
}
|
||||
|
||||
val wasmWasiMain by getting {
|
||||
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 {
|
||||
val a = A()
|
||||
}
|
||||
+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.yarn.YarnLockCopyTask>("kotlinStoreYarnLock") {
|
||||
//A little hacky way to make yarn results
|
||||
inputFile.fileValue(projectDir.resolve("yarnLockStub"))
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
||||
wasmWasi {
|
||||
nodejs {}
|
||||
}
|
||||
|
||||
wasmJs {
|
||||
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")
|
||||
+18
-5
@@ -9,8 +9,10 @@ import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.isMain
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType
|
||||
import org.jetbrains.kotlin.gradle.targets.js.NpmVersions
|
||||
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.nodejs.TasksRequirements
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinRootNpmResolution
|
||||
import java.io.File
|
||||
@@ -53,19 +55,30 @@ class KotlinRootNpmResolver internal constructor(
|
||||
if (mainCompilations.isEmpty()) return null
|
||||
|
||||
//TODO[Ilya Goncharov, Igor Iakovlev] Hack for Mixed mode of legacy and IR tooling and Wasm
|
||||
var containsWasm = false
|
||||
var containsWasmJs = false
|
||||
var containsWasmWasi = false
|
||||
var containsIrJs = false
|
||||
var containsLegacyJs = false
|
||||
val errorMessage = "Cannot resolve project dependency $src -> $target." +
|
||||
"Dependency to project with multiple js/wasm compilations is not supported yet."
|
||||
|
||||
check(mainCompilations.size <= 3) { errorMessage }
|
||||
// legacy + ir + wasmJs + wasmWasi
|
||||
val maxMainCompilationsCount = 4
|
||||
|
||||
check(mainCompilations.size <= maxMainCompilationsCount) { errorMessage }
|
||||
for (npmResolver in mainCompilations) {
|
||||
when (val compilation = npmResolver.compilation) {
|
||||
is KotlinJsIrCompilation -> {
|
||||
if (compilation.platformType == KotlinPlatformType.wasm) {
|
||||
check(!containsWasm) { errorMessage }
|
||||
containsWasm = true
|
||||
val jsTarget = compilation.target as KotlinJsIrTarget
|
||||
if (jsTarget.wasmTargetType == KotlinWasmTargetType.JS) {
|
||||
check(!containsWasmJs) { errorMessage }
|
||||
containsWasmJs = true
|
||||
}
|
||||
if (jsTarget.wasmTargetType == KotlinWasmTargetType.WASI) {
|
||||
check(!containsWasmWasi) { errorMessage }
|
||||
containsWasmWasi = true
|
||||
}
|
||||
} else {
|
||||
check(!containsIrJs) { errorMessage }
|
||||
containsIrJs = true
|
||||
@@ -78,7 +91,7 @@ class KotlinRootNpmResolver internal constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
check(containsWasm || containsIrJs || containsLegacyJs) { errorMessage }
|
||||
check(containsWasmJs || containsWasmWasi || containsIrJs || containsLegacyJs) { errorMessage }
|
||||
|
||||
return mainCompilations
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user