-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Wasm] Setup and configure binaryen per project
^KT-74840 fixed
- Loading branch information
Showing
15 changed files
with
223 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...on-tests/src/test/resources/testProject/wasm-browser-several-modules/bar/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.multiplatform") | ||
} | ||
|
||
|
||
kotlin { | ||
wasmJs { | ||
binaries.executable() | ||
browser { | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...rc/test/resources/testProject/wasm-browser-several-modules/bar/src/wasmJsMain/kotlin/A.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
*/ | ||
|
||
fun main() { | ||
println("Hello, world") | ||
} |
12 changes: 12 additions & 0 deletions
12
...on-tests/src/test/resources/testProject/wasm-browser-several-modules/foo/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.multiplatform") | ||
} | ||
|
||
|
||
kotlin { | ||
wasmJs { | ||
binaries.executable() | ||
browser { | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...rc/test/resources/testProject/wasm-browser-several-modules/foo/src/wasmJsMain/kotlin/A.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
*/ | ||
|
||
fun main() { | ||
println("Hello, world") | ||
} |
2 changes: 2 additions & 0 deletions
2
...ion-tests/src/test/resources/testProject/wasm-browser-several-modules/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include("foo") | ||
include("bar") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...lugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/binaryen/BinaryenPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2010-2020 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.gradle.targets.js.binaryen | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.plugins.BasePlugin | ||
import org.gradle.api.plugins.ExtensionContainer | ||
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl | ||
import org.jetbrains.kotlin.gradle.internal.unameExecResult | ||
import org.jetbrains.kotlin.gradle.targets.js.MultiplePluginDeclarationDetector | ||
import org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenPlatform.Companion.parseBinaryenPlatform | ||
import org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenExtension.Companion.EXTENSION_NAME | ||
import org.jetbrains.kotlin.gradle.tasks.CleanDataTask | ||
import org.jetbrains.kotlin.gradle.tasks.registerTask | ||
import org.jetbrains.kotlin.gradle.utils.castIsolatedKotlinPluginClassLoaderAware | ||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly | ||
|
||
@OptIn(ExperimentalWasmDsl::class) | ||
abstract class BinaryenPlugin internal constructor() : Plugin<Project> { | ||
override fun apply(project: Project) { | ||
MultiplePluginDeclarationDetector.detect(project) | ||
|
||
project.plugins.apply(BasePlugin::class.java) | ||
|
||
val spec = project.extensions.createBinaryenEnvSpec() | ||
|
||
val settings = project.extensions.create( | ||
EXTENSION_NAME, | ||
BinaryenExtension::class.java, | ||
project, | ||
spec | ||
) | ||
|
||
spec.initializeBinaryenRootEnvSpec(settings) | ||
|
||
addPlatform(project, settings) | ||
|
||
project.registerTask<BinaryenSetupTask>(BinaryenSetupTask.NAME, listOf(spec)) { | ||
it.group = TASKS_GROUP_NAME | ||
it.description = "Download and install a binaryen" | ||
it.configuration = it.ivyDependencyProvider.map { ivyDependency -> | ||
project.configurations.detachedConfiguration(project.dependencies.create(ivyDependency)) | ||
.also { conf -> conf.isTransitive = false } | ||
} | ||
} | ||
|
||
project.registerTask<CleanDataTask>("binaryen" + CleanDataTask.NAME_SUFFIX) { | ||
it.cleanableStoreProvider = project.provider { settings.requireConfigured().cleanableStore } | ||
it.group = TASKS_GROUP_NAME | ||
it.description = "Clean unused local binaryen version" | ||
} | ||
} | ||
|
||
private fun ExtensionContainer.createBinaryenEnvSpec(): BinaryenEnvSpec { | ||
return create( | ||
BinaryenEnvSpec.EXTENSION_NAME, | ||
BinaryenEnvSpec::class.java | ||
) | ||
} | ||
|
||
private fun BinaryenEnvSpec.initializeBinaryenRootEnvSpec( | ||
rootBinaryen: BinaryenExtension, | ||
) { | ||
download.convention(rootBinaryen.downloadProperty) | ||
downloadBaseUrl.convention(rootBinaryen.downloadBaseUrlProperty) | ||
allowInsecureProtocol.convention(false) | ||
installationDirectory.convention(rootBinaryen.installationDirectory) | ||
version.convention(rootBinaryen.versionProperty) | ||
command.convention(rootBinaryen.commandProperty) | ||
platform.convention(rootBinaryen.platform) | ||
} | ||
|
||
private fun addPlatform(project: Project, extension: BinaryenExtension) { | ||
val uname = project.providers.unameExecResult | ||
|
||
extension.platform.value( | ||
project.providers.systemProperty("os.name") | ||
.zip( | ||
project.providers.systemProperty("os.arch") | ||
) { name, arch -> | ||
parseBinaryenPlatform(name.toLowerCaseAsciiOnly(), arch, uname) | ||
} | ||
).disallowChanges() | ||
} | ||
|
||
companion object { | ||
const val TASKS_GROUP_NAME: String = "binaryen" | ||
|
||
fun apply(project: Project): BinaryenExtension { | ||
project.plugins.apply(BinaryenPlugin::class.java) | ||
return project.extensions.getByName(EXTENSION_NAME) as BinaryenExtension | ||
} | ||
|
||
val Project.kotlinBinaryenExtension: BinaryenExtension | ||
get() = extensions.getByName(EXTENSION_NAME).castIsolatedKotlinPluginClassLoaderAware() | ||
} | ||
} |
Oops, something went wrong.