Skip to content

Commit

Permalink
wasm gc: preprocess JS runtime with closure compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
konsoletyper committed Oct 9, 2024
1 parent f61d893 commit 0aefad0
Show file tree
Hide file tree
Showing 6 changed files with 720 additions and 1 deletion.
38 changes: 38 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ plugins {

description = "Compiler, backends and runtime"

configurations {
register("closureCompiler")
}

dependencies {
"closureCompiler"(libs.google.closure.compiler)

api(project(":interop:core"))
api(project(":metaprogramming:api"))

Expand All @@ -35,6 +41,38 @@ dependencies {
testImplementation(libs.junit)
}

val jsGenerateDir = layout.buildDirectory.dir("generated/js/raw")
val jsOutputDir = layout.buildDirectory.dir("generated/js/optimized")
val jsInputDir = layout.projectDirectory.dir("src/main/js/wasm-gc-runtime")
val jsInput = jsInputDir.file("runtime.js")

val simpleRuntime = tasks.register("generateSimpleRuntime") {
val outputFile = jsGenerateDir.map { it.file("wasm-gc-runtime.js") }
val wrapperFile = jsInputDir.file("simple-wrapper.js")
inputs.file(wrapperFile)
outputs.file(outputFile)
doFirst {
val wrapper = wrapperFile.asFile.readText()
val runtime = jsInput.asFile.readText()
outputFile.get().asFile.writeText(wrapper.replace("include();", runtime))
}
}

tasks.register<JavaExec>("optimizeSimpleRuntime") {
val inputFiles = simpleRuntime.map { it.outputs.files }
classpath(configurations["closureCompiler"])
inputs.file(inputFiles)
mainClass = "com.google.javascript.jscomp.CommandLineRunner"

args(Iterable {
listOf(
"--compilation_level=SIMPLE_OPTIMIZATIONS",
"--js_output_file=" + jsOutputDir.get().asFile.absolutePath + "/wasm-gc-runtime.js",
inputFiles.get().singleFile.absolutePath
).iterator()
})
}

teavmPublish {
artifactId = "teavm-core"
}
18 changes: 18 additions & 0 deletions core/src/main/js/wasm-gc-runtime/module-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2024 Alexey Andreev.
*
* 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.
*/

include();
export { load, defaults };
Loading

0 comments on commit 0aefad0

Please sign in to comment.