Giter Site home page Giter Site logo

wasmer-ruby's Introduction


A complete and mature WebAssembly runtime for Ruby based on Wasmer.

Features

  • Easy to use: The wasmer API mimics the standard WebAssembly API,
  • Fast: wasmer executes the WebAssembly modules as fast as possible, close to native speed,
  • Safe: All calls to WebAssembly will be fast, but more importantly, completely safe and sandboxed.

Documentation: browse the detailed API documentation full of examples.

Examples as tutorials: browser the examples/ directory, it's the best place for a complete introduction!

Quick Introduction

The wasmer package brings the required API to execute WebAssembly modules. In a nutshell, wasmer compiles the WebAssembly module into compiled code, and then executes it. wasmer is designed to work in various environments and platforms. To achieve this, Wasmer (the original runtime) provides multiple engines and multiple compilers.

Succinctly, an engine is responsible to drive the compilation (by using a compiler) and the execution of a WebAssembly module. Wasmer comes with many engines and compilers, but for the Ruby extension, it only provides the JIT engine with the Cranelift compiler. It is subject to change in the future where the user will have the choice to select its own engine and compiler.

Install

To install the wasmer Ruby gem, just run this command in your shell:

$ gem install wasmer

And you're ready to get fun!

View the wasmer gem on RubyGems.

Note: Rust is required to install the Ruby library (Cargo —the build tool for Rust— is used to compile the extension). See how to install Rust.

Example

We highly recommend to read the examples/ directory, which contains a sequence of examples/tutorials. It's the best place to learn by reading examples.

But for the most eager of you, and we know you're numerous you mischievous, there is a quick toy program in examples/appendices/simple.rs, written in Rust:

#[no_mangle]
pub extern fn sum(x: i32, y: i32) -> i32 {
    x + y
}

After compilation to WebAssembly, the examples/appendices/simple.wasm binary file is generated.

Then, we can execute it in Ruby:

require "wasmer"

# Let's define the store, that holds the engine, that holds the compiler.
store = Wasmer::Store.new

# Let's compile the module to be able to execute it!
module_ = Wasmer::Module.new store, IO.read("simple.wasm", mode: "rb")

# Now the module is compiled, we can instantiate it.
instance = Wasmer::Instance.new module_, nil

# Call the exported `sum` function.
result = instance.exports.sum.(5, 37)

puts result # 42!

And then, finally, enjoy by running:

$ ruby examples/appendices/simple.rb

Development

The Ruby extension is written in Rust, with rutie.

First, you need to install Rust and Ruby. We will not make you the affront to explain to you how to install Ruby (if you really need, check rbenv). For Rust though, we advice to use rustup, then:

$ rustup install stable

Then, after installing just, you can simply run:

$ just build

The supported Ruby versions are:

  • Ruby 2.6,
  • Ruby 2.7,
  • Ruby 3.0.

Extensions to rutie

This project provides extensions to rutie, through the rutie-derive and rutie-derive-macros crates (see the crates/ directory). Those crates aim at enhancing rutie by providing a better “Domain Specific Language” (DSL for short) to declare Ruby modules, classes, methods and functions. It's not perfect but it does a good job for the moment. Contributions on that front are welcomed too!

Testing

Running the test-all recipe will automatically build and run all the tests. It includes library tests, along with documentation tests and the examples:

$ just test-all

Documentation

To generate the documentation, run the following command:

$ just doc

All the examples in the documentation are automatically run as tests, called doctests. To run the doctests, run just test.

What is WebAssembly?

Quoting the WebAssembly site:

WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications.

About speed:

WebAssembly aims to execute at native speed by taking advantage of common hardware capabilities available on a wide range of platforms.

About safety:

WebAssembly describes a memory-safe, sandboxed execution environment […].

License

The entire project is under the MIT License. Please read the LICENSE file.

wasmer-ruby's People

Contributors

atul9 avatar bors[bot] avatar dnsco avatar edvakf avatar hywan avatar irxground avatar kojix2 avatar nicholaides avatar syrusakbary avatar tsmartt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wasmer-ruby's Issues

cannot instantiate `Wasmer::Instance`

Describe the bug

Example applications do not work

Steps to reproduce

install rust, install wasmer gem, clone repo and run example applications

Expected behavior

Examples should work

Actual behavior

