Stream: general

Topic: embedding and executing WASM from Rust


view this post on Zulip nikomatsakis (May 22 2021 at 21:12):

Hey folks! I would like to generate a Rust executable that will run graphviz. I currently generate HTML based on viz.js, which is basically a WASM-ified version of graphviz. I would rather just generate SVG directly by creating my "dot" file and then executing an embedded copy of graphviz. In particular, I don't want to require that the graphviz executable (or ideally even the sources) are found on the system running my rust program.

view this post on Zulip nikomatsakis (May 22 2021 at 21:12):

How do I do it!

view this post on Zulip nikomatsakis (May 22 2021 at 21:12):

cc @Alex Crichton or @fitzgen (he/him)

view this post on Zulip Alex Crichton (May 22 2021 at 21:14):

@nikomatsakis your goal being to basically build a Rust executable that uses wasmtime to execute a compiled-in wasm blob that runs graphviz?

view this post on Zulip nikomatsakis (May 22 2021 at 21:14):

I guess so

view this post on Zulip nikomatsakis (May 22 2021 at 21:14):

I don't care in particular that it's wasmtime

view this post on Zulip nikomatsakis (May 22 2021 at 21:14):

but that is I guess the most likely candidate

view this post on Zulip Alex Crichton (May 22 2021 at 21:14):

do you have the wasm blob on hand and are familiar with it? or is it a black box of sorts?

view this post on Zulip nikomatsakis (May 22 2021 at 21:14):

I'm probably making life harder than I have to

view this post on Zulip Alex Crichton (May 22 2021 at 21:14):

(presumably there's a lot of fancy JS interopereating with the wasm blob as well)

view this post on Zulip nikomatsakis (May 22 2021 at 21:15):

well, right now I have nothing

view this post on Zulip fitzgen (he/him) (May 22 2021 at 21:15):

Compile graphviz to wasm with wasi using wasi-sdk, then run it via wasmtime

view this post on Zulip nikomatsakis (May 22 2021 at 21:15):

I generate a dot file

view this post on Zulip nikomatsakis (May 22 2021 at 21:15):

I could use this Rust graphviz package, but it wants a graphviz executable, and I don't like that idea

view this post on Zulip nikomatsakis (May 22 2021 at 21:15):

fitzgen (he/him) said:

Compile graphviz to wasm with wasi using wasi-sdk, then run it via wasmtime

this sounds like what I had in mind

view this post on Zulip nikomatsakis (May 22 2021 at 21:15):

are there instructions for how to do that sort of thing?

view this post on Zulip nikomatsakis (May 22 2021 at 21:16):

this is partly an excuse for me to play with wasm, of course

view this post on Zulip fitzgen (he/him) (May 22 2021 at 21:16):

Using the existing wasm blob is probably a no go; it’s probably JS specific, as Alex mentions

view this post on Zulip fitzgen (he/him) (May 22 2021 at 21:16):

https://github.com/WebAssembly/wasi-sdk

WASI-enabled WebAssembly C/C++ toolchain. Contribute to WebAssembly/wasi-sdk development by creating an account on GitHub.

view this post on Zulip nikomatsakis (May 22 2021 at 21:17):

can I apt-get that?

view this post on Zulip fitzgen (he/him) (May 22 2021 at 21:17):

Read me has details; pretty much just setting CC and passing a couple flags

view this post on Zulip fitzgen (he/him) (May 22 2021 at 21:17):

Probably not

view this post on Zulip nikomatsakis (May 22 2021 at 21:17):

yeah, ok, it doesn't look too hard

view this post on Zulip nikomatsakis (May 22 2021 at 21:17):

(deleted)

view this post on Zulip nikomatsakis (May 22 2021 at 21:18):

fitzgen (he/him) said:

Probably not

too bad :)

view this post on Zulip fitzgen (he/him) (May 22 2021 at 21:18):

I personally don’t install it to /opt, just a local dir in my home so I can have multiple versions installed in parallel

view this post on Zulip nikomatsakis (May 22 2021 at 21:18):

this is like just on the limit of complexity I am willing to endure

view this post on Zulip nikomatsakis (May 22 2021 at 21:19):

I have to copy and paste shell commands and edit them, but there's only 2, and the edits are trivial :)

view this post on Zulip nikomatsakis (May 22 2021 at 21:19):

ok

view this post on Zulip fitzgen (he/him) (May 22 2021 at 21:19):

This may require patching graphviz, btw. I don’t know if it uses signals but that’s a common thing to have to turn off

view this post on Zulip fitzgen (he/him) (May 22 2021 at 21:19):

And multithreading

view this post on Zulip nikomatsakis (May 22 2021 at 21:20):

ok

view this post on Zulip nikomatsakis (May 22 2021 at 21:20):

I suppose I could use https://crates.io/crates/graphviz-sys

view this post on Zulip nikomatsakis (May 22 2021 at 21:20):

that's so much less cool :)

view this post on Zulip nikomatsakis (May 22 2021 at 21:21):

also I guess that would require the people running cargo build to have the libraries on their system

view this post on Zulip nikomatsakis (May 22 2021 at 21:21):

which is kind of what I want to avoid

view this post on Zulip fitzgen (he/him) (May 22 2021 at 21:21):

/me nods

view this post on Zulip nikomatsakis (May 22 2021 at 21:21):

and me to write unsafe code

view this post on Zulip nikomatsakis (May 22 2021 at 21:37):

checking for gcc... /home/nmatsakis/versioned/skill-tree/graphviz/wasi-sdk-12.0/bin/clang --sysroot='/home/nmatsakis/versioned/skill-tree/graphviz/wasi-sdk-12.0/share/wasi-sysroot
checking whether the C compiler works... no
configure: error: in `/home/nmatsakis/versioned/skill-tree/graphviz/graphviz-2.47.1':
configure: error: C compiler cannot create executables

view this post on Zulip nikomatsakis (May 22 2021 at 21:37):

I suppose that should not be surprising :)

view this post on Zulip Alex Crichton (May 22 2021 at 21:47):

tbh honest none of this is likely to succeed

view this post on Zulip Alex Crichton (May 22 2021 at 21:47):

if you're lucky you can configure graphviz for cross compilation

view this post on Zulip nikomatsakis (May 22 2021 at 21:47):

yeah I think I decided to just give up

view this post on Zulip Alex Crichton (May 22 2021 at 21:47):

if you're lucky it'll actually compile with wasi-sdk

view this post on Zulip Alex Crichton (May 22 2021 at 21:47):

if you're lucky it'll actually produce a meaningful output

view this post on Zulip Alex Crichton (May 22 2021 at 21:47):

but anything can go wrong along the way and it's all "goop of porting a C project" which can get... tricky

view this post on Zulip nikomatsakis (May 22 2021 at 21:48):

yeah I have no real appetite for that :)

view this post on Zulip nikomatsakis (May 22 2021 at 21:49):

anyway I have a workable-ish system with viz.js


Last updated: Dec 23 2024 at 12:05 UTC