maven: add archetype for WebAssembly GC target

This commit is contained in:
Alexey Andreev 2024-11-23 19:53:29 +01:00
parent 47c136ccc1
commit ff35ad3ed8
7 changed files with 215 additions and 2 deletions
settings.gradle.kts
tools/maven
webapp-wasm-gc
build.gradle.kts
src/main/resources
META-INF/maven
archetype-resources
webapp/src/main/resources/archetype-resources

View File

@ -49,6 +49,7 @@ include("tools:ide-deps")
include("tools:idea")
include("tools:maven:plugin")
include("tools:maven:webapp")
include("tools:maven:webapp-wasm-gc")
include("tools:classlib-comparison-gen")
include("tools:wasm-disassembly")
include("tests")

View File

@ -0,0 +1,34 @@
/*
* Copyright 2023 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.
*/
plugins {
java
publishing
`teavm-publish`
}
description = "An archetype that creates a simple Wasm GC web application"
tasks.processResources {
expand(
"teavmVersion" to version,
)
}
teavmPublish {
artifactId = "teavm-maven-webapp-wasm-gc"
packaging = "maven-archetype"
}

View File

@ -0,0 +1,20 @@
<archetype-descriptor xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0
http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
name="TeaVM web application" partial="false">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
</fileSet>
<fileSet filtered="true" packaged="false" encoding="UTF-8">
<directory>.</directory>
<includes>
<include>pom.xml</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="false" encoding="UTF-8">
<directory>src/main/webapp</directory>
</fileSet>
</fileSets>
</archetype-descriptor>

View File

@ -0,0 +1,122 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>\${groupId}</groupId>
<artifactId>\${artifactId}</artifactId>
<version>\${version}</version>
<packaging>war</packaging>
<properties>
<java.version>11</java.version>
<teavm.version>${teavmVersion}</teavm.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Emulator of Java class library for TeaVM -->
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>\${teavm.version}</version>
<scope>provided</scope>
</dependency>
<!-- JavaScriptObjects (JSO) - a JavaScript binding for TeaVM -->
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-apis</artifactId>
<version>\${teavm.version}</version>
<scope>provided</scope>
</dependency>
<!-- Servlet specification -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Configure Java compiler to use Java 8 syntax -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>\${java.version}</source>
<target>\${java.version}</target>
</configuration>
</plugin>
<!-- Configure WAR plugin to include JavaScript files generated by TeaVM -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<webResources>
<resource>
<directory>\${project.build.directory}/generated/wasm</directory>
</resource>
</webResources>
</configuration>
</plugin>
<!-- Configure TeaVM -->
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>\${teavm.version}</version>
<executions>
<execution>
<id>web-client-wasm</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<!-- Directory where TeaVM should put generated files. This configuration conforms to the settings
of the WAR plugin -->
<targetDirectory>\${project.build.directory}/generated/wasm/teavm</targetDirectory>
<targetType>WEBASSEMBLY_GC</targetType>
<!-- Main class, containing static void main(String[]) -->
<mainClass>\${package}.Client</mainClass>
<!-- Optimization level. Valid values are: SIMPLE, ADVANCED, FULL -->
<optimizationLevel>ADVANCED</optimizationLevel>
<!-- Whether TeaVM should produce Wasm file without `name` section. Reduces size
of wasm file, but makes it much more difficult to debug.
Disable during development, enable for production -->
<minifying>true</minifying>
<!-- Whether TeaVM should produce debug information for its built-in debugger.
Disuble for production -->
<debugInformationGenerated>true</debugInformationGenerated>
<!-- Whether TeaVM should produce source maps file.
Disuble for production -->-->
<sourceMapsGenerated>true</sourceMapsGenerated>
<!-- Whether TeaVM should also put source files into output directory,
for compatibility with source maps. Disable for production. -->
<sourceFilesCopied>true</sourceFilesCopied>
</configuration>
</execution>
<execution>
<id>web-client-runtime</id>
<goals>
<goal>copy-webassembly-gc-runtime</goal>
</goals>
<configuration>
<targetDirectory>\${project.build.directory}/generated/wasm/teavm</targetDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,12 @@
package \${package};
import org.teavm.jso.dom.html.HTMLDocument;
public class Client {
public static void main(String[] args) {
var document = HTMLDocument.current();
var div = document.createElement("div");
div.appendChild(document.createTextNode("TeaVM generated element"));
document.getBody().appendChild(div);
}
}

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Main page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" charset="utf-8" src="teavm/classes.wasm-runtime.js"></script>
<script>
async function main() {
let teavm = await TeaVM.wasmGC.load("teavm/classes.wasm", {
stackDeobfuscator: {
// set to true during development phase, as well as `debugInformationGenerated`
// option in pom.xml to get clear stack traces. Don't forget
// to disable for production.
enabled: false
}
});
teavm.exports.main([]);
}
</script>
</head>
<body onload="main()">
<!-- TODO: add HTML content -->
</body>
</html>

View File

@ -44,7 +44,7 @@
<!-- Configure Java compiler to use Java 8 syntax -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.13.0</version>
<configuration>
<source>\${java.version}</source>
<target>\${java.version}</target>
@ -54,7 +54,7 @@
<!-- Configure WAR plugin to include JavaScript files generated by TeaVM -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<version>3.4.0</version>
<configuration>
<webResources>
<resource>