Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ jobs:
distribution: 'temurin'
java-version: '${{ matrix.version }}'
cache: maven
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1
- name: Build cranelift_bridge.wasm
working-directory: redline/wasm-build
run: make all
- name: Test Java
run: ./mvnw -B clean install
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/redline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ jobs:
working-directory: redline/wasm-build
run: make all
- name: Build and test redline
run: ./mvnw -B clean install -Predline
run: ./mvnw -B clean install
env:
MAVEN_OPTS: "-ea"
12 changes: 4 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,15 @@ jobs:
run: make all

- name: Compile
run: ./mvnw --batch-mode -Dquickly -Predline

run: ./mvnw --batch-mode -Dquickly
- name: Setup Git
run: |
git config user.name "Endive BOT"
git config user.email "endive@bytecodealliance.org"

- name: Set the version
run: |
./mvnw versions:set -DgenerateBackupPoms=false -DnewVersion=${{ github.event.inputs.release-version }} -Predline
git add .
./mvnw versions:set -DgenerateBackupPoms=false -DnewVersion=${{ github.event.inputs.release-version }} git add .
git commit -m "Release version update ${{ github.event.inputs.release-version }}"
git push
git tag ${{ github.event.inputs.release-version }}
Expand All @@ -74,17 +72,15 @@ jobs:
- name: Release to Maven Central
run: |
# -Dquickly is needed to locally publish wasm-corpus
./mvnw --batch-mode -Dquickly -Predline
./mvnw --batch-mode clean deploy -Drelease -Predline -DskipTests=true -X
./mvnw --batch-mode -Dquickly ./mvnw --batch-mode clean deploy -Drelease -Predline -DskipTests=true -X
env:
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

- name: Back to Snapshot
run: |
./mvnw versions:set -DgenerateBackupPoms=false -DnewVersion=999-SNAPSHOT -Predline
git add .
./mvnw versions:set -DgenerateBackupPoms=false -DnewVersion=999-SNAPSHOT git add .
git commit -m "Snapshot version update"
git push
env:
Expand Down
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
<artifactId>redline-bridge-experimental</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>run.endive</groupId>
<artifactId>redline-build-time-compiler-experimental</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>run.endive</groupId>
<artifactId>redline-compiler-experimental</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ public String[] getVersion() {
"The indexes of functions that should be interpreted, separated by commas")
Set<Integer> interpretedFunctions;

@CommandLine.Option(
order = 7,
names = "--module-interface",
description =
"Fully qualified class name for which to generate _ModuleExports and"
+ " _ModuleImports wrappers")
String moduleInterface;

