[Gradle, Wasm] Add wasm platform kind
KTIJ-25583
This commit is contained in:
committed by
Space Team
parent
04cb217791
commit
bcefa1cd66
@@ -42,6 +42,7 @@ fun TargetPlatform.createArguments(init: (CommonCompilerArguments).() -> Unit =
|
||||
jvmTarget = (single() as? JdkPlatform)?.targetVersion?.description ?: JvmTarget.DEFAULT.description
|
||||
}
|
||||
isJs() -> K2JSCompilerArguments().apply { init() }
|
||||
isWasm() -> K2JSCompilerArguments().apply { init() }
|
||||
isNative() -> K2NativeCompilerArguments().apply { init() }
|
||||
else -> error("Unknown platform $this")
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
import org.jetbrains.kotlin.platform.impl.WasmIdePlatformKind
|
||||
|
||||
abstract class IdePlatformKind {
|
||||
abstract fun supportsTargetPlatform(platform: TargetPlatform): Boolean
|
||||
@@ -54,6 +54,7 @@ abstract class IdePlatformKind {
|
||||
get() = listOf(
|
||||
JvmIdePlatformKind,
|
||||
JsIdePlatformKind,
|
||||
WasmIdePlatformKind,
|
||||
CommonIdePlatformKind,
|
||||
NativeIdePlatformKind
|
||||
)
|
||||
|
||||
@@ -15,12 +15,15 @@ import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.JsPlatform
|
||||
import org.jetbrains.kotlin.platform.WasmPlatform
|
||||
import org.jetbrains.kotlin.platform.impl.WasmIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||
import org.jetbrains.kotlin.platform.jvm.JdkPlatform
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatform
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
import org.jetbrains.kotlin.platform.konan.NativePlatforms
|
||||
import org.jetbrains.kotlin.platform.konan.NativePlatform
|
||||
import org.jetbrains.kotlin.platform.wasm.WasmPlatforms
|
||||
|
||||
typealias OldPlatform = org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
typealias NewPlatform = org.jetbrains.kotlin.platform.TargetPlatform
|
||||
@@ -51,6 +54,7 @@ fun IdePlatform<*, *>.toNewPlatform(): NewPlatform = when (this) {
|
||||
is CommonIdePlatformKind.Platform -> CommonPlatforms.defaultCommonPlatform
|
||||
is JvmIdePlatformKind.Platform -> JvmPlatforms.jvmPlatformByTargetVersion(this.version)
|
||||
is JsIdePlatformKind.Platform -> JsPlatforms.defaultJsPlatform
|
||||
is WasmIdePlatformKind.Platform -> WasmPlatforms.Default
|
||||
is NativeIdePlatformKind.Platform -> NativePlatforms.unspecifiedNativePlatform
|
||||
else -> error("Unknown platform $this")
|
||||
}
|
||||
@@ -60,6 +64,7 @@ fun NewPlatform.toIdePlatform(): IdePlatform<*, *> = when (val single = singleOr
|
||||
is JdkPlatform -> JvmIdePlatformKind.Platform(single.targetVersion)
|
||||
is JvmPlatform -> JvmIdePlatformKind.Platform(JvmTarget.DEFAULT)
|
||||
is JsPlatform -> JsIdePlatformKind.Platform
|
||||
is WasmPlatform -> WasmIdePlatformKind.Platform
|
||||
is NativePlatform -> NativeIdePlatformKind.Platform
|
||||
else -> error("Unknown platform $single")
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ object JsIdePlatformKind : IdePlatformKind() {
|
||||
override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platform.isJs()
|
||||
|
||||
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
|
||||
return if (arguments is K2JSCompilerArguments)
|
||||
return if (arguments is K2JSCompilerArguments && !arguments.wasm)
|
||||
JsPlatforms.defaultJsPlatform
|
||||
else
|
||||
null
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
@file:JvmName("WasmIdePlatformUtil")
|
||||
@file:Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith")
|
||||
|
||||
package org.jetbrains.kotlin.platform.impl
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.platform.*
|
||||
import org.jetbrains.kotlin.platform.wasm.WasmPlatforms
|
||||
|
||||
object WasmIdePlatformKind : IdePlatformKind() {
|
||||
override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platform.isWasm()
|
||||
|
||||
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
|
||||
return if (arguments is K2JSCompilerArguments && arguments.wasm)
|
||||
WasmPlatforms.Default
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
val platforms get() = listOf(WasmPlatforms.Default)
|
||||
override val defaultPlatform get() = WasmPlatforms.Default
|
||||
|
||||
@Deprecated(
|
||||
message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
override fun getDefaultPlatform(): IdePlatform<*, *> = WasmIdePlatformKind.Platform
|
||||
|
||||
override fun createArguments(): CommonCompilerArguments {
|
||||
return K2JSCompilerArguments()
|
||||
}
|
||||
|
||||
override val argumentsClass get() = K2JSCompilerArguments::class.java
|
||||
|
||||
override val name get() = "WebAssembly"
|
||||
|
||||
@Deprecated(
|
||||
message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
object Platform : IdePlatform<WasmIdePlatformKind, K2JSCompilerArguments>() {
|
||||
override val kind get() = WasmIdePlatformKind
|
||||
override val version get() = TargetPlatformVersion.NoVersion
|
||||
override fun createArguments(init: K2JSCompilerArguments.() -> Unit) = K2JSCompilerArguments().apply(init)
|
||||
}
|
||||
}
|
||||
|
||||
val IdePlatformKind?.isWasm
|
||||
get() = this is WasmIdePlatformKind
|
||||
Reference in New Issue
Block a user