-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move compilation support image to wasm-corpus (#236)
* Move compilation support image to wasm-corpus * fix tests * Make scripts runnable on host or docker * add readme * reformat
- Loading branch information
Showing
91 changed files
with
199 additions
and
359 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
FROM ubuntu:jammy | ||
|
||
# Set the environment variable to avoid prompts | ||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y curl build-essential gcc make pkg-config libssl-dev && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Install rust | ||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
ENV PATH="/root/.cargo/bin:${PATH}" | ||
RUN rustc --version && cargo --version | ||
RUN rustup target add wasm32-unknown-unknown | ||
RUN rustup target add wasm32-wasi | ||
|
||
WORKDIR /tmp | ||
|
||
# Install wasi-sdk | ||
RUN curl -L -O https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz && \ | ||
mkdir -p /opt/wasi-sdk && \ | ||
tar xvf wasi-sdk-20.0-linux.tar.gz && \ | ||
cp -r wasi-sdk-20.0/* /opt/wasi-sdk | ||
|
||
ENV WASI_SDK_PATH=/opt/wasi-sdk | ||
|
||
# Install wabt tools | ||
RUN curl -L -O https://github.com/WebAssembly/wabt/releases/download/1.0.34/wabt-1.0.34-ubuntu.tar.gz && \ | ||
mkdir -p /opt/wabt && \ | ||
tar xvf wabt-1.0.34-ubuntu.tar.gz && \ | ||
cp -r wabt-1.0.34/* /opt/wabt | ||
|
||
# Install Javy | ||
RUN curl -L -O https://github.com/bytecodealliance/javy/releases/download/v1.4.0/javy-x86_64-linux-v1.4.0.gz && \ | ||
mkdir -p /opt/javy && \ | ||
gunzip javy-x86_64-linux-v1.4.0.gz && \ | ||
mv javy-x86_64-linux-v1.4.0 /usr/bin/javy && \ | ||
chmod a+x /usr/bin/javy | ||
|
||
ENV PATH="/opt/wabt/bin:${PATH}" | ||
|
||
WORKDIR /usr/code | ||
|
||
ENTRYPOINT ["./compile.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Wasm Corpus | ||
|
||
|
||
This is a central place for all of our guest source code. It can be included in other maven projects as a test | ||
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. | ||
|
||
You can use docker to compile everything. The run.sh script can orchestrate this for you: | ||
|
||
```bash | ||
cd wasm-corpus | ||
|
||
# rebuild (or build image for first time) | ||
./run.sh rebuild | ||
|
||
# compile all the submodules | ||
./run.sh | ||
|
||
# compile just one folder | ||
./run.sh rust | ||
``` | ||
|
||
|
||
If you want to run on your host machine you can run the `compile.sh` subscript yourself. | ||
It has the same arguments (assumes you have WASI_SDK_PATH set for compiling c: | ||
|
||
```bash | ||
cd wasm-corpus/src/test/resources | ||
|
||
# example | ||
./compile.sh rust | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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> | ||
<parent> | ||
<groupId>com.dylibso.chicory</groupId> | ||
<artifactId>chicory</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>wasm-corpus</artifactId> | ||
<name>Chicory - WASM Corpus</name> | ||
<description>A Corpus of guest modules for testing</description> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
# run with `rebuild` to build the image | ||
# run with no args to compile everything | ||
|
||
if [[ "$1" = "rebuild" ]]; then | ||
docker build . --platform linux/amd64 -t chicory/wasm-corpus | ||
else | ||
# Optionally takes the args `lang` (ex: wat, rust) and `file` (ex: br.wat) | ||
# both default to all | ||
docker run --platform linux/amd64 -v ./src/test/resources:/usr/code --rm chicory/wasm-corpus $1 $2 | ||
fi |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
compileWat() { | ||
filename=$(basename "$1") | ||
(set -x; wat2wasm $1 -o "./compiled/$filename.wasm") | ||
} | ||
|
||
compileRust() { | ||
filename=$(basename "$1") | ||
# we can use the wasi targets for any file that end in -wasi.rs | ||
if [[ "$filename" =~ wasi.rs$ ]]; then | ||
target="wasm32-wasi" | ||
crate_type="bin" | ||
else | ||
target="wasm32-unknown-unknown" | ||
crate_type="cdylib" | ||
fi | ||
(set -x; rustc $1 --target=$target --crate-type=$crate_type -o "./compiled/$filename.wasm") | ||
} | ||
|
||
ENV_WASI_SDK_PATH="${WASK_SDK_PATH:-/opt/wasi-sdk}" | ||
compileC() { | ||
filename=$(basename "$1") | ||
(set -x; ${ENV_WASI_SDK_PATH}/bin/clang -g -o "./compiled/$filename.wasm" $1 -nostartfiles -Wl,--no-entry -Wl,--export=run) | ||
} | ||
|
||
compileJavy() { | ||
filename=$(basename "$1") | ||
(set -x; javy compile $1 -o "./compiled/$filename.javy.wasm") | ||
} | ||
|
||
compile() { | ||
lang=$1 | ||
case "$lang" in | ||
wat) | ||
compileWat $2 | ||
;; | ||
rust) | ||
compileRust $2 | ||
;; | ||
c) | ||
compileC $2 | ||
;; | ||
javy) | ||
compileJavy $2 | ||
;; | ||
*) | ||
echo "Don't know how to compile language $lang" | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
lang="${1:-all}" | ||
path="${2:-all}" | ||
|
||
if [[ "$lang" == "all" ]]; then | ||
langs=("wat" "rust" "c" "javy") | ||
else | ||
langs=("$lang") | ||
fi | ||
|
||
for lang in "${langs[@]}"; do | ||
echo "Compiling all modules in ./$lang/*" | ||
for file in ./$lang/*; do | ||
compile $lang $file | ||
done | ||
done |
Binary file renamed
BIN
+1.56 KB
.../src/test/resources/compiled/basic.c.wasm → .../src/test/resources/compiled/basic.c.wasm
100644 → 100755
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file renamed
BIN
+962 KB
...test/resources/compiled/javy-demo.js.wasm → ...resources/compiled/javy-demo.js.javy.wasm
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file renamed
BIN
+7.99 KB
...src/test/resources/compiled/memory.c.wasm → ...src/test/resources/compiled/memory.c.wasm
100644 → 100755
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,4 @@ function writeOutput(output) { | |
// Stdout file descriptor | ||
const fd = 1; | ||
Javy.IO.writeSync(fd, buffer); | ||
} | ||
} |
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.
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.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.