Giter VIP home page Giter VIP logo

second-state / wasm-learning Goto Github PK

View Code? Open in Web Editor NEW
475.0 15.0 101.0 472.73 MB

Building Rust functions for Node.js to take advantage of Rust's performance, WebAssembly's security and portability, and JavaScript's ease-of-use. Demo code and recipes.

Home Page: https://www.secondstate.io/articles/getting-started-with-rust-function/

JavaScript 2.05% HTML 16.67% Rust 79.12% Dockerfile 0.07% TypeScript 0.09% Shell 0.65% Python 1.01% Go 0.17% WebAssembly 0.03% C 0.14%
wasm webassembly webassembly-tutorial rust javascript nodejs microservice tutorial getting-started beginner wasm-bindgen wasm-pack ssvm ssvmup

wasm-learning's Introduction

Learning WebAssembly, Rust, and Node.js

Brought to you by the Open source dev team at Second State. Follow us on Twitter, Facebook, LinkedIn, YouTube, or Medium.

On the server side in Node.js

Node.js examples

Developers: Getting started building Rust + JavaScript hybrid apps for Node.js.

  • Rust's performance
  • WebAssembly's security and portability
  • JavaScript's ease-of-use

Quickstart: Fork this repository and start editing the source code files on GitHub. Learn more.

Hello World

Function input and return values

Passing and return values of arbitrary types from Node.js to Rust

Calling Node.js functions from Rust

RSA public key encryption

Machine learning with k-means

Inside the web browser

Those examples demonstrate how to access WASM programs from the JS engine inside web browsers.

A basic example to perform numeric computation in WASM

An example to manipulate strings in a WASM program

Learning Rust

Getting started

Command line input and output

wasm-learning's People

Contributors

alabulei1 avatar alfaevc avatar battmdpkq avatar byteshiva avatar dlcmh avatar hydai avatar juntao avatar l-jasmine avatar mileyfu avatar o3ol avatar q82419 avatar satacker avatar tieway59 avatar tpmccallum avatar xxchan 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

wasm-learning's Issues

issue

Where can I find "MobilenetV1/Predictions/Softmax"?

issue2

When I run "let rect = Rect::at(x1, y1).of_size((x2 - x1) as u32 , (y2 - y1) as u32);"
errors comes:
width must be strictly positive
How can I fix it?

Add `rustup target add wasm32-wasi` into the `wasm-learning/cli/hello/` example

The hello file does not mention rustup target add wasm32-wasi before building as a beginner example. I believe it is better for newcomers.

$ rustup target add wasm32-wasi
$ cargo build --target wasm32-wasi

## Build the WASM bytecode
```
$ cargo build --target wasm32-wasi
```

The error log will be very confusing if someone forgets to add the target before building for the first time.

root@TW59:~/wasm-learning/cli/hello# cargo build --target wasm32-wasi
   Compiling hello v0.1.0 (/root/wasm-learning/cli/hello)
error[E0463]: can't find crate for `std`
  |
  = note: the `wasm32-wasi` target may not be installed
  = help: consider downloading the target with `rustup target add wasm32-wasi`

error[E0463]: can't find crate for `std`
 --> src/main.rs:1:5
  |
1 | use std::env;
  |     ^^^ can't find crate
  |
  = note: the `wasm32-wasi` target may not be installed
  = help: consider downloading the target with `rustup target add wasm32-wasi`

error: cannot find macro `println` in this scope
 --> src/main.rs:6:5
  |
6 |     println!("{}", argument);
  |     ^^^^^^^

error: cannot find macro `println` in this scope
 --> src/main.rs:4:3
  |
4 |   println!("hello");
  |   ^^^^^^^

error[E0433]: failed to resolve: use of undeclared crate or module `env`
 --> src/main.rs:5:19
  |
