wasm3 / wasm3-rs

Rust wrapper for Wasm3, the fastest WebAssembly interpreter
MIT License
155 stars 43 forks source link

wasm3 support for arm64 (Apple Silicon, M1) #23

Closed wesleyhales closed 3 years ago

wesleyhales commented 3 years ago

wasm3-rc won't compile on new aarch64/arm64 target. Here's the error:

Updating crates.io index Compiling cc v1.0.66 Compiling shlex v0.1.1 Compiling cty v0.2.1 Compiling wasm3-sys v0.1.2 (/Users/wesleyhales/dev/wasm3-rs/wasm3-sys) error: failed to run custom build command for wasm3-sys v0.1.2 (/Users/wesleyhales/dev/wasm3-rs/wasm3-sys)

Caused by: process didn't exit successfully: /Users/wesleyhales/dev/wasm3-rs/target/debug/build/wasm3-sys-993c8d824c535d4d/build-script-build (exit code: 101) --- stderr thread 'main' panicked at 'failed to read wasm3/source directory', wasm3-sys/build.rs:22:29 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

I originally reported the issue here... see comments on why I brought it to this repo.

I tried to build wasm3 standalone and there are issues with unrecognized flags on arm64. After running cmake, I had to edit the build file to remove the -march=native flag completely and replace -fuse-ld=lld with -fuse-ld=ld. wasm3 successfully built after these changes.

Veykril commented 3 years ago

The panic you are getting there is the following line, https://github.com/Veykril/wasm3-rs/blob/master/wasm3-sys/build.rs#L22. I assume you were trying to build it locally in which case you have to clone the submodule for this to build as the error message there implies it cant find the C soure.

As an additional note this crate doesn't make use of the original cmake but solely relies on the build script, so it might need tweaks as well to build for your platform.

wesleyhales commented 3 years ago

Will give it a try and let you know.

matthewtgilbride commented 3 years ago

@wesleyhales did you ever get wasmcloud to build on an M1 machine? Would love a helping hand if so...I'm a bit out of my depth here but found this issue and looks like it's exactly the culprit for me:

RUST_BACKTRACE=full cargo install --git https://github.com/wasmcloud/wash --branch main
error: failed to run custom build command for `wasm3-sys v0.1.2`

Caused by:
  process didn't exit successfully: `/var/folders/w7/781t8hz53nj5vzz9fyg86b_r0000gn/T/cargo-installifGCkN/release/build/wasm3-sys-082cd626bccb9ae8/build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'libclang error; possible causes include:
  - Invalid flag syntax
  - Unrecognized flags
  - Invalid flag arguments
  - File I/O errors
  - Host vs. target architecture mismatch
  If you encounter an error missing from this list, please file an issue or a PR!', /Users/matthewtgilbride/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.54.0/src/ir/context.rs:573:15
  stack backtrace:
     0:        0x102ced478 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb7980d26174b99cc
     1:        0x102d0ccec - core::fmt::write::hce37a9344a9aa8e7
     2:        0x102ce96f4 - std::io::Write::write_fmt::h686eb8440ccc31c3
     3:        0x102cf035c - std::panicking::default_hook::{{closure}}::hd8ecce238a238901
     4:        0x102cf0034 - std::panicking::default_hook::h4c3bbdaeee039651
     5:        0x102cf0910 - std::panicking::rust_panic_with_hook::h140cbf507d3407f4
     6:        0x102cf04ec - std::panicking::begin_panic_handler::{{closure}}::hb6a3220cf34e266a
     7:        0x102ced930 - std::sys_common::backtrace::__rust_end_short_backtrace::hd5353dc16fba6ea5
     8:        0x102cf0454 - _rust_begin_unwind
     9:        0x102d16808 - core::panicking::panic_fmt::h0333f3235caab578
    10:        0x102d16708 - core::option::expect_failed::hf0ddc7de4cc4d418
    11:        0x102a3a384 - core::option::Option<T>::expect::hd08a0e051adcd9f3
    12:        0x1029494ec - bindgen::ir::context::BindgenContext::new::hfc49529589a249b4
    13:        0x102a455f0 - bindgen::Bindings::generate::h9a088c84faf10139
    14:        0x102a43788 - bindgen::Builder::generate::h73fb8e18eec480f7
    15:        0x10289b500 - build_script_build::gen_bindings::h20e173fb30656fa4
    16:        0x10289b840 - build_script_build::main::h8b37b1ebfa6cf2da
    17:        0x10289cda8 - core::ops::function::FnOnce::call_once::hdd56c399c0b4127d
    18:        0x10289d034 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5ff8fdc9ba957d37
    19:        0x10289ca68 - std::rt::lang_start::{{closure}}::h63fc412dcd633c88
    20:        0x102cf0d68 - std::rt::lang_start_internal::h1c29856da483cadc
    21:        0x10289ca44 - std::rt::lang_start::h1b6a43fbd4022d49
    22:        0x10289bbcc - _main