$ ruby simple.rb
simple.rb:7:in `<main>': uninitialized constant Wasmer::Instance (NameError)
Did you mean?  Instance
$ ruby memory.rb
memory.rb:7:in `<main>': uninitialized constant Wasmer::Instance (NameError)
Did you mean?  Instance
$ ruby greet.rb
greet.rb:9:in `<main>': uninitialized constant Wasmer::Instance (NameError)

Rutie is able to open library

Rutie.new(:wasmer).init('Init_wasmer', "$HOME/wasmerio/ruby-ext-wasm/target/")
 => #<Fiddle::Pointer:0x00007f927603caa0 ptr=0x00007ffeea97d4f0 size=0 free=0x0000000000000000>

Additional context

$ rustc --version
rustc 1.36.0 (a53f9df32 2019-07-03)
$ wasmer --version
wasmer 0.6.0
$ ruby --version
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-darwin18]

OS: MacOS 10.14.6

gem install fails with Rust 1.46.0

Thanks for the bug report!

Describe the bug

I'm trying to install wasmer with Ruby 2.6.3 and Rust 1.46.0, but install fails with a bunch of errors like error: externfn uses typeinstance::RubyInstance, which is not FFI-safe (rutie issue #128. I have a number of other rutie projects and those are fine (I started getting the same issue when Rust 1.46 came out).

Steps to reproduce

  1. gem install wasmer
  2. See error

Expected behavior

Successful install.

Actual behavior

current directory: /Users/sloveless/.gem/ruby/2.6.3/gems/wasmer-0.4.0
/Users/sloveless/.rubies/ruby-2.6.3/bin/ruby -I/Users/sloveless/.rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems -rrubygems /Users/sloveless/.gem/ruby/2.6.3/gems/rake-13.0.1/exe/rake RUBYARCHDIR\=/Users/sloveless/.gem/ruby/2.6.3/extensions/x86_64-darwin-19/2.6.0/wasmer-0.4.0 RUBYLIBDIR\=/Users/sloveless/.gem/ruby/2.6.3/extensions/x86_64-darwin-19/2.6.0/wasmer-0.4.0
fatal: not a git repository (or any of the parent directories): .git
bundle install
fatal: not a git repository (or any of the parent directories): .git
Fetching gem metadata from https://rubygems.org/...
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.1
Using builder 3.2.4
Using bundler 2.1.4
Using minitest 5.14.2
Using ruby-progressbar 1.10.1
Using rutie 0.0.4
Fetching ansi 1.5.0
Using wasmer 0.4.0 from source at `.`
ctags: Warning: -f option specified more than once, last value used
ctags: Warning: cannot open source file "../extensions/x86_64-darwin-19/2.6.0/wasmer-0.4.0" : No such file or directory
Installing ansi 1.5.0
ctags: Warning: -f option specified more than once, last value used
Fetching minitest-reporters 1.4.2
Installing minitest-reporters 1.4.2
ctags: Warning: -f option specified more than once, last value used
Fetching color_pound_spec_reporter 0.0.9
Installing color_pound_spec_reporter 0.0.9
ctags: Warning: -f option specified more than once, last value used
Bundle complete! 6 Gemfile dependencies, 10 gems now installed.
Gems in the group production were not installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
cargo build --release
 Downloading crates ...
  Downloaded cranelift-codegen-shared v0.52.0
  Downloaded wasmer-clif-fork-frontend v0.52.0
  Downloaded wasmparser v0.45.2
  Downloaded cranelift-codegen v0.52.0
  Downloaded wasmer-runtime-core v0.14.1
  Downloaded wasmer-clif-backend v0.14.1
  Downloaded serde-bench v0.0.7
  Downloaded page_size v0.4.2
  Downloaded wasmer-runtime v0.14.1
  Downloaded cranelift-codegen-meta v0.52.0
  Downloaded cranelift-entity v0.52.0
  Downloaded cranelift-native v0.52.0
  Downloaded cranelift-bforest v0.52.0
  Downloaded blake3 v0.1.5
  Downloaded wasmer-clif-fork-wasm v0.52.0
   Compiling semver-parser v0.7.0
   Compiling cfg-if v0.1.10
   Compiling typenum v1.11.2
   Compiling autocfg v1.0.0
   Compiling libc v0.2.67
   Compiling cc v1.0.50
   Compiling proc-macro2 v1.0.9
   Compiling unicode-xid v0.2.0
   Compiling syn v1.0.16
   Compiling byteorder v1.3.4
   Compiling lazy_static v1.4.0
   Compiling maybe-uninit v2.0.0
   Compiling smallvec v1.2.0
   Compiling serde v1.0.104
   Compiling cranelift-codegen-shared v0.52.0
   Compiling cranelift-entity v0.52.0
   Compiling scopeguard v1.1.0
   Compiling target-lexicon v0.9.0
   Compiling log v0.4.8
   Compiling bitflags v1.2.1
   Compiling subtle v1.0.0
   Compiling constant_time_eq v0.1.5
   Compiling arrayref v0.3.6
   Compiling arrayvec v0.5.1
   Compiling nix v0.15.0
   Compiling rayon-core v1.7.0
   Compiling wasmparser v0.45.2
   Compiling void v1.0.2
   Compiling either v1.5.3
   Compiling hex v0.4.2
   Compiling rutie v0.7.0
   Compiling semver v0.9.0
   Compiling crossbeam-utils v0.7.2
   Compiling crossbeam-epoch v0.8.2
   Compiling indexmap v1.3.2
   Compiling lock_api v0.3.3
   Compiling cranelift-codegen-meta v0.52.0
   Compiling cranelift-bforest v0.52.0
   Compiling rustc_version v0.2.3
   Compiling blake3 v0.1.5
   Compiling memoffset v0.5.3
   Compiling raw-cpuid v7.0.3
   Compiling quote v1.0.2
   Compiling smallvec v0.6.13
   Compiling generic-array v0.12.3
   Compiling num_cpus v1.12.0
   Compiling parking_lot_core v0.7.0
   Compiling errno v0.2.4
   Compiling page_size v0.4.2
   Compiling memmap v0.7.0
   Compiling crossbeam-queue v0.2.1
   Compiling digest v0.8.1
   Compiling crypto-mac v0.7.0
   Compiling parking_lot v0.10.0
   Compiling crossbeam-deque v0.7.3
   Compiling wasmer-runtime-core v0.14.1
   Compiling rayon v1.3.0
   Compiling thiserror-impl v1.0.11
   Compiling serde_derive v1.0.104
   Compiling bincode v1.2.1
   Compiling serde-bench v0.0.7
   Compiling serde_bytes v0.11.3
   Compiling thiserror v1.0.11
   Compiling cranelift-codegen v0.52.0
   Compiling wasmer-clif-fork-frontend v0.52.0
   Compiling cranelift-native v0.52.0
   Compiling wasmer-clif-fork-wasm v0.52.0
   Compiling wasmer-clif-backend v0.14.1
   Compiling wasmer-runtime v0.14.1
   Compiling ruby-ext-wasm v0.4.0 (/Users/sloveless/.gem/ruby/2.6.3/gems/wasmer-0.4.0)
error: `extern` fn uses type `instance::RubyInstance`, which is not FFI-safe
  --> src/instance/mod.rs:51:5
   |
51 |     RubyInstance,
   |     ^^^^^^^^^^^^ not FFI-safe
   |
note: the lint level is defined here
  --> src/lib.rs:1:9
   |
1  | #![deny(warnings)]
   |         ^^^^^^^^
   = note: `#[deny(improper_ctypes_definitions)]` implied by `#[deny(warnings)]`
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> src/instance/mod.rs:47:1
   |
47 | class!(RubyInstance);
   | ^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::RubyInstance`, which is not FFI-safe
  --> src/instance/mod.rs:51:5
   |
51 |     RubyInstance,
   |     ^^^^^^^^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> src/instance/mod.rs:47:1
   |
47 | class!(RubyInstance);
   | ^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::exports::RubyExportedFunctions`, which is not FFI-safe
   --> src/instance/exports.rs:178:5
    |
178 |     RubyExportedFunctions,
    |     ^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/instance/exports.rs:174:1
    |
174 | class!(RubyExportedFunctions);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::exports::RubyExportedFunctions`, which is not FFI-safe
   --> src/instance/exports.rs:196:13
    |
196 |     itself: RubyExportedFunctions,
    |             ^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/instance/exports.rs:174:1
    |
174 | class!(RubyExportedFunctions);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `rutie::AnyObject`, which is not FFI-safe
   --> src/instance/exports.rs:197:6
    |
197 | ) -> AnyObject {
    |      ^^^^^^^^^ not FFI-safe
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout

error: `extern` fn uses type `instance::globals::RubyExportedGlobals`, which is not FFI-safe
  --> src/instance/globals.rs:77:5
   |
77 |     RubyExportedGlobals,
   |     ^^^^^^^^^^^^^^^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> src/instance/globals.rs:73:1
   |
73 | class!(RubyExportedGlobals);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::globals::RubyExportedGlobals`, which is not FFI-safe
  --> src/instance/globals.rs:95:13
   |
95 |     itself: RubyExportedGlobals,
   |             ^^^^^^^^^^^^^^^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> src/instance/globals.rs:73:1
   |
