eagler-teavm-fork/core/build.gradle.kts

99 lines
3.3 KiB
Plaintext
Raw Normal View History

import com.github.gradle.node.npm.task.NpmTask
2019-01-24 05:28:30 -08:00
/*
2023-01-03 06:29:13 -08:00
* Copyright 2023 Alexey Andreev.
2019-01-24 05:28:30 -08:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2023-01-03 06:29:13 -08:00
plugins {
`java-library`
`teavm-publish`
alias(libs.plugins.nodejs)
2023-01-03 06:29:13 -08:00
}
description = "Compiler, backends and runtime"
2019-01-24 05:28:30 -08:00
node {
2024-10-11 09:09:27 -07:00
download = providers.gradleProperty("teavm.localNodeJS")
.map { it == "true" }
.map { !it }
.orElse(true)
}
2023-01-03 06:29:13 -08:00
dependencies {
api(project(":interop:core"))
api(project(":metaprogramming:api"))
2019-01-24 05:28:30 -08:00
2023-01-03 06:29:13 -08:00
implementation(libs.asm.commons)
implementation(libs.asm.util)
implementation(libs.hppc)
implementation(libs.rhino)
2019-01-24 05:28:30 -08:00
2023-01-03 06:29:13 -08:00
compileOnly(libs.jackson.annotations)
2019-01-24 05:28:30 -08:00
2023-01-03 06:29:13 -08:00
testImplementation(libs.junit)
2019-01-24 05:28:30 -08:00
}
2023-01-03 06:29:13 -08:00
val jsOutputDir = layout.buildDirectory.dir("generated/js")
val jsOutputPackageDir = jsOutputDir.map { it.dir("org/teavm/backend/wasm") }
val jsInputDir = layout.projectDirectory.dir("src/main/js/wasm-gc-runtime")
val jsInput = jsInputDir.file("runtime.js")
fun registerRuntimeTasks(taskName: String, wrapperType: String, outputName: String) {
val generateTask by tasks.register<DefaultTask>("generate${taskName}Runtime") {
val wrapperFile = jsInputDir.file(wrapperType)
val runtimeFile = jsInput
val outputFile = jsOutputPackageDir.map { it.file("$outputName.js") }
inputs.files(wrapperFile, runtimeFile)
outputs.file(outputFile)
doLast {
val wrapper = wrapperFile.asFile.readText()
var runtime = runtimeFile.asFile.readText()
val startText = "// !BEGINNING!\n"
val startIndex = runtime.indexOf(startText)
if (startIndex >= 0) {
runtime = runtime.substring(startIndex + startText.length)
}
outputFile.get().asFile.writeText(wrapper.replace("include();", runtime))
}
}
val optimizeTask = tasks.register<NpmTask>("optimize${taskName}Runtime") {
val inputFiles = generateTask.outputs.files
val outputFile = jsOutputPackageDir.map { it.file("$outputName.min.js") }
inputs.files(inputFiles)
outputs.file(outputFile)
npmCommand.addAll("run", "uglify")
args.addAll(provider {
listOf(
"--",
"-m", "--module", "--toplevel",
inputFiles.singleFile.absolutePath,
"-o", outputFile.get().asFile.absolutePath
)
})
}
sourceSets.main.configure {
output.dir(mapOf("builtBy" to generateTask), jsOutputDir)
output.dir(mapOf("builtBy" to optimizeTask), jsOutputDir)
}
}
registerRuntimeTasks("Simple", "simple-wrapper.js", "wasm-gc-runtime")
registerRuntimeTasks("Module", "module-wrapper.js", "wasm-gc-module-runtime")
2023-01-03 06:29:13 -08:00
teavmPublish {
artifactId = "teavm-core"
}