wesleyhales commented 3 years ago

@matthewtgilbride not yet. I think #22 or #21 are related and compile flags need to be passed in to support the M1. That issue talks about different flags for a different problem but I think the problem with passing the arguments are related. I really want to get back to this, so let me know if you make any progress.

matthewtgilbride commented 3 years ago

@wesleyhales this stuff is a bit over my head (learning Rust...with stretch goals to run this project on wasmCloud...but keeping the wasm dependencies isolated for now).

My current workaround here: https://github.com/matthewtgilbride/codenames/blob/main/service/Dockerfile.wash

You'll see there's a docker-compose.yml in the same directory... docker-compose run wash ...start a shell in that container wash up -h nats ...runs the wash cli tool.

My experience with the Docker preview for M1 so far has been quite positive. Obviously you'd need to mount a volume or copy your actor .wasm into the container...but this at least unblocks my use case for now.

Hope that helps...LMK.

matthewtgilbride commented 3 years ago

Hi @Veykril , it appears that wasm3 has released support for M1: https://github.com/wasm3/wasm3/releases/tag/v0.5.0

I don't really understand the codebase here so forgive me if this question is somewhat ignorant. It appears you point to wasm3 as a git submodule here: https://github.com/wasm3/wasm3-rs/tree/master/wasm3-sys

Is it as simple as updating the sha of that submodule to v0.5.0 of wasm3 to close this issue, or is it more complex than that?

Veykril commented 3 years ago

Assuming nothing of the api that the crate uses got changed since the last update it should suffice to just update the sys-bindings I believe

Veykril commented 3 years ago

Just checked and some things have changed for it to not compile as is unfortunately(most likely since the crate relies on some internal things still, which might not be needed anymore). I don't know if these are simple to fix or not. error output:

lukas in wasm3-rs on  master ❯ cargo test
   Compiling wasm3-sys v0.1.2 (C:\Workspace\Rust\wasm3-rs\wasm3-sys)
warning: couldn't execute `llvm-config --prefix` (error: The system cannot find the file specified. (os error 2))
warning: set the LLVM_CONFIG_PATH environment variable to the full path to a valid `llvm-config` executable (including the executable itself)
   Compiling wasm3 v0.1.3 (C:\Workspace\Rust\wasm3-rs)
error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
  --> src\ty.rs:93:33
   |
93 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_i32 as u8;
   |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:113:33
    |
113 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_i32 as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:133:33
    |
133 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_i64 as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:154:33
    |
154 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_i64 as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:174:33
    |
174 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_f32 as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:194:33
    |
194 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_f64 as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:213:33
    |
213 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_none as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
  --> src\ty.rs:93:33
   |
93 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_i32 as u8;
   |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:113:33
    |
113 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_i32 as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:133:33
    |
133 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_i64 as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:154:33
    |
154 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_i64 as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:174:33
    |
174 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_f32 as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:194:33
    |
194 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_f64 as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:213:33
    |
213 |     const TYPE_INDEX: u8 = ffi::_bindgen_ty_1::c_m3Type_none as u8;
    |                                 ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:333:18
    |
333 |             ffi::_bindgen_ty_1::c_m3Type_f64 as u8
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:340:18
    |
340 |             ffi::_bindgen_ty_1::c_m3Type_f64 as u8
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:347:18
    |
347 |             ffi::_bindgen_ty_1::c_m3Type_f64 as u8,
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:348:18
    |
348 |             ffi::_bindgen_ty_1::c_m3Type_i32 as u8
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:355:18
    |
355 |             ffi::_bindgen_ty_1::c_m3Type_i64 as u8,
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:356:18
    |
356 |             ffi::_bindgen_ty_1::c_m3Type_f32 as u8
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:363:18
    |
363 |             ffi::_bindgen_ty_1::c_m3Type_f64 as u8,
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:364:18
    |
364 |             ffi::_bindgen_ty_1::c_m3Type_i32 as u8,
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:365:18
    |
365 |             ffi::_bindgen_ty_1::c_m3Type_i32 as u8,
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:366:18
    |
366 |             ffi::_bindgen_ty_1::c_m3Type_i64 as u8,
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:367:18
    |
367 |             ffi::_bindgen_ty_1::c_m3Type_f32 as u8
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:374:18
    |
374 |             ffi::_bindgen_ty_1::c_m3Type_i32 as u8,
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:375:18
    |
375 |             ffi::_bindgen_ty_1::c_m3Type_i64 as u8,
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:376:18
    |
376 |             ffi::_bindgen_ty_1::c_m3Type_i32 as u8,
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:377:18
    |
377 |             ffi::_bindgen_ty_1::c_m3Type_f32 as u8,
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0433]: failed to resolve: could not find `_bindgen_ty_1` in `ffi`
   --> src\ty.rs:378:18
    |
378 |             ffi::_bindgen_ty_1::c_m3Type_f64 as u8
    |                  ^^^^^^^^^^^^^ could not find `_bindgen_ty_1` in `ffi`

error[E0609]: no field `name` on type `&M3Function`
   --> src\function.rs:112:48
    |
112 |         unsafe { cstr_to_str(self.raw.as_ref().name) }
    |                                                ^^^^ help: a field with a similar name exists: `names`

error[E0026]: struct `M3FuncType` does not have fields named `returnType`, `argTypes`
   --> src\function.rs:123:13
    |
123 |             returnType: ret,
    |             ^^^^^^^^^^
124 |             argTypes: ref args,
    |             ^^^^^^^^ struct `M3FuncType` does not have these fields

error[E0609]: no field `name` on type `&&mut M3Function`
   --> src\module.rs:153:43
    |
153 |             .find(|func| eq_cstr_str(func.name, function_name))
    |                                           ^^^^ help: a field with a similar name exists: `names`

error[E0609]: no field `name` on type `&M3Function`
   --> src\function.rs:112:48
    |
112 |         unsafe { cstr_to_str(self.raw.as_ref().name) }
    |                                                ^^^^ help: a field with a similar name exists: `names`

error[E0026]: struct `M3FuncType` does not have fields named `returnType`, `argTypes`
   --> src\function.rs:123:13
    |
123 |             returnType: ret,
    |             ^^^^^^^^^^
124 |             argTypes: ref args,
    |             ^^^^^^^^ struct `M3FuncType` does not have these fields

error[E0609]: no field `name` on type `&&mut M3Function`
   --> src\module.rs:153:43
    |
153 |             .find(|func| eq_cstr_str(func.name, function_name))
    |                                           ^^^^ help: a field with a similar name exists: `names`

error: aborting due to 10 previous errors

Some errors have detailed explanations: E0026, E0433, E0609.
For more information about an error, try `rustc --explain E0026`.
error: could not compile `wasm3`

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

Some errors have detailed explanations: E0026, E0433, E0609.
For more information about an error, try `rustc --explain E0026`.
error: build failed
vshymanskyy commented 3 years ago

Not sure what to do with ffi::_bindgen_ty_1::* errors. The original issue was refering to 'failed to read wasm3/source directory', this was fixed by removing the submodule and including the wasm3 source code directly.

vshymanskyy commented 3 years ago

Wasm3 update is tracked by https://github.com/wasm3/wasm3-rs/issues/24

Veykril commented 3 years ago

The original issue was refering to 'failed to read wasm3/source directory', this was fixed by removing the submodule and including the wasm3 source code directly.

That is usually caused when not pulling the submodule sources.