diff --git a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArgumentsCopyGenerated.kt b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArgumentsCopyGenerated.kt index 804abfaa053..2b281ed77c3 100644 --- a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArgumentsCopyGenerated.kt +++ b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArgumentsCopyGenerated.kt @@ -72,6 +72,7 @@ fun copyK2JSCompilerArguments(from: K2JSCompilerArguments, to: K2JSCompilerArgum to.wasmEnableAsserts = from.wasmEnableAsserts to.wasmGenerateWat = from.wasmGenerateWat to.wasmKClassFqn = from.wasmKClassFqn + to.wasmTarget = from.wasmTarget return to } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt index 4e2720faa09..963f7d3254d 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt @@ -623,6 +623,13 @@ class K2JSCompilerArguments : CommonCompilerArguments() { field = value } + @Argument(value = "-Xwasm-target", description = "Set up Wasm target (wasm-js or wasm-wasi)") + var wasmTarget: String? = null + set(value) { + checkFrozen() + field = if (value.isNullOrEmpty()) null else value + } + @Argument( value = "-Xforce-deprecated-legacy-compiler-usage", description = "The flag is used only for our inner infrastructure. It will be removed soon, so it's unsafe to use it nowadays." diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt index 47efb196829..11a2820f08d 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt @@ -169,6 +169,8 @@ class K2JsIrCompiler : CLICompiler() { configuration.put(JSConfigurationKeys.WASM_ENABLE_ARRAY_RANGE_CHECKS, arguments.wasmEnableArrayRangeChecks) configuration.put(JSConfigurationKeys.WASM_ENABLE_ASSERTS, arguments.wasmEnableAsserts) configuration.put(JSConfigurationKeys.WASM_GENERATE_WAT, arguments.wasmGenerateWat) + configuration.putIfNotNull(JSConfigurationKeys.WASM_TARGET, arguments.wasmTarget?.let(WasmTarget::fromName)) + configuration.put(JSConfigurationKeys.OPTIMIZE_GENERATED_JS, arguments.optimizeGeneratedJs) val commonSourcesArray = arguments.commonSources diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index 2fbec287c4c..627b35e9ad7 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -59,6 +59,7 @@ where advanced options include: -Xwasm-enable-asserts Turn on asserts -Xwasm-generate-wat Generate wat file -Xwasm-kclass-fqn Enable support for FQ names in KClass + -Xwasm-target Set up Wasm target (wasm-js or wasm-wasi) -Xallow-any-scripts-in-source-roots Allow to compile any scripts along with regular Kotlin sources -Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/config/JSConfigurationKeys.java b/js/js.frontend/src/org/jetbrains/kotlin/js/config/JSConfigurationKeys.java index 068d9606830..89607dcc9c7 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/config/JSConfigurationKeys.java +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/config/JSConfigurationKeys.java @@ -121,6 +121,9 @@ public class JSConfigurationKeys { public static final CompilerConfigurationKey WASM_GENERATE_WAT = CompilerConfigurationKey.create("generate wat file"); + public static final CompilerConfigurationKey WASM_TARGET = + CompilerConfigurationKey.create("wasm target"); + public static final CompilerConfigurationKey ZIP_FILE_SYSTEM_ACCESSOR = CompilerConfigurationKey.create("zip file system accessor, used for klib reading"); diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/config/WasmTarget.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/config/WasmTarget.kt new file mode 100644 index 00000000000..aacee5d1958 --- /dev/null +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/config/WasmTarget.kt @@ -0,0 +1,19 @@ +/* + * 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. + */ + +package org.jetbrains.kotlin.js.config + +enum class WasmTarget { + JS, + WASI; + + companion object { + fun fromName(name: String): WasmTarget? = when (name) { + "wasm-js" -> JS + "wasm-wasi" -> WASI + else -> null + } + } +} \ No newline at end of file