Stream: git-wasmtime

Topic: wasmtime / PR #3193 Docs: Created the Wasmtime Markdown P...


view this post on Zulip Wasmtime GitHub notifications bot (Aug 16 2021 at 22:19):

torch2424 opened PR #3193 (assigned to torch2424) from torch2424/rust-wasi-markdown-parser-example to main:

This implements the example that is missing on the Wasmtime Docs: https://docs.wasmtime.dev/examples-markdown.html

It uses the same pulldown-cmark library I've seen used across many Rust/Wasm markdown examples (for example: https://github.com/tschneidereit/pulldown-cmark-wasm )

The example is also inspired by the WASI example on the WasmByExample website: https://wasmbyexample.dev/examples/wasi-hello-world/wasi-hello-world.rust.en-us.html

Example

torch2424 at torch2424-XPS-13-7390 in ~/Source/wasmtime/docs/rust_wasi_markdown_parser on torch2424/rust-wasi-markdown-parser-example
$ cargo build --target wasm32-wasi    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
torch2424 at torch2424-XPS-13-7390 in ~/Source/wasmtime/docs/rust_wasi_markdown_parser on torch2424/rust-wasi-markdown-parser-example
$ wasmtime --mapdir .::. target/wasm32-wasi/debug/rust_wasi_markdown_parser.wasm ./example_markdown.md
<h1>Hello!</h1>
<p>I am example markdown for this demo!</p>

torch2424 at torch2424-XPS-13-7390 in ~/Source/wasmtime/docs/rust_wasi_markdown_parser on torch2424/rust-wasi-markdown-parser-example
$

view this post on Zulip Wasmtime GitHub notifications bot (Aug 16 2021 at 22:19):

torch2424 assigned PR #3193 to torch2424.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 16 2021 at 22:19):

torch2424 requested tschneidereit for a review on PR #3193.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 16 2021 at 22:26):

torch2424 edited PR #3193 (assigned to torch2424) from torch2424/rust-wasi-markdown-parser-example to main:

This implements the example that is missing on the Wasmtime Docs: https://docs.wasmtime.dev/examples-markdown.html

It uses the same pulldown-cmark library I've seen used across many Rust/Wasm markdown examples (for example: https://github.com/tschneidereit/pulldown-cmark-wasm )

The example is also inspired by the WASI example on the WasmByExample website: https://wasmbyexample.dev/examples/wasi-hello-world/wasi-hello-world.rust.en-us.html

Example

torch2424 at torch2424-XPS-13-7390 in ~/Source/wasmtime/docs/rust_wasi_markdown_parser on torch2424/rust-wasi-markdown-parser-example
$ cargo build --target wasm32-wasi    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
torch2424 at torch2424-XPS-13-7390 in ~/Source/wasmtime/docs/rust_wasi_markdown_parser on torch2424/rust-wasi-markdown-parser-example
$ wasmtime --mapdir .::. target/wasm32-wasi/debug/rust_wasi_markdown_parser.wasm ./example_markdown.md
<h1>Hello!</h1>
<p>I am example markdown for this demo!</p>

torch2424 at torch2424-XPS-13-7390 in ~/Source/wasmtime/docs/rust_wasi_markdown_parser on torch2424/rust-wasi-markdown-parser-example
$

(Yes, I will update my chrome after this :joy: )

![Screenshot from 2021-08-16 15-26-13](https://user-images.githubusercontent.com/1448289/129636885-684916f5-76b1-458e-a93a-9f9588dc465e.png)

view this post on Zulip Wasmtime GitHub notifications bot (Aug 17 2021 at 09:18):

tschneidereit submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 17 2021 at 09:18):

tschneidereit submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 17 2021 at 09:18):

tschneidereit created PR review comment:

Nit: I think render_markdown might be a better name than format

view this post on Zulip Wasmtime GitHub notifications bot (Aug 17 2021 at 09:18):

tschneidereit created PR review comment:

I think it'd be nice to use one of the existing arg parsing crates here, to get good help messages, etc. Using StructOpt, that could look roughly like this:

#[derive(StructOpt)]
pub struct Options {
    /// The markdown file to render
    #[structopt(parse(from_os_str))]
    filename: PathBuf,
}


fn main() {
    let options = Options::from_args();
   // and then use `options.filename`
  // [..]
}

view this post on Zulip Wasmtime GitHub notifications bot (Aug 17 2021 at 09:18):

tschneidereit created PR review comment:

I think I'd slightly prefer simply dropping this comment, at least with the name change suggested above.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 17 2021 at 09:18):

tschneidereit created PR review comment:

I'm a bit confused by the need of all these—you really should only need to exclude target, which contains all of these.

I also think all the others below aren't really needed for this example, so perhaps just make this .gitignore file match what cargo new creates by default—i.e. only include /target?

view this post on Zulip Wasmtime GitHub notifications bot (Aug 17 2021 at 09:18):

tschneidereit created PR review comment:

I think for this example --dir would also work, and be a bit easier to follow along with.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 00:40):

torch2424 updated PR #3193 (assigned to torch2424) from torch2424/rust-wasi-markdown-parser-example to main.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 07:50):

tschneidereit submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 07:50):

tschneidereit submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 07:50):

tschneidereit created PR review comment:

To grant the capability to read in a directory using the Wasmtime CLI, we need to use the --dir flag. --dir will instruct wasmtime to make the passed directory available to access files from. (You can also `--mapdir GUEST_DIRECTORY::HOST_DIRECTORY` to make it available under a different path inside the content.) For example:

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 07:51):

tschneidereit updated PR #3193 (assigned to torch2424) from torch2424/rust-wasi-markdown-parser-example to main.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 09:06):

tschneidereit submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 09:06):

tschneidereit created PR review comment:

```bash

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 09:06):

tschneidereit submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 09:06):

tschneidereit created PR review comment:

```bash

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 09:06):

tschneidereit created PR review comment:

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 09:06):

tschneidereit created PR review comment:

```bash

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 09:06):

tschneidereit created PR review comment:

```bash
$ wasmtime --dir . target/wasm32-wasi/debug/rust_wasi_markdown_parser.wasm -- ./example_markdown.md

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 09:06):

tschneidereit created PR review comment:

```bash

view this post on Zulip Wasmtime GitHub notifications bot (Aug 18 2021 at 09:08):

tschneidereit updated PR #3193 (assigned to torch2424) from torch2424/rust-wasi-markdown-parser-example to main.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2021 at 19:04):

torch2424 updated PR #3193 (assigned to torch2424) from torch2424/rust-wasi-markdown-parser-example to main.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2021 at 19:08):

torch2424 updated PR #3193 (assigned to torch2424) from torch2424/rust-wasi-markdown-parser-example to main.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2021 at 20:04):

torch2424 updated PR #3193 (assigned to torch2424) from torch2424/rust-wasi-markdown-parser-example to main.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2021 at 14:16):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2021 at 14:16):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2021 at 14:16):

alexcrichton created PR review comment:

I think this may no longer be necessary since this is part of the main workspace?

view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2021 at 14:16):

alexcrichton created PR review comment:

Similar to above I think this is no longer needed?

view this post on Zulip Wasmtime GitHub notifications bot (Aug 31 2021 at 18:59):

torch2424 updated PR #3193 (assigned to torch2424) from torch2424/rust-wasi-markdown-parser-example to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 01 2021 at 17:25):

alexcrichton merged PR #3193.


Last updated: Dec 23 2024 at 12:05 UTC