73 | class!(RubyExportedGlobals);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::globals::RubyExportedGlobal`, which is not FFI-safe
   --> src/instance/globals.rs:96:6
    |
96  | ) -> RubyExportedGlobal {
    |      ^^^^^^^^^^^^^^^^^^ not FFI-safe
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/instance/globals.rs:155:1
    |
155 | class!(RubyExportedGlobal);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::globals::RubyExportedGlobal`, which is not FFI-safe
   --> src/instance/globals.rs:159:5
    |
159 |     RubyExportedGlobal,
    |     ^^^^^^^^^^^^^^^^^^ not FFI-safe
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/instance/globals.rs:155:1
    |
155 | class!(RubyExportedGlobal);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::RubyMemory`, which is not FFI-safe
  --> src/memory/mod.rs:77:5
   |
77 |     RubyMemory,
   |     ^^^^^^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> src/memory/mod.rs:73:1
   |
73 | class!(RubyMemory);
   | ^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `module::Module`, which is not FFI-safe
 --> src/module.rs:7:5
  |
7 |     Module,
  |     ^^^^^^ not FFI-safe
  |
  = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
  = note: this struct has unspecified layout
note: the type is defined here
 --> src/module.rs:4:1
  |
4 | class!(Module);
  | ^^^^^^^^^^^^^^^
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::uint8array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
140 | memory_view!(uint8array over u8|1);
    | ----------------------------------- in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:140:1
    |
140 | memory_view!(uint8array over u8|1);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::int8array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
141 | memory_view!(int8array over i8|1);
    | ---------------------------------- in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:141:1
    |
141 | memory_view!(int8array over i8|1);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::uint16array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
142 | memory_view!(uint16array over u16|2);
    | ------------------------------------- in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:142:1
    |
142 | memory_view!(uint16array over u16|2);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::int16array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
143 | memory_view!(int16array over i16|2);
    | ------------------------------------ in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:143:1
    |
143 | memory_view!(int16array over i16|2);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::uint32array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
144 | memory_view!(uint32array over u32|4);
    | ------------------------------------- in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:144:1
    |
144 | memory_view!(uint32array over u32|4);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::int32array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
145 | memory_view!(int32array over i32|4);
    | ------------------------------------ in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:145:1
    |
145 | memory_view!(int32array over i32|4);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 17 previous errors

error: could not compile `ruby-ext-wasm`.

To learn more, run the command again with --verbose.
rake aborted!
Command failed with status (101): [cargo build --release...]
/Users/sloveless/.gem/ruby/2.6.3/gems/wasmer-0.4.0/Rakefile:7:in `block in <top (required)>'
/Users/sloveless/.gem/ruby/2.6.3/gems/rake-13.0.1/exe/rake:27:in `<main>'
Tasks: TOP => default => test => build_lib
(See full trace by running task with --trace)

rake failed, exit code 1

Install fails on Ruby 3.0.1

Describe the bug

RubyGems install of wasmer 0.4.0 fails on Ruby 3.0.1.

(NOTE: Ruby 3 has been released as stable in December.)

Steps to reproduce

  1. gem install wasmer (on Ruby 3.0.1).
  2. See error

Expected behavior

Install the package and not to fail.

Actual behavior

gem install wasmer
Building native extensions. This could take a while...                                                                              
ERROR:  Error installing wasmer:                                                                                                    
        ERROR: Failed to build gem native extension.
    current directory: /opt/rubies/ruby-3.0.1/lib/ruby/gems/3.0.0/gems/wasmer-0.4.0/opt/rubies/ruby-3.0.1/bin/ruby -I/opt/rubies/ruby-3.0.1/lib/ruby/3.0.0 -rrubygems /opt/rubies/ruby-3.0.1/lib/ruby/gems/3.0.0/gems/r
ake-13.0.3/exe/rake RUBYARCHDIR\=/opt/rubies/ruby-3.0.1/lib/ruby/gems/3.0.0/extensions/x86_64-linux/3.0.0-static/wasmer-0.4.0 RUBYLI
BDIR\=/opt/rubies/ruby-3.0.1/lib/ruby/gems/3.0.0/extensions/x86_64-linux/3.0.0-static/wasmer-0.4.0
fatal: not a git repository (or any of the parent directories): .git
bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application
for all non-root users on this machine.
fatal: not a git repository (or any of the parent directories): .git
Fetching gem metadata from https://rubygems.org/...
Resolving dependencies...
Using rake 13.0.3
Using ansi 1.5.0
Using builder 3.2.4
Using bundler 2.2.15
Using minitest 5.14.4
Using ruby-progressbar 1.11.0
Using minitest-reporters 1.4.3
Using color_pound_spec_reporter 0.0.9
Using rutie 0.0.4
Using wasmer 0.4.0 from source at `.`
Bundle complete! 6 Gemfile dependencies, 10 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
cargo build --release
rake aborted!
Command failed with status (127): [cargo build --release...]

Tasks: TOP => default => test => build_lib
(See full trace by running task with --trace)

rake failed, exit code 1

Gem files will remain installed in /opt/rubies/ruby-3.0.1/lib/ruby/gems/3.0.0/gems/wasmer-0.4.0 for inspection.
Results logged to /opt/rubies/ruby-3.0.1/lib/ruby/gems/3.0.0/extensions/x86_64-linux/3.0.0-static/wasmer-0.4.0/gem_make.out

Challenges in Running JS Interpreter via wasmer-ruby

Summary

My end goal is to be able to execute JavaScript code, server-side in a sandbox from Ruby.

I'm thinking that wasi is a good approach as that offers the sandbox. There is also multiple Javascript engines that have been compiled to wasi modules on wapm such as Spidermonkey (Firefox's JS engine), QuickJS, and duktape.

When I try to load any of these wasi modules I get an error it seems related to the FS API.

Spidermonkey

(irb):4:in `new': Error while importing "wasi_snapshot_preview1"."fd_read": unknown import. Expected Function(FunctionType { params: [I32, I32, I32, I32], results: [I32] }) (RuntimeError)
	from (irb):4:in `<main>'
	from /Users/eric/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/irb-1.3.5/exe/irb:11:in `<top (required)>'
	from /Users/eric/.rbenv/versions/3.0.4/bin/irb:23:in `load'
	from /Users/eric/.rbenv/versions/3.0.4/bin/irb:23:in `<main>'

Duktape

(irb):5:in `new': Error while importing "wasi_unstable"."fd_prestat_get": unknown import. Expected Function(FunctionType { params: [I32, I32], results: [I32] }) (RuntimeError)
	from (irb):5:in `<main>'
	from /Users/eric/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/irb-1.3.5/exe/irb:11:in `<top (required)>'
	from /Users/eric/.rbenv/versions/3.0.4/bin/irb:23:in `load'
	from /Users/eric/.rbenv/versions/3.0.4/bin/irb:23:in `<main>'

QuickJS

(irb):13:in `new': Error while importing "wasi_unstable"."fd_prestat_get": unknown import. Expected Function(FunctionType { params: [I32, I32], results: [I32] }) (RuntimeError)
	from (irb):13:in `<main>'
	from /Users/eric/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/irb-1.3.5/exe/irb:11:in `<top (required)>'
	from /Users/eric/.rbenv/versions/3.0.4/bin/irb:23:in `load'
	from /Users/eric/.rbenv/versions/3.0.4/bin/irb:23:in `<main>'

Am I just doing it wrong?

Is this built with Helix?

Summary

I see that a lot of the code for this project is written in Rust. I'm just curious if you've written this as a C extension, with Rust instead of C via Helix. I'm also curious if it is thus bound to MRI only or if it can run on other Ruby implementations, such as the up-and-coming speed demon TruffleRuby.

Seg fault with statically linked version of Ruby

Describe the bug

I'm using a statically linked version of Ruby 2.7.2 on macOS. I can build the gem (it links against libruby.2.7-static.a) but when I require the gem, I get a seg fault at lib/wasmer.rb:31. If I use a dynamically linked version of Ruby 2.7.2 (where the gem links against libruby.2.7.dylib) everything works fine.

Steps to reproduce

  1. On a Mac, build a statically linked version of Ruby 2.7.2 (e.g. RUBY_CONFIGURE_OPTS="--disable-shared" ruby-build 2.7.2 /path/to/install)
  2. Verify that /path/to/install/lib contains libruby.2.7-static.a
  3. Build the gem against this version of Ruby
  4. Open an IRB session
  5. Run require 'wasmer'

Expected behavior

No seg fault occurs.

Actual behavior

Seg fault occurs.

Additional context

Repeating the same steps with RUBY_CONFIGURE_OPTS="--enabled-shared" works just fine.

Too much rust too little Ruby

Summary

The README seems tailored to rust programmers not Ruby yet the project name is wasmer-ruby.

Additional details

Could you please abstract low-level (unimportant) details away and hide them from us Ruby programmers (perhaps in a wiki page or other file) and just give us Ruby programmer tailored instructions instead? I thought that would be obvious on any Ruby project. I just want to run this Opal Ruby project in wasm instead:
https://github.com/AndyObtiva/glimmer-dsl-opal

Don’t you have any automated or fast track Ruby-inside-the-browser instructions? I just want to hack on some Ruby in the browser within seconds and be happy (just like I did with Opal). I don’t want to muck with rust.

Thanks and Godspeed!

Andy Maleh

gem install fails with Rust 1.75.0

Describe the bug

We had some team members report issues when installing wasmer on MacOS with rustc 1.75.0 and Ruby 3.2.2. I was able to reproduce when I upgraded my rustc to 1.75.0, but when returning to 1.73.0 (which is what I was on prior), installation worked.

Steps to reproduce

  1. install v1.75.0 of rustc
  2. attempt to install the gem

Expected behavior

I'd expect the gem to compile and install successfully.

Actual behavior

When attempting to install with rustc 1.75.0, we get the following:

  Compiling wasmer v1.0.0 (/Users/{user}/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/wasmer-1.0.0/crates/wasmer)
error: unused import: `ClassInfo`
--> crates/wasmer/src/prelude.rs:3:62
  |
3 | pub use rutie_derive::{rubyclass, rubyfunction, rubymethods, ClassInfo, UpcastRubyClass};
  |                                                              ^^^^^^^^^
  |
note: the lint level is defined here
--> crates/wasmer/src/lib.rs:1:9
  |
1 | #![deny(warnings)]
  |         ^^^^^^^^
  = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]`


error: could not compile `wasmer` (lib) due to previous error
rake aborted!

Failed to install this gem

Summary

Hi guys, when I install this gem, it said 'could not compile ruby-ext-wasm' with 17 errors. It's all about "not FFI-safe". Could you give me some advice here?
(I'm using Ubuntu 20.04, and rbenv)

Additional details

rustc -V
rustc 1.46.0 (04488afe3 2020-08-24)

rustup -V
rustup 1.22.1 (b01adbbc3 2020-07-08)

cargo -V
cargo 1.46.0 (149022b1d 2020-07-17)

ruby -v
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]

Error log

$ gem install wasmer --verbose                                                                                                                                                                                                                        ⬡ 12.18.3 [±signing ●●]
HEAD https://rubygems.org/api/v1/dependencies
200 OK
GET https://rubygems.org/api/v1/dependencies?gems=wasmer
200 OK
GET https://rubygems.org/api/v1/dependencies?gems=rutie
200 OK
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/.cargo/config
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/.github/ISSUE_TEMPLATE/---bug-report.md
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/.github/ISSUE_TEMPLATE/---feature-request.md
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/.github/ISSUE_TEMPLATE/--question.md
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/.github/workflows/test.yml
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/.gitignore
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/CHANGELOG.md
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/Cargo.lock
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/Cargo.toml
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/Gemfile
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/LICENSE
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/README.md
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/Rakefile
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/bors.toml
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/justfile
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/lib/wasmer.rb
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/lib/wasmer/version.rb
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/src/error.rs
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/src/instance/exports.rs
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/src/instance/globals.rs
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/src/instance/mod.rs
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/src/lib.rs
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/src/memory/mod.rs
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/src/memory/view.rs
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/src/module.rs
/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0/wasmer.gemspec
Building native extensions. This could take a while...
current directory: /home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0
["/home/nam/.rbenv/versions/2.6.6/bin/ruby", "-rrubygems", "/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/exe/rake", "RUBYARCHDIR=/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/wasmer-0.4.0", "RUBYLIBDIR=/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/wasmer-0.4.0"]
bundle install
Fetching gem metadata from https://rubygems.org/...
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.1
Using ansi 1.5.0
Using builder 3.2.4
Using bundler 2.1.4
Using minitest 5.14.2
Using ruby-progressbar 1.10.1
Using minitest-reporters 1.4.2
Using color_pound_spec_reporter 0.0.9
Using rutie 0.0.4
Using wasmer 0.4.0 from source at `.`
Bundle complete! 6 Gemfile dependencies, 10 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
cargo build --release
   Compiling cfg-if v0.1.10
   Compiling semver-parser v0.7.0
   Compiling autocfg v1.0.0
   Compiling libc v0.2.67
   Compiling proc-macro2 v1.0.9
   Compiling unicode-xid v0.2.0
   Compiling cc v1.0.50
   Compiling syn v1.0.16
   Compiling typenum v1.11.2
   Compiling byteorder v1.3.4
   Compiling lazy_static v1.4.0
   Compiling maybe-uninit v2.0.0
   Compiling cranelift-entity v0.52.0
   Compiling smallvec v1.2.0
   Compiling cranelift-codegen-shared v0.52.0
   Compiling serde v1.0.104
   Compiling scopeguard v1.1.0
   Compiling target-lexicon v0.9.0
   Compiling bitflags v1.2.1
   Compiling log v0.4.8
   Compiling subtle v1.0.0
   Compiling arrayref v0.3.6
   Compiling constant_time_eq v0.1.5
   Compiling arrayvec v0.5.1
   Compiling rayon-core v1.7.0
   Compiling nix v0.15.0
   Compiling void v1.0.2
   Compiling wasmparser v0.45.2
   Compiling hex v0.4.2
   Compiling either v1.5.3
   Compiling rutie v0.7.0
   Compiling semver v0.9.0
   Compiling cranelift-bforest v0.52.0
   Compiling lock_api v0.3.3
   Compiling cranelift-codegen-meta v0.52.0
   Compiling crossbeam-utils v0.7.2
   Compiling crossbeam-epoch v0.8.2
   Compiling indexmap v1.3.2
   Compiling rustc_version v0.2.3
   Compiling quote v1.0.2
   Compiling memoffset v0.5.3
   Compiling generic-array v0.12.3
   Compiling smallvec v0.6.13
   Compiling num_cpus v1.12.0
   Compiling parking_lot_core v0.7.0
   Compiling page_size v0.4.2
   Compiling errno v0.2.4
   Compiling memmap v0.7.0
   Compiling crypto-mac v0.7.0
   Compiling digest v0.8.1
   Compiling blake3 v0.1.5
   Compiling raw-cpuid v7.0.3
   Compiling parking_lot v0.10.0
   Compiling crossbeam-queue v0.2.1
   Compiling serde-bench v0.0.7
   Compiling bincode v1.2.1
   Compiling serde_bytes v0.11.3
   Compiling crossbeam-deque v0.7.3
   Compiling rayon v1.3.0
   Compiling wasmer-runtime-core v0.14.1
   Compiling thiserror-impl v1.0.11
   Compiling serde_derive v1.0.104
   Compiling thiserror v1.0.11
    Building [================================================>      ] 100/112: cranelift-codegen-meta, serde_derive                                                                                                                                                          

   Compiling cranelift-codegen v0.52.0
   Compiling wasmer-clif-fork-frontend v0.52.0
   Compiling cranelift-native v0.52.0
   Compiling wasmer-clif-fork-wasm v0.52.0
   Compiling wasmer-clif-backend v0.14.1
   Compiling wasmer-runtime v0.14.1
   Compiling ruby-ext-wasm v0.4.0 (/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0)
error: `extern` fn uses type `instance::RubyInstance`, which is not FFI-safe
  --> src/instance/mod.rs:51:5
   |
51 |     RubyInstance,
   |     ^^^^^^^^^^^^ not FFI-safe
   |
note: the lint level is defined here
  --> src/lib.rs:1:9
   |
1  | #![deny(warnings)]
   |         ^^^^^^^^
   = note: `#[deny(improper_ctypes_definitions)]` implied by `#[deny(warnings)]`
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> src/instance/mod.rs:47:1
   |
47 | class!(RubyInstance);
   | ^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::RubyInstance`, which is not FFI-safe
  --> src/instance/mod.rs:51:5
   |
51 |     RubyInstance,
   |     ^^^^^^^^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> src/instance/mod.rs:47:1
   |
47 | class!(RubyInstance);
   | ^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::exports::RubyExportedFunctions`, which is not FFI-safe
   --> src/instance/exports.rs:178:5
    |
178 |     RubyExportedFunctions,
    |     ^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/instance/exports.rs:174:1
    |
174 | class!(RubyExportedFunctions);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::exports::RubyExportedFunctions`, which is not FFI-safe
   --> src/instance/exports.rs:196:13
    |
196 |     itself: RubyExportedFunctions,
    |             ^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/instance/exports.rs:174:1
    |
174 | class!(RubyExportedFunctions);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `rutie::AnyObject`, which is not FFI-safe
   --> src/instance/exports.rs:197:6
    |
197 | ) -> AnyObject {
    |      ^^^^^^^^^ not FFI-safe
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout

error: `extern` fn uses type `instance::globals::RubyExportedGlobals`, which is not FFI-safe
  --> src/instance/globals.rs:77:5
   |
77 |     RubyExportedGlobals,
   |     ^^^^^^^^^^^^^^^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> src/instance/globals.rs:73:1
   |
73 | class!(RubyExportedGlobals);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::globals::RubyExportedGlobals`, which is not FFI-safe
  --> src/instance/globals.rs:95:13
   |
95 |     itself: RubyExportedGlobals,
   |             ^^^^^^^^^^^^^^^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> src/instance/globals.rs:73:1
   |
73 | class!(RubyExportedGlobals);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::globals::RubyExportedGlobal`, which is not FFI-safe
   --> src/instance/globals.rs:96:6
    |
96  | ) -> RubyExportedGlobal {
    |      ^^^^^^^^^^^^^^^^^^ not FFI-safe
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/instance/globals.rs:155:1
    |
155 | class!(RubyExportedGlobal);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `instance::globals::RubyExportedGlobal`, which is not FFI-safe
   --> src/instance/globals.rs:159:5
    |
159 |     RubyExportedGlobal,
    |     ^^^^^^^^^^^^^^^^^^ not FFI-safe
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/instance/globals.rs:155:1
    |
155 | class!(RubyExportedGlobal);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::RubyMemory`, which is not FFI-safe
  --> src/memory/mod.rs:77:5
   |
77 |     RubyMemory,
   |     ^^^^^^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> src/memory/mod.rs:73:1
   |
73 | class!(RubyMemory);
   | ^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `module::Module`, which is not FFI-safe
 --> src/module.rs:7:5
  |
7 |     Module,
  |     ^^^^^^ not FFI-safe
  |
  = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
  = note: this struct has unspecified layout
note: the type is defined here
 --> src/module.rs:4:1
  |
4 | class!(Module);
  | ^^^^^^^^^^^^^^^
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::uint8array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
140 | memory_view!(uint8array over u8|1);
    | ----------------------------------- in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:140:1
    |
140 | memory_view!(uint8array over u8|1);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::int8array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
141 | memory_view!(int8array over i8|1);
    | ---------------------------------- in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:141:1
    |
141 | memory_view!(int8array over i8|1);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::uint16array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
142 | memory_view!(uint16array over u16|2);
    | ------------------------------------- in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:142:1
    |
142 | memory_view!(uint16array over u16|2);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::int16array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
143 | memory_view!(int16array over i16|2);
    | ------------------------------------ in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:143:1
    |
143 | memory_view!(int16array over i16|2);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::uint32array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
144 | memory_view!(uint32array over u32|4);
    | ------------------------------------- in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:144:1
    |
144 | memory_view!(uint32array over u32|4);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: `extern` fn uses type `memory::view::int32array::RubyMemoryView`, which is not FFI-safe
   --> src/memory/view.rs:90:17
    |
90  |                 RubyMemoryView,
    |                 ^^^^^^^^^^^^^^ not FFI-safe
...
145 | memory_view!(int32array over i32|4);
    | ------------------------------------ in this macro invocation
    |
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
note: the type is defined here
   --> src/memory/view.rs:145:1
    |
145 | memory_view!(int32array over i32|4);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 17 previous errors

error: could not compile `ruby-ext-wasm`.

To learn more, run the command again with --verbose.
rake aborted!
Command failed with status (101): [cargo build --release...]

Tasks: TOP => default => test => build_lib
(See full trace by running task with --trace)
ERROR:  Error installing wasmer:
	ERROR: Failed to build gem native extension.

    current directory: /home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0
/home/nam/.rbenv/versions/2.6.6/bin/ruby -rrubygems /home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/exe/rake RUBYARCHDIR\=/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/wasmer-0.4.0 RUBYLIBDIR\=/home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/wasmer-0.4.0
Building has failed. See above output for more information on the failure.
rake failed, exit code 1

Gem files will remain installed in /home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/wasmer-0.4.0 for inspection.
Results logged to /home/nam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/wasmer-0.4.0/gem_make.out

`undefining the allocator of T_DATA class ...` warning on Ruby 3.2

Describe the bug

In Ruby 3.2 all the wasmer classes when creating an instance now show a warning similar to:

warning: undefining the allocator of T_DATA class Wasmer::Store

It's not just Wasmer::Store that does this but I also see it on Wasmer::Module, Wasmer::Wasi::StateBuilder, Wasmer::Wasi::Environment and Wasmer::ImportObject.

Steps to reproduce

% irb
irb(main):001:0> require "wasmer"
=> true
irb(main):002:0> Wasmer::Store.new
(irb):2: warning: undefining the allocator of T_DATA class Wasmer::Store

Expected behavior

The instance should be created without a warning.

Actual behavior

I get a warning. It can be suppressed via $VERBOSE (or Rails' silence_warnings which is a wrapper for $VERBSOSE). The actual functionality seems to all work just fine.

Additional context

I was previously using Ruby 3.0.4 and did not get a warning with that version.

Feature request : new classes `Uint64View`, `Int64View`, `Float32View`, and `Float64View`

Hi!
Thank you for creating very useful library.

Motivation

I am building a tool as a hobby to call WebAssembly functions generated by Crystal language from Ruby to speed up. When I tried to pass a Ruby array to Wasm, I noticed that int64_view, uint64_view, float32_view, and float64_view were not yet provided.

Proposed solution

new methods: uint64_view, int64_view, float32_view, and float64_view
new classes Uint64View, Int64View, Float32View, and Float64View

Alternatives

The use of binary strings is a possible alternative. In that case, Ruby methods such as pack and unpack could be used.

Additional context

You can find similar functionality in Python bindings.
wasmerio/wasmer-python@b484654

instance.memory may cause a (small) problem in the future

Summary

At the current version of WebAssembly, an instance has at most one memory instance, but it may not be true in the future.

If there are more than one memory, the interface of instance.memory will not be the best interface.

Additional details

http://webassembly.github.io/spec/core/syntax/modules.html#syntax-mem

In the current version of WebAssembly, at most one memory may be defined or imported in a single module, and all constructs implicitly reference this memory 0. This restriction may be lifted in future versions.

Just for your information, the memory is exposed to the JavaScript API through exportsObject, ie. instance.exports.mem1.

https://webassembly.github.io/spec/js-api/#dom-module-exports

Cannot install on macOS with statically distributed Ruby version

Tried to install on macOS 11.4 (Big Sur) and got this error:

No such file or directory - getcwd

# context
which ruby 
/Users/my-user/.rubies/ruby-2.6.6/bin/ruby

ruby --version
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin20]
gem install wasmer -v '0.5.0' --verbose
HEAD https://rubygems.org/api/v1/dependencies
200 OK
GET https://rubygems.org/api/v1/dependencies?gems=wasmer
200 OK
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/.cargo/config
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/.github/ISSUE_TEMPLATE/---bug-report.md
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/.github/ISSUE_TEMPLATE/---feature-request.md
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/.github/ISSUE_TEMPLATE/--question.md
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/.github/workflows/documentation.yml
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/.github/workflows/test.yml
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/.gitignore
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/CHANGELOG.md
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/Cargo.lock
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/Cargo.toml
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/Gemfile
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/LICENSE
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/README.md
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/Rakefile
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/bors.toml
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-derive-macros/Cargo.toml
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-derive-macros/README.md
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-derive-macros/src/class.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-derive-macros/src/function.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-derive-macros/src/lib.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-derive-macros/src/methods.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-derive/Cargo.toml
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-derive/README.md
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-derive/src/lib.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-derive/src/upcast.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-test/Cargo.toml
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/rutie-test/src/lib.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/Cargo.toml
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/README.md
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/doc.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/error.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/exports.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/externals/function.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/externals/global.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/externals/memory.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/externals/mod.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/externals/table.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/import_object.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/instance.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/lib.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/memory/mod.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/memory/views.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/module.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/prelude.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/store.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/types.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/values.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/wasi.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/crates/wasmer/src/wat.rs
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/justfile
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/lib/wasmer.rb
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/wasmer.gemspec
Building native extensions. This could take a while...
current directory: /Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0
["/Users/my-user/.rubies/ruby-2.6.6/bin/ruby", "-rrubygems", "/Users/my-user/repos/proj1/application/.direnv/ruby/gems/rake-13.0.3/exe/rake", "RUBYARCHDIR=/Users/my-user/repos/proj1/application/.direnv/ruby/extensions/x86_64-darwin-20/2.6.0-static/wasmer-0.5.0", "RUBYLIBDIR=/Users/my-user/repos/proj1/application/.direnv/ruby/extensions/x86_64-darwin-20/2.6.0-static/wasmer-0.5.0"]
bundle config set --local path "vendor/bundle"
bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching source index from https://rubygems.org/
Resolving dependencies...
Using rake 13.0.3
Using concurrent-ruby 1.1.8
Using i18n 1.8.9
Using minitest 5.10.3
[… redacted for brevity]
Using therubyracer 0.12.3
Using tzinfo-data 1.2021.1
Using user_agent_parser 2.7.0
Fetching wasmer 0.5.0
Installing wasmer 0.5.0 with native extensions
Traceback (most recent call last):
	25: from /Users/my-user/repos/proj1/application/.direnv/bin/bundle:104:in `<main>'
	24: from /Users/my-user/repos/proj1/application/.direnv/bin/bundle:104:in `load'
	23: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:22:in `<top (required)>'
	22: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
	21: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:30:in `block in <top (required)>'
	20: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/cli.rb:18:in `start'
	19: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
	18: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/cli.rb:27:in `dispatch'
	17: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
	16: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
	15: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	14: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/cli.rb:234:in `install'
	13: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/settings.rb:143:in `temporary'
	12: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/cli.rb:235:in `block in install'
	11: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/cli/install.rb:65:in `run'
	10: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/installer.rb:25:in `install'
	 9: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/installer.rb:73:in `run'
	 8: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/process_lock.rb:9:in `lock'
	 7: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/process_lock.rb:9:in `open'
	 6: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/process_lock.rb:12:in `block in lock'
	 5: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/installer.rb:92:in `block in run'
	 4: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/installer.rb:197:in `install'
	 3: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/installer.rb:289:in `install_in_parallel'
	 2: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/installer/parallel_installer.rb:78:in `call'
	 1: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/installer/parallel_installer.rb:106:in `call'
/Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/installer/parallel_installer.rb:201:in `handle_error': Gem::Ext::BuildError: ERROR: Failed to build gem native extension. (Bundler::InstallError)

    No such file or directory - getcwd

Gem files will remain installed in /Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0 for inspection.
Results logged to /Users/my-user/repos/proj1/application/.direnv/ruby/extensions/x86_64-darwin-20/2.6.0-static/wasmer-0.5.0/gem_make.out

An error occurred while installing wasmer (0.5.0), and Bundler cannot continue.
Make sure that `gem install wasmer -v '0.5.0'` succeeds before bundling.

In Gemfile:
  wasmer
	13: from /Users/my-user/repos/proj1/application/.direnv/bin/bundle:104:in `<main>'
	12: from /Users/my-user/repos/proj1/application/.direnv/bin/bundle:104:in `load'
	11: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:22:in `<top (required)>'
	10: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
	 9: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:30:in `block in <top (required)>'
	 8: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/cli.rb:23:in `start'
	 7: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/cli.rb:23:in `ensure in start'
	 6: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/shared_helpers.rb:155:in `print_major_deprecations!'
	 5: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/shared_helpers.rb:272:in `search_up'
	 4: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/shared_helpers.rb:70:in `pwd'
	 3: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
	 2: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/shared_helpers.rb:71:in `block in pwd'
	 1: from /Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/shared_helpers.rb:71:in `pwd'
/Users/my-user/.rubies/ruby-2.6.6/lib/ruby/2.6.0/bundler/shared_helpers.rb:71:in `getwd': No such file or directory - getcwd (Errno::ENOENT)
rake aborted!
Command failed with status (1): [bundle install...]
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0/Rakefile:12:in `block in <top (required)>'
/Users/my-user/repos/proj1/application/.direnv/ruby/gems/rake-13.0.3/exe/rake:27:in `<main>'
Tasks: TOP => default => test => bundle_install
(See full trace by running task with --trace)
ERROR:  Error installing wasmer:
	ERROR: Failed to build gem native extension.

    current directory: /Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0
/Users/my-user/.rubies/ruby-2.6.6/bin/ruby -rrubygems /Users/my-user/repos/proj1/application/.direnv/ruby/gems/rake-13.0.3/exe/rake RUBYARCHDIR\=/Users/my-user/repos/proj1/application/.direnv/ruby/extensions/x86_64-darwin-20/2.6.0-static/wasmer-0.5.0 RUBYLIBDIR\=/Users/my-user/repos/proj1/application/.direnv/ruby/extensions/x86_64-darwin-20/2.6.0-static/wasmer-0.5.0
Building has failed. See above output for more information on the failure.
rake failed, exit code 1

Gem files will remain installed in /Users/my-user/repos/proj1/application/.direnv/ruby/gems/wasmer-0.5.0 for inspection.
Results logged to /Users/my-user/repos/proj1/application/.direnv/ruby/extensions/x86_64-darwin-20/2.6.0-static/wasmer-0.5.0/gem_make.out
cat /Users/cta/repos/skovik/application/.direnv/ruby/extensions/x86_64-darwin-20/2.6.0-static/wasmer-0.5.0/gem_make.out

current directory: /Users/cta/repos/skovik/application/.direnv/ruby/gems/wasmer-0.5.0
/Users/cta/.rubies/ruby-2.6.6/bin/ruby -rrubygems /Users/cta/repos/skovik/application/.direnv/ruby/gems/rake-13.0.3/exe/rake RUBYARCHDIR\=/Users/cta/repos/skovik/application/.direnv/ruby/extensions/x86_64-darwin-20/2.6.0-static/wasmer-0.5.0 RUBYLIBDIR\=/Users/cta/repos/skovik/application/.direnv/ruby/extensions/x86_64-darwin-20/2.6.0-static/wasmer-0.5.0
Building has failed. See above output for more information on the failure.
rake failed, exit code 1

WASI / import function support ?

I have a number of import statement in my WASM code to declare WASI functions and wahen I instantiate Wasmer and try to execute, I get the following error

RuntimeError: Failed to instantiate the module:
    5 link errors:
(1 of 5) Import not found, namespace: wasi_unstable, name: args_sizes_get
(2 of 5) Import not found, namespace: wasi_unstable, name: args_get
(3 of 5) Import not found, namespace: wasi_unstable, name: fd_write
(4 of 5) Import not found, namespace: wasi_unstable, name: fd_read
(5 of 5) Import not found, namespace: wasi_unstable, name: proc_exit

Wasmer is supposed to support WASI so I was wondering if this could be something to modify in ruby-ext-wasm to "make the connection" with imported functions ? (Not specifically WASI functions by the way....)

Thanks!

Crash when calling a WASM function with no result

Summary

I cannot call an exported WASM function from a wasmer instance. There seems to be some kind of runtime function and/opr static data wasmer is expecting from a WASM module but which ones ?

Any help is much appreciated

Details

I wrote the following minimal webassembly module in WAT text file

(module $simple
  (export "memory" (memory $0))
  (export "set_freep" (func $set_freep))

  (memory $0 1)

  (func $set_freep (param $value i32)
    (i32.store (i32.const 20) (local.get $value))
  )

  (func $main)

)

then compiled it to WASM code with wat2wasm (from the wabt toolkit). It is a straight compilation from WASM text format to wasm binary format with no additional runtime code if any kind

FInally I'm trying to instantiate this WASM module with wasmer

require 'wasmer'

bytes = File.read('/tmp/simple.wasm')
instance = Instance.new(bytes)
instance.exports.set_freep(1)

This code keeps generating the following error:

hread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libcore/slice/mod.rs:2686:10
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
fatal runtime error: failed to initiate panic, error 5
Aborted

And with stack trace

<ExportedFunctions:0x000057fb04b3e500>
thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libcore/slice/mod.rs:2686:10
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
   5: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:381
   6: rust_begin_unwind
             at src/libstd/panicking.rs:308
  7: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
   8: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:61
   9: wasmer::instance::ExportedFunctions::method_missing
  10: wasmer::instance::ruby_exported_functions_method_missing
....
....

Release version 1.0.1

I believe #58 fixes an issue for https://github.com/brave-intl/wasm-thumbnail , as it seems like the Rakefile line 12 in v1.0.0 seems to be causing issues as seen below:

#18 324.8 Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
#18 324.8
#18 324.8     current directory: /var/www/vendor/bundle/ruby/2.7.0/gems/wasmer-1.0.0
#18 324.8 /usr/local/bin/ruby -I/usr/local/lib/ruby/2.7.0/rubygems -rrubygems
#18 324.8 /var/www/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake
#18 324.8 RUBYARCHDIR\=/var/www/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux-musl/2.7.0/wasmer-1.0.0
#18 324.8 RUBYLIBDIR\=/var/www/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux-musl/2.7.0/wasmer-1.0.0
#18 324.8 fatal: not a git repository (or any of the parent directories): .git
#18 324.8 bundle config set --local path "vendor/bundle"
#18 324.8 bundle install
#18 324.8 The deployment setting requires a Gemfile.lock. Please make sure you have
#18 324.8 checked your Gemfile.lock into version control before deploying.
#18 324.8 rake aborted!
#18 324.8 Command failed with status (16): [bundle install...]
#18 324.8 /var/www/vendor/bundle/ruby/2.7.0/gems/wasmer-1.0.0/Rakefile:12:in `block in
#18 324.8 <top (required)>'
#18 324.8 /var/www/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<main>'
#18 324.8 Tasks: TOP => default => test => bundle_install
#18 324.8 (See full trace by running task with --trace)

