wapm-packages / cowsay Goto Github PK
View Code? Open in Web Editor NEWCowsay in WebAssembly
Home Page: https://wasmer.io/syrusakbary/cowsay
License: MIT License
Cowsay in WebAssembly
Home Page: https://wasmer.io/syrusakbary/cowsay
License: MIT License
Hi, I'm playing with @wasmer/wasi in the browser environment found out that the current version of cowsay downloaded via wapm (0.2.0) doesn't work, resulting in the below exception. Note that other packages do work using with the following code snippet. So far I only tried cowsay and "huhn/hello-wasm".
Exception from chrome:
Uncaught (in promise) RuntimeError: unreachable
at rust_panic (:wasm-function[685]:0x4d8e6)
at _ZN3std9panicking20rust_panic_with_hook17h915896130bbbef4eE (:wasm-function[202]:0x1a04b)
at _ZN3std9panicking18continue_panic_fmt17h273222db9d5894b3E (:wasm-function[720]:0x4ef61)
at rust_begin_unwind (:wasm-function[619]:0x4afb4)
at _ZN4core9panicking9panic_fmt17hade9d5174dac2b2bE (:wasm-function[249]:0x1e388)
at _ZN4core9panicking18panic_bounds_check17h55b51e817be982c8E (:wasm-function[37]:0x2e0e)
at _ZN6cowsay4main17h8d51d1f6d9e8b09aE (:wasm-function[44]:0x5c5f)
at ZN3std2rt10lang_start28$u7b$ $u7b$closure$u7d$$u7d$17h269cebd620f9f473E (:wasm-function[20]:0x1bcb)
at _ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17hc121d5dc89b45d51E (:wasm-function[112]:0x13fdf)
at main (:wasm-function[110]:0x13d79)
Also happens in firefox.
import * as React from 'react';
import { WASI } from "@wasmer/wasi";
import wasiBindings from "@wasmer/wasi/lib/bindings/browser";
import { WasmFs } from "@wasmer/wasmfs";
const wasmFs = new WasmFs();
const wasi = new WASI({
args: [],
env: {},
bindings: {
...wasiBindings,
fs: wasmFs.fs
}
});
const startWasiTask = async () => {
const response = await fetch("./cowsay.wasm");
const responseArrayBuffer = await response.arrayBuffer();
const wasm_bytes = new Uint8Array(responseArrayBuffer);
let module = await WebAssembly.compile(wasm_bytes);
let instance = await WebAssembly.instantiate(module, {
...wasi.getImports(module)
});
wasi.start(instance);
const stdout = await wasmFs.getStdOut();
console.log(stdout);
};
startWasiTask();
$ echo -e a\nb\nc | cowsay
_______
< a b c >
-------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
vs
$ echo -e a\nb\nc | cargo run --
_______
< a
b
c >
-------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Might also need some extra treatment for full-width characters…
_______________________________
< ありがとうMrロボット >
-------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
(admittedly, normal cowsay also fails on this one)
$ echo ありがとうMrロボット | cowsay
_____________
< ありがとうMrロボット >
-------------
\ ^__^
Title^
Here's the backtrace:
thread 'main' panicked at 'internal error: entered unreachable code', /Users/syrusakbary/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.4.6/src/jitter.rs:703:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: RuntimeError: unreachable
at rust_panic (<module>[581]:0x467b5)
at std::panicking::rust_panic_with_hook::h1c67ce6bc4eb31b7 (<module>[270]:0x1ad0c)
at std::panicking::begin_panic_handler::{{closure}}::h749586aa4ef76f6f (<module>[590]:0x46f51)
at std::sys_common::backtrace::__rust_end_short_backtrace::h426b71926848cb31 (<module>[589]:0x46eb9)
at rust_begin_unwind (<module>[491]:0x41603)
at core::panicking::panic_fmt::hf4ce15c1b219b988 (<module>[91]:0x10fa0)
at core::panicking::panic::h8fa39a92dcc1b069 (<module>[86]:0x108a5)
at rand::StdRng::new::hb4f63eea71fa4728 (<module>[70]:0xfacb)
at cowsay::main::h0341b02cf26fb7f7 (<module>[34]:0x48b0)
at std::sys_common::backtrace::__rust_begin_short_backtrace::hd209db048344c68d (<module>[13]:0x109d)
at __main_void (<module>[93]:0x1116a)
at _start (<module>[9]:0x6f7)
╰─▶ 1: RuntimeError: unreachable
at rust_panic (<module>[581]:0x467b5)
at std::panicking::rust_panic_with_hook::h1c67ce6bc4eb31b7 (<module>[270]:0x1ad0c)
at std::panicking::begin_panic_handler::{{closure}}::h749586aa4ef76f6f (<module>[590]:0x46f51)
at std::sys_common::backtrace::__rust_end_short_backtrace::h426b71926848cb31 (<module>[589]:0x46eb9)
at rust_begin_unwind (<module>[491]:0x41603)
at core::panicking::panic_fmt::hf4ce15c1b219b988 (<module>[91]:0x10fa0)
at core::panicking::panic::h8fa39a92dcc1b069 (<module>[86]:0x108a5)
at rand::StdRng::new::hb4f63eea71fa4728 (<module>[70]:0xfacb)
at cowsay::main::h0341b02cf26fb7f7 (<module>[34]:0x48b0)
at std::sys_common::backtrace::__rust_begin_short_backtrace::hd209db048344c68d (<module>[13]:0x109d)
at __main_void (<module>[93]:0x1116a)
at _start (<module>[9]:0x6f7)
I executed this on MacBook Pro x86
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.