Code Monkey home page Code Monkey logo

wasmtime-demos's Introduction

Wasmtime Demos

This repository is now subsumed by the upstream wasmtime repository at https://github.com/bytecodealliance/wasmtime.

Historically this repository had a work-in-progress demo of the "Interface Types" proposal circa 2019 which has long since evolved past this point (as well as Wasmtime itself). None of the demos here still work today and most, if not all, of the design around the demos has significantly changed. Nowadays it's recommended to explore:

It is not recommended to use what's here in this repository for anything else nowadays, instead feel free to reach out on those repositories with questions and/or requests.

wasmtime-demos's People

Contributors

alexcrichton avatar fitzgen avatar peterhuene avatar samrat avatar sunfishcode avatar tschneidereit avatar vladikoff 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  avatar

wasmtime-demos's Issues

Rust example is an order of magnitude slower than wasmtime binary

time wasmtime markdown.wasm --invoke render "# Hello"
warning: using `--invoke` with a function that takes arguments is experimental and may break in the future
warning: using `--invoke` with a function that returns values is experimental and may break in the future
<h1>Hello</h1>


real    0m0.041s
user    0m0.039s
sys     0m0.005s

Rust:

time ./target/release/markdown 
Loaded in 475 ms
Rendered <h1>Hello, Rust!</h1>
 in 1 ms

real    0m0.484s
user    0m1.674s
sys     0m0.040s

I have added a stopwatch around load_file and render method. What could be the issue?

Building markdown failed while validating input.

I tried to compile the markdown example, but unfortunately compilation fails.

$ wasm-pack --version
wasm-pack 0.9.1
$ cargo --version
cargo 1.41.0 (626f0f40e 2019-12-03)

Here are the steps to reproduce. Not that I didn't copy full logs:

$ wasm-pack build
�[1m�[2m[INFO]�[0m: Checking for the Wasm target...
�[1m�[2m[INFO]�[0m: Checking for the Wasm target...
�[1m�[2m[INFO]�[0m: Compiling to Wasm...
�[1m�[2m[INFO]�[0m: Compiling to Wasm...
    Finished    Finished release [optimized] target(s) in 0.02s
 release [optimized] target(s) in 0.02s
�[1m�[2m[INFO]�[0m: Installing wasm-bindgen...
�[1m�[2m[INFO]�[0m: Installing wasm-bindgen...
�[1m�[2m[INFO]�[0m: Optimizing wasm binaries with `wasm-opt`...
�[1m�[2m[INFO]�[0m: Optimizing wasm binaries with `wasm-opt`...
[wasm-validator error in function render\20multivalue\20shim] (i32, i32) != i32: block with value and last element with value must match types, on
[(i32, i32)] [(i32, i32)] (block (result i32 i32)
 [none] (global.set $global$0
  [i32] (local.tee $2
   [i32] (i32.sub
    [i32] (global.get $global$0)
    [i32] (i32.const 16)
   )
  )
 )
 [none] (call $render
  [i32] (local.get $2)
  [i32] (local.get $0)
  [i32] (local.get $1)
 )
 [none] (local.set $3
  [i32] (i32.load
   [i32] (local.get $2)
  )
 )
 [none] (drop
  [i32] (i32.load offset=4
   [i32] (local.get $2)
  )
 )
 [none] (global.set $global$0
  [i32] (i32.add
   [i32] (local.get $2)
   [i32] (i32.const 16)
  )
 )
 [i32] (local.get $3)
) ;; end block
[...]
 (func $<T\20as\20core::any::Any>::type_id::ha8033cc8aaed9e29 (; 212 ;) (param $0 i32) (result i64)
  (i64.const 1229646359891580772)
 )
 (func $<T\20as\20core::any::Any>::type_id::h26c6ec07af71e373 (; 213 ;) (param $0 i32) (result i64)
  (i64.const -225553400743110688)
 )
 (func $<T\20as\20core::any::Any>::type_id::hf03814fcf300737e (; 214 ;) (param $0 i32) (result i64)
  (i64.const 2849073579228188672)
 )
 (func $std::process::abort::h83667d4dc61f8ff4 (; 215 ;)
  (unreachable)
 )
 (func $__rust_start_panic (; 216 ;) (param $0 i32) (result i32)
  (unreachable)
 )
 (func $dlmalloc::dlmalloc::Dlmalloc::malloc_alignment::hcee1c950df17a4f7 (; 217 ;) (param $0 i32) (result i32)
  (i32.const 8)
 )
 (func $<T\20as\20core::any::Any>::type_id::hcbe1e308a536e760 (; 218 ;) (param $0 i32) (result i64)
  (i64.const -225553400743110688)
 )
 (func $core::panic::Location::caller::h4586dda5eb624bd0 (; 219 ;) (param $0 i32) (result i32)
  (local.get $0)
 )
 (func $core::ptr::drop_in_place::hdf3ac4f0aee1b486 (; 220 ;) (param $0 i32)
 )
 (func $core::ptr::drop_in_place::ha08c4b3d9252f877 (; 221 ;) (param $0 i32)
 )
 (func $core::ptr::drop_in_place::he9358e90f45c44df (; 222 ;) (param $0 i32)
 )
 (func $core::ptr::drop_in_place::h01349a483699dc28 (; 223 ;) (param $0 i32)
 )
 (func $core::ptr::drop_in_place::h0293f9ecfaa56c65 (; 224 ;) (param $0 i32)
 )
 (func $core::ptr::drop_in_place::h86bf89378777bea4 (; 225 ;) (param $0 i32)
 )
 (func $core::ptr::drop_in_place::h3a3c6f3f877fe4f5 (; 226 ;) (param $0 i32)
 )
 (func $core::ptr::drop_in_place::h08414e5d2954751c (; 227 ;) (param $0 i32)
 )
 (func $std::alloc::default_alloc_error_hook::h9f234f4112b0e55e (; 228 ;) (param $0 i32) (param $1 i32)
 )
 (func $core::ptr::drop_in_place::h04478f7f402db464 (; 229 ;) (param $0 i32)
 )
 ;; custom section "producers", size 121
 ;; custom section "webidl-bindings", size 50
)
Fatal: error in validating input
Error: failed to execute `wasm-opt`: exited with exit code: 1
  full command: "/home/developer/.cache/.wasm-pack/wasm-opt-4d7a65327e9363b7/wasm-opt" "/home/developer/projects/wasmtime-demos/markdown/pkg/markdown.wasm" "-o" "/home/developer/projects/wasmtime-demos/markdown/pkg/markdown.wasm-opt.wasm" "-O"
To disable `wasm-opt`, add `wasm-opt = false` to your package metadata in your `Cargo.toml`.

I've tried the suggestion and modified the Cargo.toml and added the following lines:

[package.metadata.wasm-pack.profile.dev]
wasm-opt = false

But that didn't help

archive and mark this repository read-only

The README states that this repository is no longer in use / maintained, due to examples being included in the upstream repository bytecodealiance / wasmtime. I think this is a good change, so that the demos can evolve with the runtime.

However, the way this repository is set up is not clear - there are still issues being created here. The standard on GitHub is to put a big banner at the top of the README with a redirect to the new repository, and marking the repository read-only.

No module named '__wbindgen_placeholder__'

On a Linux host, following the instructions for the Python demo, I get the following errors:

$ cd markdown
$ cargo build --target wasm32-unknown-unknown
$ cp target/wasm32-unknown-unknown/debug/markdown.wasm ../python
$ cd ../python
$ python3 run.py 
Traceback (most recent call last):
  File "run.py", line 7, in <module>
    import markdown
  File "[...]/.local/lib/python3.6/site-packages/wasmtime/__init__.py", line 42, in exec_module
    imported_module = import_module(module_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '__wbindgen_placeholder__'
$ wasm2wat markdown.wasm |grep 'import.*wbindgen'
  (import "__wbindgen_placeholder__" "__wbindgen_describe" (func $__wbindgen_describe (type 0)))
  (import "__wbindgen_placeholder__" "__wbindgen_throw" (func $__wbindgen_throw (type 4)))
  (import "__wbindgen_anyref_xform__" "__wbindgen_anyref_table_grow" (func $__wbindgen_anyref_table_grow (type 6)))
  (import "__wbindgen_anyref_xform__" "__wbindgen_anyref_table_set_null" (func $__wbindgen_anyref_table_set_null (type 0)))

webpack and node.js demos fail with a version mismatch

ERROR in ./markdown.wasm
Module build failed (from ./node_modules/wasm-interface-types-loader/index.js):
NonErrorEmittedError: (Emitted value instead of an instance of Error) ErrorMessage { msg: "version mismatch in the bindings section: wasm file has 0.6.0 and this library supports 0.4.0" }

Dotnet demo crahses with TrapException

I am getting TrapException when trying to run dotnet demo.

Unhandled exception. Wasmtime.TrapException: trap during instantiation
   at Wasmtime.Instance..ctor(Module module, IHost host)
   at Wasmtime.Module.Instantiate(IHost host)
   at WasmtimeDemo.Program.Main() in C:\Users\Administrator\dev\wasmtime-demos\dotnet\Program.cs:line 20

I am following the instructions from:
https://github.com/bytecodealliance/wasmtime-demos/tree/master/dotnet

I have:

  • wasmtime-demos 171b4cb
  • Wasmtime.Dotnet.dll 0.8.0-preview2
  • dotnet 3.1.100

It reproduced on two machines for me.

Any ideas?

Getting an error when I tried the dotnet demo on .net core 3.1

I followed all the steps in the tutorial, but I couldnt get it to run. Below is the error.

c:\wasmtime-demos\dotnet>dotnet run
Unhandled exception. Wasmtime.WasmtimeException: Failed to bind function import 'wasi_snapshot_preview1.fd_write': the host does not contain a method with a matching 'Import' attribute.
at Wasmtime.Bindings.Binding.BindFunction(FunctionImport import, IEnumerable`1 methods)
at Wasmtime.Bindings.Binding.GetImportBindings(IHost host, Module module)
at Wasmtime.IHost.GetImportBindings(Module module)
at Wasmtime.Instance..ctor(Module module, IHost host)
at Wasmtime.Module.Instantiate(IHost host)
at WasmtimeDemo.Program.Main() in C:\Users\abbennet\workspace\wasi\wasmtime-demos\dotnet\Program.cs:line 20

dotnet demo error: unknown instruction LocalTee

Hi

I'm trying to run the dotnet demo by following the readme instructions:
https://github.com/bytecodealliance/wasmtime-demos/blob/06d5c28/dotnet/README.md

cargo wasi build --release fails with:

└─[$] cargo wasi build --release                                      [1:54:09]
info: downloading component 'rust-std' for 'wasm32-wasi'
info: installing component 'rust-std' for 'wasm32-wasi'
 19.6 MiB /  19.6 MiB (100 %)   9.8 MiB/s in  1s ETA:  0s
    Updating crates.io index
  Downloaded lazy_static v1.4.0
  Downloaded bitflags v1.3.2
  Downloaded version_check v0.9.4
  Downloaded unicode-ident v1.0.8
  Downloaded unicase v2.6.0
  Downloaded cfg-if v0.1.10
  Downloaded memchr v2.5.0
  Downloaded quote v1.0.26
  Downloaded log v0.4.17
  Downloaded syn v1.0.109
  Downloaded proc-macro2 v1.0.56
  Downloaded wasm-bindgen-macro-support v0.2.55
  Downloaded wasm-bindgen-macro v0.2.55
  Downloaded wasm-bindgen-shared v0.2.55
  Downloaded wasm-bindgen-backend v0.2.55
  Downloaded bumpalo v2.6.0
  Downloaded wasm-bindgen v0.2.55
  Downloaded pulldown-cmark v0.5.3
  Downloaded 18 crates (1.1 MB) in 6.18s
   Compiling proc-macro2 v1.0.56
   Compiling quote v1.0.26
   Compiling unicode-ident v1.0.8
   Compiling log v0.4.17
   Compiling syn v1.0.109
   Compiling wasm-bindgen-shared v0.2.55
   Compiling cfg-if v1.0.0
   Compiling version_check v0.9.4
   Compiling lazy_static v1.4.0
   Compiling bumpalo v2.6.0
   Compiling unicase v2.6.0
   Compiling memchr v2.5.0
   Compiling wasm-bindgen v0.2.55
   Compiling pulldown-cmark v0.5.3
   Compiling wasm-bindgen-backend v0.2.55
   Compiling wasm-bindgen-macro-support v0.2.55
   Compiling wasm-bindgen-macro v0.2.55
   Compiling cfg-if v0.1.10
   Compiling bitflags v1.3.2
   Compiling markdown v0.1.0 (/home/ubuntu/workspaces/wasmtime-demos/markdown)
    Finished release [optimized] target(s) in 19.11s
 Downloading precompiled wasm-bindgen v0.2.55
thread 'main' panicked at 'unknown instruction LocalTee(LocalTee { local: Id { idx: 1488 } })', crates/wasm-interpreter/src/lib.rs:372:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: failed to process wasm at `/home/ubuntu/workspaces/wasmtime-demos/markdown/target/wasm32-wasi/release/markdown.rustc.wasm`

Caused by:
    failed to execute "/home/ubuntu/.cache/cargo-wasi/0.1.27/wasm-bindgen/0.2.55/wasm-bindgen" "/home/ubuntu/workspaces/wasmtime-demos/markdown/target/wasm32-wasi/release/markdown.rustc.wasm" "--out-dir" "/home/ubuntu/workspaces/wasmtime-demos/markdown/target/wasm32-wasi/release/.tmpvAc9nR" "--out-name" "foo"
        status: exit status: 101

Ubuntu 22.04
cargo 1.68.2 (6feb7c9cf 2023-03-26)

Tables count error in Rust example (bad wasm?)

When running the Rust example, I get the following error:

$ cargo run
   Compiling markdown v0.1.0 (/Users/jkriss/Desktop/wasmtime-demos/rust)
    Finished dev [unoptimized + debuginfo] target(s) in 4.26s
     Running `target/debug/markdown`
Error: tables count must be at most 1 (at offset 405)

This is after cloning the repo, installing Rust nightly and wasm-pack, then:

cd markdown
export WASM_INTERFACE_TYPES=1
wasm-pack build
cd ../rust
cp ../markdown/pkg/markdown.wasm .

In the python example, I get:

$ python3 run.py 
Traceback (most recent call last):
  File "run.py", line 7, in <module>
    import markdown
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "/usr/local/lib/python3.7/site-packages/wasmtime/__init__.py", line 46, in exec_module
    res = instantiate(data, imports)
Exception: Validation error: module did not validate

It seems that something's going wrong with the initial wasm generation. Any ideas? This is with 1.42.0-nightly and wasm-pack 0.8.1.

Change default branch name

As a policy, the Bytecode Alliance is changing the default branch names in all repositories. We would like for all projects to change the default to main by June 26. (We mention June 26th because there is some suggestion that GitHub may be adding the ability to make this process more seamless. Feel free to wait for that, but only up to June 26. We'll provide further support and documentation before that date.)

Please consider this a tracking issue. It is not intended for public debate.

  • Change branch name
  • Update CI
  • Update build scripts
  • Update documentation

Two errors when trying to run the Python demo

C:\py\git>git clone https://github.com/bytecodealliance/wasmtime-demos
Cloning into 'wasmtime-demos'...
remote: Enumerating objects: 127, done.
Receiving objects: 100% (127/127), 29.73 KiB | 2.48 MiB/s, done.
Resolving deltas: 100% (38/38), done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 127 (delta 12), reused 10 (delta 10), pack-reused 112

C:\py\git>cd wasmtime-demos

C:\py\git\wasmtime-demos>cd markdown

C:\py\git\wasmtime-demos\markdown>cargo build --target=wasm32-unknown-unknown
Updating crates.io index
Compiling proc-macro2 v1.0.29
Compiling unicode-xid v0.2.2
Compiling log v0.4.14
Compiling wasm-bindgen-shared v0.2.55
Compiling syn v1.0.80
Compiling cfg-if v1.0.0
Compiling bumpalo v2.6.0
Compiling version_check v0.9.3
Compiling lazy_static v1.4.0
Compiling memchr v2.4.1
Compiling pulldown-cmark v0.5.3
Compiling wasm-bindgen v0.2.55
Compiling bitflags v1.3.2
Compiling cfg-if v0.1.10
Compiling unicase v2.6.0
Compiling quote v1.0.10
Compiling wasm-bindgen-backend v0.2.55
Compiling wasm-bindgen-macro-support v0.2.55
Compiling wasm-bindgen-macro v0.2.55
Compiling markdown v0.1.0 (C:\py\git\wasmtime-demos\markdown)
Finished dev [unoptimized + debuginfo] target(s) in 30.04s

C:\py\git\wasmtime-demos\markdown>
C:\py\git\wasmtime-demos\markdown>cd ..

C:\py\git\wasmtime-demos>cd python

C:\py\git\wasmtime-demos\python>copy ..\markdown\target\wasm32-unknown-unknown\debug\markdown.wasm
1 file(s) copied.

C:\py\git\wasmtime-demos\python>python run.py
Traceback (most recent call last):
File "C:\py\git\wasmtime-demos\python\run.py", line 7, in
import markdown
ModuleNotFoundError: No module named 'markdown'

C:\py\git\wasmtime-demos\python>python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import wasmtime.loader
import markdown
Traceback (most recent call last):
File "", line 1, in
File "C:\python\lib\site-packages\wasmtime\loader.py", line 72, in exec_module
imported_module = importlib.import_module(module_name)
File "C:\python\lib\importlib_init_.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'wbindgen_placeholder'

wasmtime demo command fail to execute markdown.wasm

Following the demo in this youtube video with a clone of this directory, I was unable to use wasmtime to run wasmtime markdown.wasm --invoke render "# Hello"

wasmtime version 0.9.0

Error:

~/wasmtime-demos/markdown(master) » wasmtime markdown.wasm --invoke render "# Hello" 
Error: failed to run main module `markdown.wasm`

Caused by:
    func type returns multiple values (at offset 47)

Exception: version mismatch in the bindings section

Running strictly from the example it looks like something in the instantiate function within wasmtime broke.

Traceback (most recent call last):
  File "run.py", line 7, in <module>
    import markdown
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "/private/tmp/wasmtime-demos/python/venv/lib/python3.7/site-packages/wasmtime/__init__.py", line 46, in exec_module
    res = instantiate(data, imports)
Exception: version mismatch in the bindings section: wasm file has `0.5.0` and this library supports `0.4.0`

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.