Stream: git-wasmtime

Topic: wasmtime / Issue #2401 How do I run wasmtime inside C


view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 06:33):

ZW007 opened Issue #2401:

I followed this official wasmtime tutorial on embedding wasmtime in C. https://github.com/bytecodealliance/wasmtime/blob/main/examples/hello.c

It provides commands to compile the C code with hello-world wasm embedded, but I don't know what does the quoted two lines (cargo build --release -p wasmtime-c-api, target/release/libwasmtime.a) do? cargo build is for building a wasm application, what has it to do with compiling C code, let alone there is no cargo.toml, so the cargo build itself would also fail. And this static library target/release/libwasmtime.a is also not in the wasmtime repo. https://github.com/bytecodealliance/wasmtime

cargo build --release -p wasmtime-c-api

cc examples/hello.c \

-I crates/c-api/include \
-I crates/c-api/wasm-c-api/include \
target/release/libwasmtime.a \

-lpthread -ldl -lm \
-o hello
./hello

Without question, I cannot get this hello-world wasm in C compiled and run :(

Thank you so much!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 07:45):

bjorn3 commented on Issue #2401:

cargo build --release -p wasmtime-c-api

This is what compiles target/release/libwasmtime.a. You will have to run it from the root of your wasmtime clone. Rustc can target wasm, but by default it will compile for the host system.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 14:18):

ZW007 edited Issue #2401:

I followed this official wasmtime tutorial on embedding wasmtime in C. https://github.com/bytecodealliance/wasmtime/blob/main/examples/hello.c

It provides commands to compile the C code with hello-world wasm embedded, but I don't know what do the two lines (cargo build --release -p wasmtime-c-api, target/release/libwasmtime.a) do? cargo build is for building a rust application, what has it to do with compiling C code, let alone there is no cargo.toml, so the cargo build itself would also fail. And this static library target/release/libwasmtime.a is also not in the wasmtime repo. https://github.com/bytecodealliance/wasmtime

cargo build --release -p wasmtime-c-api
cc examples/hello.c \
-I crates/c-api/include \
-I crates/c-api/wasm-c-api/include \

### target/release/libwasmtime.a \
-lpthread -ldl -lm \
-o hello
./hello

Without question, I cannot get this hello-world wasm in C compiled and run :(

Thank you so much!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 14:24):

ZW007 commented on Issue #2401:

cargo build --release -p wasmtime-c-api

This is what compiles target/release/libwasmtime.a. You will have to run it from the root of your wasmtime clone. Rustc can target wasm, but by default it will compile for the host system.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 14:24):

ZW007 closed Issue #2401:

I followed this official wasmtime tutorial on embedding wasmtime in C. https://github.com/bytecodealliance/wasmtime/blob/main/examples/hello.c

It provides commands to compile the C code with hello-world wasm embedded, but I don't know what do the two lines (cargo build --release -p wasmtime-c-api, target/release/libwasmtime.a) do? cargo build is for building a rust application, what has it to do with compiling C code, let alone there is no cargo.toml, so the cargo build itself would also fail. And this static library target/release/libwasmtime.a is also not in the wasmtime repo. https://github.com/bytecodealliance/wasmtime

cargo build --release -p wasmtime-c-api
cc examples/hello.c \
-I crates/c-api/include \
-I crates/c-api/wasm-c-api/include \

### target/release/libwasmtime.a \
-lpthread -ldl -lm \
-o hello
./hello

Without question, I cannot get this hello-world wasm in C compiled and run :(

Thank you so much!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 14:28):

ZW007 edited a comment on Issue #2401:

cargo build --release -p wasmtime-c-api

This is what compiles target/release/libwasmtime.a. You will have to run it from the root of your wasmtime clone. Rustc can target wasm, but by default it will compile for the host system.

Thank you~! When I run cargo build --release -p wasmtime-c-api from the root of wasmtime clone, it says
error: failed to read pathtowasmtimeclone/wasmtime/crates/wasi-common/WASI/tools/witx/Cargo.toml

I dont know what to do.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 16:06):

ZW007 reopened Issue #2401:

I followed this official wasmtime tutorial on embedding wasmtime in C. https://github.com/bytecodealliance/wasmtime/blob/main/examples/hello.c

It provides commands to compile the C code with hello-world wasm embedded, but I don't know what do the two lines (cargo build --release -p wasmtime-c-api, target/release/libwasmtime.a) do? cargo build is for building a rust application, what has it to do with compiling C code, let alone there is no cargo.toml, so the cargo build itself would also fail. And this static library target/release/libwasmtime.a is also not in the wasmtime repo. https://github.com/bytecodealliance/wasmtime

cargo build --release -p wasmtime-c-api
cc examples/hello.c \
-I crates/c-api/include \
-I crates/c-api/wasm-c-api/include \

### target/release/libwasmtime.a \
-lpthread -ldl -lm \
-o hello
./hello

Without question, I cannot get this hello-world wasm in C compiled and run :(

Thank you so much!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 16:06):

ZW007 commented on Issue #2401:

When I run cargo build --release -p wasmtime-c-api from the root of wasmtime clone, it says
error: failed to read pathtowasmtimeclone/wasmtime/crates/wasi-common/WASI/tools/witx/Cargo.toml

I dont know what to do.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 16:08):

