Skip to content

Commit

Permalink
Use resources from wasm-corpus as a normal Maven artifact (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum authored May 18, 2024
1 parent 0ee6662 commit ce3a659
Show file tree
Hide file tree
Showing 76 changed files with 38 additions and 35 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void copyFileFromWasmCorpus(String sourceName, String destName) throws Ex
Files.copy(new File(".").toPath()
.resolve("wasm-corpus")
.resolve("src")
.resolve("test")
.resolve("main")
.resolve("resources")
.resolve("compiled")
.resolve(sourceName),
Expand All @@ -73,13 +73,13 @@ public void writeResultFile(String name, String content) throws Exception {

### Loading and Instantiating Code

First your Wasm module must be loaded from disk and then "instantiated". Let's [download a test module](https://raw.githubusercontent.com/dylibso/chicory/main/wasm-corpus/src/test/resources/compiled/iterfact.wat.wasm) .
First your Wasm module must be loaded from disk and then "instantiated". Let's [download a test module](https://raw.githubusercontent.com/dylibso/chicory/main/wasm-corpus/src/main/resources/compiled/iterfact.wat.wasm) .
This module contains some code to compute factorial:

Download from the link or with curl:

```bash
curl https://raw.githubusercontent.com/dylibso/chicory/main/wasm-corpus/src/test/resources/compiled/iterfact.wat.wasm > factorial.wasm
curl https://raw.githubusercontent.com/dylibso/chicory/main/wasm-corpus/src/main/resources/compiled/iterfact.wat.wasm > factorial.wasm
```

<!--
Expand Down Expand Up @@ -139,7 +139,7 @@ example where we have a module `count_vowels.wasm`, written in rust, that takes
in the string:

```bash
curl https://raw.githubusercontent.com/dylibso/chicory/main/wasm-corpus/src/test/resources/compiled/count_vowels.rs.wasm > count_vowels.wasm
curl https://raw.githubusercontent.com/dylibso/chicory/main/wasm-corpus/src/main/resources/compiled/count_vowels.rs.wasm > count_vowels.wasm
```

<!--
Expand Down Expand Up @@ -204,7 +204,7 @@ are and how they behave and it's written in Java.
Let's download another example module to demonstrate this:

```bash
curl https://raw.githubusercontent.com/dylibso/chicory/main/wasm-corpus/src/test/resources/compiled/host-function.wat.wasm > logger.wasm
curl https://raw.githubusercontent.com/dylibso/chicory/main/wasm-corpus/src/main/resources/compiled/host-function.wat.wasm > logger.wasm
```

<!--
Expand Down
11 changes: 5 additions & 6 deletions aot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasm-corpus</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
<directory>${project.basedir}/../wasm-corpus/src/test/resources</directory>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>com.dylibso.chicory</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void setup() throws IOException {
var factorial =
Module.builder(
new File(
"wasm-corpus/src/test/resources/compiled/iterfact.wat.wasm"))
"wasm-corpus/src/main/resources/compiled/iterfact.wat.wasm"))
.build()
.instantiate();
iterFact = factorial.export("iterFact");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
public class BenchmarkParsing {

@Param({
"wasm-corpus/src/test/resources/compiled/basic.c.wasm",
"wasm-corpus/src/test/resources/compiled/javy-demo.js.javy.wasm"
"wasm-corpus/src/main/resources/compiled/basic.c.wasm",
"wasm-corpus/src/main/resources/compiled/javy-demo.js.javy.wasm"
})
private String fileName;

Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@
<artifactId>cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasm-corpus</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Used by AOT compiler -->
<dependency>
Expand Down
11 changes: 5 additions & 6 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasm-corpus</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
<directory>${project.basedir}/../wasm-corpus/src/test/resources</directory>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>com.dylibso.chicory</groupId>
Expand Down
10 changes: 5 additions & 5 deletions wasi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasm-corpus</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
Expand All @@ -30,11 +35,6 @@
</dependencies>

<build>
<testResources>
<testResource>
<directory>${project.basedir}/../wasm-corpus/src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>com.dylibso.chicory</groupId>
Expand Down
4 changes: 2 additions & 2 deletions wasm-corpus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This is a central place for all of our guest source code. It can be included in
resources bundle.

If you want to add or edit guest modules for tests, you'll need to compile here. Add the program to the subfolder
for the appropriate source language. Example: src/test/resources/rust.
for the appropriate source language. Example: src/main/resources/rust.

You can use docker to compile everything. The run.sh script can orchestrate this for you:

Expand All @@ -27,7 +27,7 @@ If you want to run on your host machine you can run the `compile.sh` subscript y
It has the same arguments (assumes you have WASI_SDK_PATH set for compiling c:

```bash
cd wasm-corpus/src/test/resources
cd wasm-corpus/src/main/resources

# example
./compile.sh rust
Expand Down
2 changes: 1 addition & 1 deletion wasm-corpus/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ if [[ "$1" = "rebuild" ]]; then
else
# Optionally takes the args `lang` (ex: wat, rust) and `file` (ex: br.wat)
# both default to all
docker run --platform linux/amd64 -v $(pwd)/src/test/resources:/usr/code --rm chicory/wasm-corpus $1 $2
docker run --platform linux/amd64 -v $(pwd)/src/main/resources:/usr/code --rm chicory/wasm-corpus $1 $2
fi
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions wasm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasm-corpus</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
<directory>${project.basedir}/../wasm-corpus/src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>com.dylibso.chicory</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void shouldParseIterfact() throws IOException {

@Test
public void shouldParseAllFiles() {
File compiledDir = new File("../wasm-corpus/src/test/resources/compiled/");
File compiledDir = new File("../wasm-corpus/src/main/resources/compiled/");

List<File> files = new ArrayList<>();
files.addAll(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Wat2WasmTest {

@Test
public void shouldRunWat2Wasm() throws Exception {
var result = Wat2Wasm.parse(new File("../wasm-corpus/src/test/resources/wat/iterfact.wat"));
var result = Wat2Wasm.parse(new File("../wasm-corpus/src/main/resources/wat/iterfact.wat"));

assertTrue(result.length > 0);
assertTrue(new String(result).contains("iterFact"));
Expand Down

0 comments on commit ce3a659

Please sign in to comment.