Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An example WASI wrapper based on Rust std #34

Merged
merged 2 commits into from
Jun 20, 2024

Conversation

fgh1999
Copy link
Contributor

@fgh1999 fgh1999 commented Jun 13, 2024

Convert the Linux WASI wrapper example into Rust.

@ainozaki
Copy link
Contributor

Sorry for the delay in noticing. Thank you for the PR! I will review it soon.

@ainozaki ainozaki self-requested a review June 16, 2024 23:46
Copy link
Contributor

@saza-ku saza-ku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about separating directories by languages? Like this:

wasi-wrapper/
├── c
└── rust

@fgh1999 fgh1999 force-pushed the rust-wrapper branch 4 times, most recently from a914da5 to 91302d7 Compare June 18, 2024 16:27
@ainozaki
Copy link
Contributor

ainozaki commented Jun 19, 2024

It seems wasm.o isn't generated in my environment and Codespace.
Could you show me how it looks when you execute cargo run?

warning: version requirement `0.11.0+wasi-snapshot-preview1` for dependency `wasi` includes semver metadata which will be ignored, removing the metadata is recommended to avoid confusion
   Compiling wasi-wrapper v0.1.0 (/workspaces/wasker/examples/wasi-wrapper/rust)
   Compiling wasi v0.11.0+wasi-snapshot-preview1
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/vscode/bin/linux-x64/611f9bfce64f25108829dd295f54a6894e87339d/bin/remote-cli:/usr/local/cargo/bin:/usr/local/cargo/bin:/usr/local/llvm/bin:/usr/local/cargo/bin:/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/vscode/.local/bin:/home/vscode/" VSLANG="1033" "cc" "-m64" "/tmp/rustcZvuD8I/symbols.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.10r1pyb1xkbom89n.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.1h534bfnf3gg1rx3.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.1lr27v5gnrcqae10.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.1u44bw3h4kk52neb.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.1yz812zd7dz5dh6k.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.1z2vgd934eto991a.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.1z8onw7b2bwe7f7d.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.2mufezumokr96vvo.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.2xpbtne4bj9hswui.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.2xrtinygjr787bnx.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.3pyxq28ex0urwivv.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.3vj4fxlyv1atmkpt.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.3zwrrwy4v5zg8i57.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.3zzrcip2bx74fpf6.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.42bnwtgwkyf4im7f.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.4boh8kdm9ffh4m5b.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.4em8s1tz46wue7e5.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.4fnoj8h5bfn02zlc.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.4fv9nwzio0ajbnze.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.4p97l8sn7mypsk9y.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.4r1rm752lfmaxu1x.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.4s4kq3v5gga1z286.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.4snbsgf4uc131d92.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.5gkjdywn1x1hc0eg.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.hkjwzfakft7y8t0.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.udymfk4gglm34ad.rcgu.o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710.2ucjvt0yme4xndvu.rcgu.o" "-Wl,--as-needed" "-L" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps" "-L" "../../rust" "-L" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-lwasm" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/libwasi-e849b874138ed05d.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-d2ef02247056996e.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fde67f6c4eccaa42.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-2549d0ec992a5666.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-bb9bfc0931d5cad0.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-7c0b91fdc4adc2c5.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-6ec164769e6c2957.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-95326caaef561554.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-704dba0df3717bb7.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-5f0117cb69112303.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-7a95907f1ed0cea5.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-d4aa666f8242aefc.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-9abec8861e966bc7.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-863ac378b60eeb30.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-fc8aa5b7d220f0a9.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-0cc850f1e941238d.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-f7b445210e88e768.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-f37052492751c579.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-fd15ec7f305d48e7.rlib" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d700583125da6701.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/workspaces/wasker/examples/wasi-wrapper/rust/target/debug/deps/wasi_wrapper-dc4e58fbce74c710" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "-no-pie"
  = note: /usr/bin/ld: cannot find -lwasm: No such file or directory
          collect2: error: ld returned 1 exit status
          

error: could not compile `wasi-wrapper` (bin "wasi-wrapper") due to 1 previous error
@ainozaki ➜ .../wasker/examples/wasi-wrapper/rust (rust-wrapper) $ ls ../../rust/
Cargo.lock  Cargo.toml  README.md  src  target

Command::new("wasker")
.args([
"-o",
path_to_str(wasm_path.join(&target_obj_name).as_path()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, current dir is wasm_path(../../rust) , so it might not be necessary to join the wasm_path.

@fgh1999
Copy link
Contributor Author

fgh1999 commented Jun 19, 2024

Sorry. My incomplete cleanup of the space resulted in a misleading compilation success.
The obj & lib files are generated under examples/rust now.

@ainozaki
Copy link
Contributor

Thank you very much!
I've confirmed it works. LGTM 👍

@ainozaki ainozaki merged commit be66b30 into mewz-project:main Jun 20, 2024
2 checks passed
@ainozaki
Copy link
Contributor

Thank you very much for your contribution ❤️ @fgh1999

@fgh1999 fgh1999 deleted the rust-wrapper branch June 20, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants