diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 34ed9c011..6dd3e0b5f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -126,6 +126,7 @@ jobs: run: mvn clean install -DskipTests env: MAVEN_OPTS: "-Dmaven.repo.local=${{ github.workspace }}/repository" + # Test root Readme - name: jbang uses: jbangdev/jbang-action@74844c9631cf1f35650427323e9bb3ffa41dfbd9 # tag=v0.115.0 with: @@ -133,4 +134,13 @@ jobs: env: JBANG_REPO: "${{ github.workspace }}/repository" - name: compare results - run: diff -r ./readme-approved-results ./readme-results + run: diff -r ./readmes/main/expected ./readmes/main/current + # Test wasi Readme + - name: jbang + uses: jbangdev/jbang-action@74844c9631cf1f35650427323e9bb3ffa41dfbd9 # tag=v0.115.0 + with: + script: wasi/README.md + env: + JBANG_REPO: "${{ github.workspace }}/repository" + - name: compare results + run: diff -r ./readmes/wasi/expected ./readmes/wasi/current diff --git a/.gitignore b/.gitignore index 0458b6816..2df5fa5dc 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,4 @@ scripts/jmh-tmp /main/ /*.wasm -readme-results +readmes/*/current diff --git a/README.md b/README.md index d6533dc87..290517e2b 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ public void copyFileFromWasmCorpus(String sourceName, String destName) throws Ex StandardCopyOption.REPLACE_EXISTING); } -var readmeResults = "readme-results"; +var readmeResults = "readmes/main/current"; new File(readmeResults).mkdirs(); public void writeResultFile(String name, String content) throws Exception { diff --git a/readme-approved-results/countVowels.result b/readmes/main/expected/countVowels.result similarity index 100% rename from readme-approved-results/countVowels.result rename to readmes/main/expected/countVowels.result diff --git a/readme-approved-results/factorial.result b/readmes/main/expected/factorial.result similarity index 100% rename from readme-approved-results/factorial.result rename to readmes/main/expected/factorial.result diff --git a/readme-approved-results/hostFunction.result b/readmes/main/expected/hostFunction.result similarity index 100% rename from readme-approved-results/hostFunction.result rename to readmes/main/expected/hostFunction.result diff --git a/readmes/wasi/expected/greet-wasi.result b/readmes/wasi/expected/greet-wasi.result new file mode 100644 index 000000000..e8b510f2e --- /dev/null +++ b/readmes/wasi/expected/greet-wasi.result @@ -0,0 +1 @@ +Hello, Andrea! diff --git a/wasi/README.md b/wasi/README.md index 5dfcd4da8..149dccb01 100644 --- a/wasi/README.md +++ b/wasi/README.md @@ -86,6 +86,43 @@ We also have a table: > **Note**: 💀 means the function is no longer part of WASI. + + + + ### wasip2 We do have intentions to support wasip2 in the future, however this work has not been started. Please reach out to us on zulip if you are interested in helping plan and execute this work. @@ -101,16 +138,35 @@ these functions behave and what the module can and cannot do. So to instantiate a WASI module you need an instance of `WasiPreview1`. You can turn this instance into import functions which can then be passed to the Module builder. +Download from the link or with curl: + +```bash +curl https://raw.githubusercontent.com/dylibso/chicory/main/wasm-corpus/src/main/resources/compiled/hello-wasi.wat.wasm > hello-wasi.wasm +``` + + + ```java +import com.dylibso.chicory.log.SystemLogger; +import com.dylibso.chicory.wasi.WasiOptions; +import com.dylibso.chicory.wasi.WasiPreview1; +import com.dylibso.chicory.runtime.Module; +import com.dylibso.chicory.runtime.HostImports; +import java.io.File; + var logger = new SystemLogger(); // let's just use the default options for now var options = WasiOptions.builder().build(); // create our instance of wasip1 -var wasi = new WasiPreview1(this.logger, WasiOptions.builder().build()); +var wasi = new WasiPreview1(logger, WasiOptions.builder().build()); // turn those into host imports. Here we could add any other custom imports we have var imports = new HostImports(wasi.toHostFunctions()); // create the module and connect imports -var module = Module.builder("hello-wasi.wasm").withHostImports(imports).build(); +var module = Module.builder(new File("hello-wasi.wasm")).withHostImports(imports).build(); // this will execute the module if it's a WASI command-pattern module module.instantiate(); ``` @@ -125,6 +181,18 @@ Often, this is the way you communicate with basic WASI-enabled modules by way of In order to make it easy to manipulate these streams, we expose stdin as an [InputStream](https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html) and stdout/stderr as an [OutputStream](https://docs.oracle.com/javase/8/docs/api/java/io/OutputStream.html). +Download from the link or with curl: + +```bash +curl https://raw.githubusercontent.com/dylibso/chicory/main/wasm-corpus/src/main/resources/compiled/greet-wasi.rs.wasm > greet-wasi.wasm +``` + + + ```java // Let's create a fake stdin stream with the bytes "Andrea" var fakeStdin = new ByteArrayInputStream("Andrea".getBytes()); @@ -132,24 +200,25 @@ var fakeStdin = new ByteArrayInputStream("Andrea".getBytes()); var fakeStdout = new ByteArrayOutputStream(); var fakeStderr = new ByteArrayOutputStream(); // now pass those to our wasi options builder -var wasiOpts = WasiOptions - .builder() - .withStdout(fakeStdout) - .withStderr(fakeStderr) - .withStdin(fakeStdin) - .build(); - -var wasi = new WasiPreview1(this.logger, wasiOpts); +var wasiOpts = WasiOptions.builder().withStdout(fakeStdout).withStderr(fakeStderr).withStdin(fakeStdin).build(); + +var wasi = new WasiPreview1(logger, wasiOpts); var imports = new HostImports(wasi.toHostFunctions()); // greet-wasi is a rust program that greets the string passed in stdin -var module = Module.builder("greet-wasi.rs.wasm").withHostImports(imports).build(); +var module = Module.builder(new File("greet-wasi.wasm")).withHostImports(imports).build(); // instantiating will execute the module if it's a WASI command-pattern module module.instantiate(); // check that we output the greeting -assertEquals(fakeStdout.toString(), "Hello, Andrea!"); +assert(fakeStdout.toString().equals("Hello, Andrea!")); // there should be no bytes in stderr! -assertEquals(fakeStderr.toString(), ""); +assert(fakeStderr.toString().equals("")); +``` + +