@Override
public void run() {
var config =
Expand All @@ -82,6 +90,7 @@ public void run() {
.withTargetWasmFolder(targetWasmFolder)
.withInterpreterFallback(interpreterFallback)
.withInterpretedFunctions(interpretedFunctions)
.withModuleInterface(moduleInterface)
.build();

var generator = new Generator(config);
Expand All @@ -90,13 +99,19 @@ public void run() {
var interpretedFunctions = generator.generateResources();
generator.generateMetaWasm(interpretedFunctions);
generator.generateSources();
if (moduleInterface != null && !moduleInterface.isEmpty()) {
generator.generateModuleInterface(moduleInterface);
}
} catch (IOException e) {
throw new CommandLine.PicocliException("Failed to execute the command", e);
}
}

public static int execute(String[] args) {
return new CommandLine(new Cli()).execute(args);
}

public static void main(String[] args) {
int exitCode = new CommandLine(new Cli()).execute(args);
System.exit(exitCode);
System.exit(execute(args));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package run.endive.build.time.compiler;

import java.nio.file.Path;
import java.util.List;
import java.util.Set;
import java.util.StringJoiner;
import run.endive.compiler.InterpreterFallback;
Expand Down Expand Up @@ -46,6 +47,11 @@ public final class Config {
*/
private final String moduleInterface;

/**
* target triples for redline native compilation (empty = no native compilation)
*/
private final List<String> redlineTargets;

private Config(
Path wasmFile,
String name,
Expand All @@ -54,7 +60,8 @@ private Config(
Path targetWasmFolder,
InterpreterFallback interpreterFallback,
Set<Integer> interpretedFunctions,
String moduleInterface) {
String moduleInterface,
List<String> redlineTargets) {
this.wasmFile = wasmFile;
this.name = name;
this.targetClassFolder = targetClassFolder;
Expand All @@ -63,6 +70,7 @@ private Config(
this.interpreterFallback = interpreterFallback;
this.interpretedFunctions = interpretedFunctions;
this.moduleInterface = moduleInterface;
this.redlineTargets = redlineTargets;
}

public Path wasmFile() {
Expand Down Expand Up @@ -97,6 +105,14 @@ public String moduleInterface() {
return moduleInterface;
}

public List<String> redlineTargets() {
return redlineTargets;
}

public boolean hasRedlineTargets() {
return redlineTargets != null && !redlineTargets.isEmpty();
}

public static Builder builder() {
return new Builder();
}
Expand Down Expand Up @@ -126,6 +142,7 @@ public static final class Builder {
private InterpreterFallback interpreterFallback = InterpreterFallback.FAIL;
private Set<Integer> interpretedFunctions;
private String moduleInterface;
private List<String> redlineTargets = List.of();

private Builder() {}

Expand Down Expand Up @@ -169,6 +186,11 @@ public Builder withModuleInterface(String moduleInterface) {
return this;
}

public Builder withRedlineTargets(List<String> redlineTargets) {
this.redlineTargets = redlineTargets;
return this;
}

public Config build() {
return new Config(
wasmFile,
Expand All @@ -178,7 +200,8 @@ public Config build() {
targetWasmFolder,
interpreterFallback,
interpretedFunctions,
moduleInterface);
moduleInterface,
redlineTargets);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package run.endive.build.time.compiler;

import java.io.IOException;
import java.nio.file.Path;
import run.endive.compiler.InterpreterFallback;

public final class GeneratorMain {

private GeneratorMain() {}

public static void main(String[] args) throws IOException {
if (args.length < 5) {
throw new IllegalArgumentException(
"Usage: GeneratorMain <wasmFile> <name> <targetClassFolder>"
+ " <targetSourceFolder> <targetWasmFolder>"
+ " [interpreterFallback] [moduleInterface]");
}
var configBuilder =
Config.builder()
.withWasmFile(Path.of(args[0]))
.withName(args[1])
.withTargetClassFolder(Path.of(args[2]))
.withTargetSourceFolder(Path.of(args[3]))
.withTargetWasmFolder(Path.of(args[4]));
if (args.length > 5 && !args[5].isEmpty()) {
configBuilder.withInterpreterFallback(InterpreterFallback.valueOf(args[5]));
}
if (args.length > 6 && !args[6].isEmpty()) {
configBuilder.withModuleInterface(args[6]);
}
var config = configBuilder.build();
var generator = new Generator(config);
var interpreted = generator.generateResources();
generator.generateMetaWasm(interpreted);
generator.generateSources();
if (config.moduleInterface() != null && !config.moduleInterface().isEmpty()) {
generator.generateModuleInterface(config.moduleInterface());
}
}
}
4 changes: 4 additions & 0 deletions compiler-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<groupId>run.endive</groupId>
<artifactId>compiler</artifactId>
</dependency>
<dependency>
<groupId>run.endive</groupId>
<artifactId>redline-build-time-compiler-experimental</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.apache.maven.model.Resource;
Expand All @@ -14,6 +15,7 @@
import run.endive.build.time.compiler.Config;
import run.endive.build.time.compiler.Generator;
import run.endive.compiler.InterpreterFallback;
import run.endive.redline.experimental.build.RedlineGenerator;

/**
* This plugin generates an invokable library from the compiled Wasm
Expand Down Expand Up @@ -77,6 +79,20 @@ public class EndiveCompilerGenMojo extends AbstractMojo {
@Parameter(required = false)
String moduleInterface;

/**
* Enable Redline native compilation (experimental) for all supported
* platforms (x86_64 and aarch64 on Linux, macOS, and Windows).
*/
@Parameter(required = false, defaultValue = "false")
boolean redlineExperimental;

/**
* Target triples for Redline native compilation. Overrides {@code redlineExperimental}
* for fine-grained control over which platforms to cross-compile for.
*/
@Parameter(required = false)
List<String> redlineTargets;

/**
* The current Maven project.
*/
Expand All @@ -87,7 +103,7 @@ public class EndiveCompilerGenMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
getLog().info("Compiling classes for " + name + " from " + wasmFile);

var config =
var configBuilder =
Config.builder()
.withWasmFile(wasmFile.toPath())
.withName(name)
Expand All @@ -96,8 +112,13 @@ public void execute() throws MojoExecutionException {
.withTargetWasmFolder(targetWasmFolder.toPath())
.withInterpreterFallback(interpreterFallback)
.withInterpretedFunctions(interpretedFunctions)
.withModuleInterface(moduleInterface)
.build();
.withModuleInterface(moduleInterface);
if (redlineTargets != null && !redlineTargets.isEmpty()) {
configBuilder.withRedlineTargets(redlineTargets);
} else if (redlineExperimental) {
configBuilder.withRedlineTargets(RedlineGenerator.allTargets());
}
var config = configBuilder.build();

var generator = new Generator(config);

Expand All @@ -106,6 +127,13 @@ public void execute() throws MojoExecutionException {
generator.generateMetaWasm(finalInterpretedFunctions);
generator.generateSources();

if (config.hasRedlineTargets()) {
getLog().info("Redline native compilation for targets: " + config.redlineTargets());
var redlineGenerator = new RedlineGenerator(config);
redlineGenerator.generateNativeCode();
redlineGenerator.extendGeneratedSources();
}

if (moduleInterface != null && !moduleInterface.isEmpty()) {
generator.generateModuleInterface(moduleInterface);
}
Expand Down
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@
<artifactId>redline-bridge-experimental</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>run.endive</groupId>
<artifactId>redline-build-time-compiler-experimental</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>run.endive</groupId>
<artifactId>redline-compiler-experimental</artifactId>
Expand Down Expand Up @@ -1041,13 +1046,6 @@
</modules>
</profile>

<profile>
<id>redline</id>
<modules>
<module>redline</module>
</modules>
</profile>

<profile>
<id>default-all-modules</id>
<activation>
Expand All @@ -1073,6 +1071,7 @@
<module>jmh</module>
<module>log</module>
<module>machine-tests</module>
<module>redline</module>
<module>runtime</module>
<module>runtime-tests</module>
<module>test-gen-lib</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public String resourceSuffix() {
return resourceSuffix;
}

public static Optional<RedlineTarget> fromTriple(String triple) {
for (RedlineTarget target : values()) {
if (target.triple.equals(triple)) {
return Optional.of(target);
}
}
return Optional.empty();
}

public static Optional<RedlineTarget> detectHost() {
String osName =
System.getProperty("endive.redline.os.name", System.getProperty("os.name", ""))
Expand Down
Loading
Loading