ZW007 deleted a comment on Issue #2401:

When I run cargo build --release -p wasmtime-c-api from the root of wasmtime clone, it says
error: failed to read pathtowasmtimeclone/wasmtime/crates/wasi-common/WASI/tools/witx/Cargo.toml

I dont know what to do.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 16:08):

ZW007 commented on Issue #2401:

cargo build --release -p wasmtime-c-api

This is what compiles target/release/libwasmtime.a. You will have to run it from the root of your wasmtime clone. Rustc can target wasm, but by default it will compile for the host system.

Thank you~! When I run cargo build --release -p wasmtime-c-api from the root of wasmtime clone, it says
error: failed to read pathtowasmtimeclone/wasmtime/crates/wasi-common/WASI/tools/witx/Cargo.toml

I dont know what to do.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 16:09):

ZW007 deleted a comment on Issue #2401:

cargo build --release -p wasmtime-c-api

This is what compiles target/release/libwasmtime.a. You will have to run it from the root of your wasmtime clone. Rustc can target wasm, but by default it will compile for the host system.

Thank you~! When I run cargo build --release -p wasmtime-c-api from the root of wasmtime clone, it says
error: failed to read pathtowasmtimeclone/wasmtime/crates/wasi-common/WASI/tools/witx/Cargo.toml

I dont know what to do.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 16:46):

cfallin commented on Issue #2401:

It sounds like maybe the git submodules aren't cloned? Try this:

git submodule update --init

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 19:48):

ZW007 commented on Issue #2401:

It sounds like maybe the git submodules aren't cloned? Try this:

git submodule update --init

Hi Chris, Thank you!! I thought simply a git would work. Now I am able to run the examples except the wasi one.
https://github.com/bytecodealliance/wasmtime/blob/eb650f6fe0e1f40432e7fa8d62b2885d0e4c5467/examples/wasi/main.c

The line 40 is: FILE* file = fopen("target/wasm32-wasi/debug/wasi.wasm", "rb");

but there is no wasm32-wasi directory in my wasmtime clone. I have already cargo build --release -p wasmtime-c-api But after this command, there is only a ./release directory and a CACHEDIR.TAG file in my ./target directory.

There is still something missing in my target directory I think

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 19:57):

bjorn3 commented on Issue #2401:

I think you will also need to run cargo build --target wasm32-wasi --example wasi to build just that file.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 20:16):

ZW007 commented on Issue #2401:

I think you will also need to run cargo build --target wasm32-wasi --example wasi to build just that file.

Thank you! I tried this command, but there is compiling error during cargo build:

Compiling errno v0.2.7
error[E0554]: #![feature] may not be used on the stable release channel
--> /home/zhen/.cargo/registry/src/github.com-1ecc6299db9ec823/errno-0.2.7/src/lib.rs:20:33
|
20 | #![cfg_attr(target_os = "wasi", feature(thread_local))]
| ^^^^^^^^^^^^^^^^^^^^^

Compiling time v0.1.44
error: aborting due to previous error

For more information about this error, try rustc --explain E0554.
error: could not compile errno.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 20:26):

ZW007 edited a comment on Issue #2401:

I think you will also need to run cargo build --target wasm32-wasi --example wasi to build just that file.

Thank you! I tried this command, but there is compiling error during cargo build:

Compiling errno v0.2.7
error[E0554]: #![feature] may not be used on the stable release channel
--> /home/zhen/.cargo/registry/src/github.com-1ecc6299db9ec823/errno-0.2.7/src/lib.rs:20:33
|
20 | #![cfg_attr(target_os = "wasi", feature(thread_local))]
| ^^^^^^^^^^^^^^^^^^^^^

Compiling time v0.1.44
error: aborting due to previous error

For more information about this error, try rustc --explain E0554.
error: could not compile errno.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

rustc --explain E0554 says I need nightly version. So I changed by using rustup default nightly, now I got the new error :(

error[E0463]: can't find crate for core
|
= note: the wasm32-wasi target may not be installed

error: aborting due to previous error

For more information about this error, try rustc --explain E0463.
error: could not compile cfg-if

view this post on Zulip Wasmtime GitHub notifications bot (Nov 12 2020 at 20:27):

ZW007 edited a comment on Issue #2401:

I think you will also need to run cargo build --target wasm32-wasi --example wasi to build just that file.

Thank you! I tried this command, but there is compiling error during cargo build:

Compiling errno v0.2.7
error[E0554]: #![feature] may not be used on the stable release channel
--> /home/zhen/.cargo/registry/src/github.com-1ecc6299db9ec823/errno-0.2.7/src/lib.rs:20:33
|
20 | #![cfg_attr(target_os = "wasi", feature(thread_local))]
| ^^^^^^^^^^^^^^^^^^^^^

Compiling time v0.1.44
error: aborting due to previous error

For more information about this error, try rustc --explain E0554.
error: could not compile errno.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

rustc --explain E0554 says I need nightly version. So I changed by using rustup default nightly

, now I got the new error :(

error[E0463]: can't find crate for core
|
= note: the wasm32-wasi target may not be installed

error: aborting due to previous error

For more information about this error, try rustc --explain E0463.
error: could not compile cfg-if


Last updated: Oct 23 2024 at 20:03 UTC