Given it's a low risk change, would you be able to release 1.0.1?

Export Wasm globals ?

Hi there,

It is unclear to me whether one can access exported Wasm globals with ruby-ext-wasm. I tried and I got some kind of weird errors when instatiating a wasm module with exported globals like "global must be a const" (although the wasm code was perfectly valid)
Thanks!

Problem installing the gem

Summary

I am not able to install the gem, should I upgrade anything?

Tell me if you need additional information. Thanks

Additional details

OS: macOS Mojave 10.14.16

$ rustc -V
rustc 1.30.0 (da5f414c2 2018-10-24)

$ cargo -V
cargo 1.30.0 (36d96825d 2018-10-24)

$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]

$ gem install wasmer
Fetching wasmer-0.3.0.gem
Fetching rutie-0.0.4.gem
Successfully installed rutie-0.0.4
Building native extensions. This could take a while...
ERROR:  Error installing wasmer:
	ERROR: Failed to build gem native extension.

    current directory: /Users/jose.galisteo/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/wasmer-0.3.0
/Users/jose.galisteo/.rbenv/versions/2.6.5/bin/ruby -rrubygems /Users/jose.galisteo/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-13.0.0/exe/rake RUBYARCHDIR\=/Users/jose.galisteo/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/wasmer-0.3.0 RUBYLIBDIR\=/Users/jose.galisteo/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/wasmer-0.3.0
fatal: not a git repository (or any of the parent directories): .git
bundle install
fatal: not a git repository (or any of the parent directories): .git
Fetching gem metadata from https://rubygems.org/.............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Fetching rake 10.5.0
Installing rake 10.5.0
Fetching ansi 1.5.0
Installing ansi 1.5.0
Using builder 3.2.3
Using bundler 2.0.1
Fetching minitest 5.13.0
Installing minitest 5.13.0
Using ruby-progressbar 1.10.1
Fetching minitest-reporters 1.4.2
Installing minitest-reporters 1.4.2
Fetching color_pound_spec_reporter 0.0.9
Installing color_pound_spec_reporter 0.0.9
Using rutie 0.0.4
Using wasmer 0.3.0 from source at `.`
Bundle complete! 6 Gemfile dependencies, 10 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
cargo build --release
error: unable to get packages from source

Caused by:
  failed to parse manifest at `/Users/jose.galisteo/.cargo/registry/src/github.com-1ecc6299db9ec823/wasmer-clif-backend-0.5.5/Cargo.toml`

Caused by:
  feature `rename-dependency` is required

this Cargo does not support nightly features, but if you
switch to nightly channel you can add
`cargo-features = ["rename-dependency"]` to enable this feature
rake aborted!
Command failed with status (101): [cargo build --release...]

Tasks: TOP => default => test => build_lib
(See full trace by running task with --trace)

rake failed, exit code 1

Gem files will remain installed in /Users/jose.galisteo/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/wasmer-0.3.0 for inspection.
Results logged to /Users/jose.galisteo/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/wasmer-0.3.0/gem_make.out

Redirecting STDOUT and STDERR

Summary

When I run a wasi binary with this library the stdout and stderr are directed towards the application's stdout and stderr. I would rather capture that information to present it in my own way. Is there an option for that which I am missing.

Additional details

Right now I'm working around this issue by futzing with the file descriptors for the program but this seems less than ideal.

def capturing_output
  old_stdout = $stdout.dup
  old_stderr = $stderr.dup

  Tempfile.create '' do |stdout|
    $stdout.reopen stdout.path, 'w+'

    Tempfile.create '' do |stderr|
      $stderr.reopen stderr.path, 'w+'

      yield

      stdout.read
    rescue RuntimeError
      raise ScriptError.new stdout.read, stderr.read, $!.message
    end
  ensure
    $stdout.reopen old_stdout
    $stderr.reopen old_stderr
  end
end

capturing_output do
  Wasmer::Instance.new(module_, import).exports._start.()
end

It's both overly complicated and requires the use of files which is IO I would prefer to avoid. I expect my output to be very small so it would be ideal if I could provide a StringIO object to avoid that disk access.

[More Examples] Could more examples be added?

Could more examples be added?

Ideally something like a slow build-up step that showcases what can be done with it.

I'd also love some example where we could add functionality to a simple sinatra
application or something like that.

Right now I am a bit clueless what we can do with wasmer. Even opal makes this
more clear than wasmer.

More parity with other languages

It seems like the ruby sdk/client is still a bit behind the other languages. Would be awesome if more functionality was supported, for example terminate in host call, serialization and exposing host (imported) functions.

image

Source:
https://docs.wasmer.io/ecosystem/wasmer/wasmer-features#language-embeddings

For our use case, we'd like to pass in a bunch of data from the host (e.g. JSON like data), pass in a bunch of functions, accessible to the WASM-code, and then call the function exposed by WASM (with ability to abort/terminate from host).

Integer conversion raising en exception

When trying to call an exported WASM function from Ruby with a negative integer parameter an exception is raised.

The function call is:
@exports.i32_to_s.call(-1)
the parameter signature of the WASM func is i32

and the exception raised is
TypeError: out of range integral type conversion attempted

I have no trouble passing a positive value.
Is this the expected behavior ? How can I pass a negative value ? Do i Have to pass the 2-complement positive value (meaning 65535 here) ?

Thank you for your help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.