Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/java-wasm-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: prism.wasm
path: java-wasm/src/test/resources/prism.wasm
path: java-wasm/src/main/resources/prism.wasm

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prism.wasm file was very intentionally placed in test so that it doesn't get included in the resulting jar (it's redundant).

The Chicory compiler already generates a org/prism/PrismParser.meta file that is smaller and contains everything needed for execution.

5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ all: shared static
shared: build/libprism.$(SOEXT)
static: build/libprism.a
wasm: javascript/src/prism.wasm
java-wasm: java-wasm/src/test/resources/prism.wasm
java-wasm: java-wasm/src/main/resources/prism.wasm

build/libprism.$(SOEXT): $(SHARED_OBJECTS)
$(ECHO) "linking $@ with $(CC)"
Expand All @@ -44,8 +44,9 @@ javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS)
$(ECHO) "building $@"
$(Q) $(WASI_SDK_PATH)/bin/clang --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/ $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -o $@ $(SOURCES)

java-wasm/src/test/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS)
java-wasm/src/main/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS)
$(ECHO) "building $@"
$(Q) $(MAKEDIRS) $(@D)
$(Q) $(WASI_SDK_PATH)/bin/clang $(DEBUG_FLAGS) -DPRISM_EXCLUDE_PRETTYPRINT -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(JAVA_WASM_CFLAGS) -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -lc++ -lc++abi -o $@ $(SOURCES)

build/shared/%.o: src/%.c Makefile $(HEADERS)
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ end
CLOBBER.concat(Prism::Template::TEMPLATES)
CLOBBER.concat(["build"])
CLOBBER << "lib/prism/prism.#{RbConfig::CONFIG["DLEXT"]}"
CLOBBER << "java-wasm/src/main/resources/prism.wasm"

Prism::Template::TEMPLATES.each do |filepath|
desc "Generate #{filepath}"
Expand Down
23 changes: 23 additions & 0 deletions java-wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
This dir contains the chicory-prism artifact, a version of prism compiled to WASM and then AOT compiled to JVM bytecode by the Chicory project.

Generate the templated sources:

```
PRISM_EXCLUDE_PRETTYPRINT=1 PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS=1 PRISM_JAVA_BACKEND=jruby bundle exec rake templates
```

Compile to WASM using WASI SDK version 25:

```
make java-wasm WASI_SDK_PATH=.../wasi-sdk-25.0-arm64-macos
```

Build the AOT-compiled machine and wrapper library:

```
mvn -f java-wasm/pom.xml clean package
```

This should build the chicory-wasm jar file and pass some basic tests.

The jar will be under `java-wasm/target/chicory-prism-#####-SNAPSHOT.jar` or can be installed by using `install` instead of `pacakge` in the `mvn` command line above.
27 changes: 16 additions & 11 deletions java-wasm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<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>com.prism</groupId>
<artifactId>java-prism</artifactId>
<version>999-SNAPSHOT</version>
<groupId>org.jruby</groupId>
<artifactId>chicory-prism</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Prism</name>
<description>Pure Java Prism interpreting WASM</description>
<description>Pure Java Prism using Chicory WASM runtime</description>


<properties>
Expand All @@ -15,7 +15,7 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

<chicory.version>1.2.1</chicory.version>
<chicory.version>1.6.1</chicory.version>
<junit.version>5.12.1</junit.version>
</properties>

Expand Down Expand Up @@ -47,9 +47,14 @@
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>host-module-annotations-experimental</artifactId>
<artifactId>annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-base</artifactId>
<version>10.0.2.0</version>
</dependency>
</dependencies>

<build>
Expand All @@ -76,7 +81,7 @@
<annotationProcessorPaths>
<path>
<groupId>com.dylibso.chicory</groupId>
<artifactId>host-module-processor-experimental</artifactId>
<artifactId>annotations-processor</artifactId>
<version>${chicory.version}</version>
</path>
</annotationProcessorPaths>
Expand Down Expand Up @@ -107,17 +112,17 @@
</plugin>
<plugin>
<groupId>com.dylibso.chicory</groupId>
<artifactId>aot-maven-plugin-experimental</artifactId>
<artifactId>chicory-compiler-maven-plugin</artifactId>
<version>${chicory.version}</version>
<executions>
<execution>
<id>prism</id>
<goals>
<goal>wasm-aot-gen</goal>
<goal>compile</goal>
</goals>
<configuration>
<name>org.prism.Prism</name>
<wasmFile>src/test/resources/prism.wasm</wasmFile>
<name>org.prism.PrismParser</name>
<wasmFile>src/main/resources/prism.wasm</wasmFile>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.prism;

public final class WasmResource {
public static final String absoluteFile = "file://${project.basedir}/src/test/resources/prism.wasm";
public static final String absoluteFile = "file://${project.basedir}/src/main/resources/prism.wasm";

private WasmResource() {}
}
9 changes: 6 additions & 3 deletions java-wasm/src/main/java/org/prism/Prism.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.prism;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but you might want to align the package name to the new groupId.


import com.dylibso.chicory.annotations.WasmModuleInterface;
import com.dylibso.chicory.runtime.ByteArrayMemory;
import com.dylibso.chicory.experimental.hostmodule.annotations.WasmModuleInterface;
import com.dylibso.chicory.runtime.ImportValues;
import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.wasi.WasiOptions;
import com.dylibso.chicory.wasi.WasiPreview1;
import com.dylibso.chicory.wasm.WasmModule;
import com.dylibso.chicory.wasm.types.MemoryLimits;

import java.nio.charset.StandardCharsets;
Expand All @@ -21,9 +22,11 @@ public Prism() {
}
public Prism(WasiOptions wasiOpts) {
wasi = WasiPreview1.builder().withOptions(wasiOpts).build();
instance = Instance.builder(PrismModule.load())
WasmModule module = PrismParser.load();
PrismParser parser = new PrismParser();
instance = Instance.builder(module)
.withMemoryFactory(limits -> new ByteArrayMemory(new MemoryLimits(10, MemoryLimits.MAX_PAGES)))
.withMachineFactory(PrismModule::create)
.withMachineFactory(parser.machineFactory())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: .withMachineFactory(PrismParser::create)

.withImportValues(ImportValues.builder().addFunction(wasi.toHostFunctions()).build())
.build();
exports = new Prism_ModuleExports(instance);
Expand Down
Loading