5 |   for argument in env::args().skip(1) {
  |                   ^^^ use of undeclared crate or module `env`

error: requires `sized` lang_item

Some errors have detailed explanations: E0433, E0463.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `hello` due to 6 previous errors

Reference:

WASI-tutorial.md this file gives an shell example with add target.

Run nodejs example with c api

Hello, I‘d like to ask if I can use the official c-api to run the wasm module compiled in this project(e.g. k-means), or maybe I need some other things?

Issue running npm express on docker WSL 2

On some examples in server.js the following line does not work, missing express package in docker as well
app.use(express.static('public'));
it works when i change it to
app.use(express.static(__dirname + "/public"));

I am using WSL 2 ubuntu and i ran the following

cd /mnt/c/.../wasm-learning/
docker run -p 8080:8080 --rm -it -v $(pwd):/app ssvm-nodejs:v1
cd app
npm install express
cd quadratic
ssvmup build
node node/server.js

Update new TensorFlow API

We should use wasmedge_tensorflow_interface to replace the old ssvm_tensorflow_interface for TensorFlow functions.

ocr issue

Problem:
Interpretation of the code:
"let mut host_temp_input_filename = String::from("/tmp/");"?

Roots not ready on quadratic equation example

Hi :)

I've been following the examples from the free Raspberry Pi page, and got to the quadratic equations example.

Everything seems to install and update correctly, and running the 'node test.js' example works perfectly. When I run the 'node server.js' command, it starts to go wrong though. I get the 'Listening at http://localhost:8080' message, but as soon as I open the calculator I get a 'The roots are not ready' error, and when I enter any values into the calculator and press Solve, nothing happens on the calculator page, but on the Visual Studio page, the terminal gives me a long error message. I can't copy and paste it, so I've attached a screenshot.
Quadratic Equation Error

Fails to compile with go run but succeeds with go build

concerning /reactr/hello

 go run -tags wasmedge main.go
# github.com/suborbital/reactr/rwasm/runtime/wasmedge
/home/korny/go/pkg/mod/github.com/suborbital/[email protected]/rwasm/runtime/wasmedge/builder.go:43:17: undefined: wasmedge.NewWasiImportObject
/home/korny/go/pkg/mod/github.com/suborbital/[email protected]/rwasm/runtime/wasmedge/builder.go:50:20: store.FindFunction undefined (type *wasmedge.Store has no field or method FindFunction)
/home/korny/go/pkg/mod/github.com/suborbital/[email protected]/rwasm/runtime/wasmedge/builder.go:52:39: cannot use "_start" (type string) as type *wasmedge.Function in argument to executor.Invoke
/home/korny/go/pkg/mod/github.com/suborbital/[email protected]/rwasm/runtime/wasmedge/builder.go:56:15: store.FindFunction undefined (type *wasmedge.Store has no field or method FindFunction)
/home/korny/go/pkg/mod/github.com/suborbital/[email protected]/rwasm/runtime/wasmedge/builder.go:58:39: cannot use "init" (type string) as type *wasmedge.Function in argument to executor.Invoke
/home/korny/go/pkg/mod/github.com/suborbital/[email protected]/rwasm/runtime/wasmedge/builder.go:72:40: undefined: wasmedge.ImportObject
/home/korny/go/pkg/mod/github.com/suborbital/[email protected]/rwasm/runtime/wasmedge/builder.go:100:13: undefined: wasmedge.NewImportObject
/home/korny/go/pkg/mod/github.com/suborbital/[email protected]/rwasm/runtime/wasmedge/host_function.go:27:26: undefined: wasmedge.ImportObject
/home/korny/go/pkg/mod/github.com/suborbital/[email protected]/rwasm/runtime/wasmedge/wasmedge.go:13:11: undefined: wasmedge.ImportObject
/home/korny/go/pkg/mod/github.com/suborbital/[email protected]/rwasm/runtime/wasmedge/wasmedge.go:19:44: cannot use fn (type string) as type *wasmedge.Function in argument to w.executor.Invoke
/home/korny/go/pkg/mod/github.com/suborbital/[email protected]/rwasm/runtime/wasmedge/wasmedge.go:19:44: too many errors

a simple go build on the other hand compiles a binary that runs my rust-wasm code successfully.

go version go1.17.1 linux/amd64
wasmedge version 0.10.0
arch linux

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.