From 94c50dd1bcdf46db87596166600d8842abbd0d07 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 14 Oct 2024 20:37:32 +0200 Subject: [PATCH] wasm gc: support source map in gradle plugin --- samples/benchmark/build.gradle.kts | 1 + tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java | 1 + .../src/main/java/org/teavm/gradle/TeaVMExtensionImpl.java | 1 + tools/gradle/src/main/java/org/teavm/gradle/TeaVMPlugin.java | 1 + .../java/org/teavm/gradle/api/TeaVMWasmGCConfiguration.java | 2 ++ .../main/java/org/teavm/gradle/tasks/GenerateWasmGCTask.java | 5 +++++ 6 files changed, 11 insertions(+) diff --git a/samples/benchmark/build.gradle.kts b/samples/benchmark/build.gradle.kts index db9565d10..6144fa866 100644 --- a/samples/benchmark/build.gradle.kts +++ b/samples/benchmark/build.gradle.kts @@ -54,6 +54,7 @@ teavm { wasmGC { addedToWebApp = true mainClass = "org.teavm.samples.benchmark.teavm.BenchmarkStarter" + sourceMap = true } wasm { addedToWebApp = true diff --git a/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java b/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java index d5cdfc837..b30b994fe 100644 --- a/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java +++ b/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java @@ -407,6 +407,7 @@ public class TeaVMTool { target.setDebugInfoLevel(debugInformationGenerated ? WasmDebugInfoLevel.FULL : wasmDebugInfoLevel); target.setDebugInfoLocation(wasmDebugInfoLocation); if (sourceMapsFileGenerated) { + wasmSourceMapWriter = new SourceMapBuilder(); target.setSourceMapBuilder(wasmSourceMapWriter); target.setSourceMapLocation(getResolvedTargetFileName() + ".map"); } diff --git a/tools/gradle/src/main/java/org/teavm/gradle/TeaVMExtensionImpl.java b/tools/gradle/src/main/java/org/teavm/gradle/TeaVMExtensionImpl.java index b15efca44..e494c7b3e 100644 --- a/tools/gradle/src/main/java/org/teavm/gradle/TeaVMExtensionImpl.java +++ b/tools/gradle/src/main/java/org/teavm/gradle/TeaVMExtensionImpl.java @@ -119,6 +119,7 @@ class TeaVMExtensionImpl extends TeaVMBaseExtensionImpl implements TeaVMExtensio .map(v -> WasmDebugInfoLocation.valueOf(v.toUpperCase())).orElse(WasmDebugInfoLocation.EXTERNAL)); wasmGC.getDebugInfoLevel().convention(property("wasm-gc.debugInformation.level") .map(v -> WasmDebugInfoLevel.valueOf(v.toUpperCase())).orElse(WasmDebugInfoLevel.DEOBFUSCATION)); + wasmGC.getSourceMap().convention(property("wasm-gc.sourceMap").map(Boolean::parseBoolean).orElse(false)); } private void setupWasiDefaults() { diff --git a/tools/gradle/src/main/java/org/teavm/gradle/TeaVMPlugin.java b/tools/gradle/src/main/java/org/teavm/gradle/TeaVMPlugin.java index 5d824a484..263f93242 100644 --- a/tools/gradle/src/main/java/org/teavm/gradle/TeaVMPlugin.java +++ b/tools/gradle/src/main/java/org/teavm/gradle/TeaVMPlugin.java @@ -225,6 +225,7 @@ public class TeaVMPlugin implements Plugin { task.getTargetFileName().convention(wasmGC.getTargetFileName()); task.getObfuscated().convention(wasmGC.getObfuscated()); task.getStrict().convention(wasmGC.getStrict()); + task.getSourceMap().convention(wasmGC.getSourceMap()); }); project.getTasks().create(WASM_GC_COPY_RUNTIME_TASK_NAME, CopyWasmGCRuntimeTask.class, task -> { task.setGroup(TASK_GROUP); diff --git a/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMWasmGCConfiguration.java b/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMWasmGCConfiguration.java index bac4bb61c..f4e73bdba 100644 --- a/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMWasmGCConfiguration.java +++ b/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMWasmGCConfiguration.java @@ -31,4 +31,6 @@ public interface TeaVMWasmGCConfiguration extends TeaVMCommonConfiguration, TeaV Property getDebugInfoLocation(); Property getDebugInfoLevel(); + + Property getSourceMap(); } diff --git a/tools/gradle/src/main/java/org/teavm/gradle/tasks/GenerateWasmGCTask.java b/tools/gradle/src/main/java/org/teavm/gradle/tasks/GenerateWasmGCTask.java index 18922b242..e524e3d75 100644 --- a/tools/gradle/src/main/java/org/teavm/gradle/tasks/GenerateWasmGCTask.java +++ b/tools/gradle/src/main/java/org/teavm/gradle/tasks/GenerateWasmGCTask.java @@ -29,6 +29,7 @@ public abstract class GenerateWasmGCTask extends TeaVMTask { getDebugInfo().convention(true); getDebugInfoLevel().convention(WasmDebugInfoLevel.DEOBFUSCATION); getDebugInfoLocation().convention(WasmDebugInfoLocation.EXTERNAL); + getSourceMap().convention(false); } @Input @@ -46,11 +47,15 @@ public abstract class GenerateWasmGCTask extends TeaVMTask { @Input public abstract Property getDebugInfoLocation(); + @Input + public abstract Property getSourceMap(); + @Override protected void setupBuilder(BuildStrategy builder) { builder.setStrict(getStrict().get()); builder.setObfuscated(getObfuscated().get()); builder.setDebugInformationGenerated(getDebugInfo().get()); + builder.setSourceMapsFileGenerated(getSourceMap().get()); switch (getDebugInfoLevel().get()) { case FULL: builder.setWasmDebugInfoLevel(org.teavm.backend.wasm.WasmDebugInfoLevel.FULL);