Skip to content

Commit

Permalink
wasm gc: add Maven mojo that copies runtime, add more Maven compilati…
Browse files Browse the repository at this point in the history
…on properties for Wasm GC
  • Loading branch information
konsoletyper committed Oct 18, 2024
1 parent c7a9b52 commit 797ceb9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/maven/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ description = "A set of mojos that allow to include TeaVM compiler into maven bu
dependencies {
implementation(project(":core"))
implementation(project(":tools:core"))
implementation(project(":tools:deobfuscator-wasm-gc"))
}

teavmPublish {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.teavm.backend.javascript.JSModuleType;
import org.teavm.backend.wasm.WasmDebugInfoLocation;
import org.teavm.backend.wasm.render.WasmBinaryVersion;
import org.teavm.tooling.TeaVMProblemRenderer;
import org.teavm.tooling.TeaVMSourceFilePolicy;
Expand Down Expand Up @@ -96,6 +97,9 @@ public class TeaVMCompileMojo extends AbstractMojo {
@Parameter(property = "teavm.debugInformationGenerated", defaultValue = "false")
private boolean debugInformationGenerated;

@Parameter(property = "teavm.debugInfoLocation", defaultValue = "EXTERNAL")
private WasmDebugInfoLocation wasmDebugInfoLocation = WasmDebugInfoLocation.EXTERNAL;

@Parameter(property = "teavm.sourceMapsGenerated", defaultValue = "false")
private boolean sourceMapsGenerated;

Expand Down Expand Up @@ -189,6 +193,7 @@ private void setupBuilder(BuildStrategy builder) throws MojoExecutionException {
}
builder.setIncremental(incremental);
builder.setDebugInformationGenerated(debugInformationGenerated);
builder.setWasmDebugInfoLocation(wasmDebugInfoLocation);
builder.setSourceMapsFileGenerated(sourceMapsGenerated);
builder.setSourceFilePolicy(sourceFilesCopied
? TeaVMSourceFilePolicy.COPY
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2024 konsoletyper.
*
* 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.
*/
package org.teavm.maven;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

@Mojo(name = "copy-webassembly-gc-runtime", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
public class TeaVMCopyWebassemblyGCRuntimeMojo extends AbstractMojo {
@Parameter(defaultValue = "${project.build.directory}/javascript")
private File targetDirectory;

@Parameter(property = "teavm.wasmGC.runtime.fileName", defaultValue = "classes.wasm-runtime.js")
private String runtimeFileName;

@Parameter(property = "teavm.wasmGC.deobfuscator.fileName", defaultValue = "classes.wasm-deobfuscator.wasm")
private String deobfuscatorFileName;

@Parameter(property = "teavm.wasmGC.runtime.minified", defaultValue = "true")
private boolean minified;

@Parameter(property = "teavm.wasmGC.runtime.modular", defaultValue = "false")
private boolean modular;

@Parameter(property = "teavm.wasmGC.runtime.deobfuscator", defaultValue = "false")
private boolean deobfuscator;

@Override
public void execute() throws MojoExecutionException {
try {
var name = new StringBuilder("wasm-gc");
if (modular) {
name.append("-modular");
}
name.append("-runtime");
if (minified) {
name.append(".min");
}
var resourceName = "org/teavm/backend/wasm/" + name + ".js";
var classLoader = TeaVMCopyWebassemblyGCRuntimeMojo.class.getClassLoader();
var output = new File(targetDirectory, runtimeFileName);
try (var input = classLoader.getResourceAsStream(resourceName)) {
Files.copy(input, output.toPath(), StandardCopyOption.REPLACE_EXISTING);
}

if (deobfuscator) {
resourceName = "org/teavm/backend/wasm/deobfuscator.wasm";
output = new File(targetDirectory, deobfuscatorFileName);
try (var input = classLoader.getResourceAsStream(resourceName)) {
Files.copy(input, output.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
} catch (IOException e) {
throw new MojoExecutionException("Failed to copy webassembly runtime", e);
}
}
}

0 comments on commit 797ceb9

Please sign in to comment.