WebAssembly : l'atelier !
Le navigateur comme Machine Virtuelle
@m4d_zhttps://talks.m4dz.net/a-taste-of-wasm/fr/atelier/Paranoïd Web Dino · Tech Evangelist
Au menu ce soir
$ git clone https://github.com/m4dz/wasm-workshop.git
Il était une fois…
Nous développons des apps!
Nos besoins :
WASM Binary Assembly Format
0200 20 00
0202 42 00
0204 51
0205 04 7e
0207 42 01
020A 05
020B 20 00
020D 20 00
0210 42 01
0211 7d
0212 10 00
0214 7e
0217 0b
C’est un… langage ?
WASM Text Format
get_local 0
i64.const 0
i64.eq
if i64
i64.const 1
else
get_local 0
get_local 0
i64.const 1
i64.sub
call 0
i64.mul
end
🍀 types statiques
Mon problème :
j’utilise pas que des nombres !
Je veux des chaînes de caractères
💩
Il va falloir
compiler pour le Web
Ce dont on a besoin
Ce dont on n’a pas besoin
Rust 🦀
Linux / MacOS / Unix
curl https://sh.rustup.rs -sSf | sh
Windows
→ https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe
Test
$ rustup --version
rustup 1.19.0 (2af131cf9 2019-09-08)
$ cargo --version
cargo 1.38.0 (23ef9a4ef 2019-08-20)
Pourquoi Rust?
Ordre d’exécution
On va utiliser un packer
wasm-pack 📦✨
📦✨ your favorite rust -> wasm workflow tool!
Linux / MacOS / Unix
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
Windows
→ https://github.com/rustwasm/wasm-pack/releases/download/v0.8.1/wasm-pack-init.exe
Test
$ wasm-pack --version
wasm-pack 0.8.1
Bonus : Node.js
Utilisation
$ wasm-pack test [--firefox [--headless]] wasm-workshop
$ wasm-pack build [--target web] [--release] wasm-workshop [-- --features wee_alloc]
Prêt à l’emploi
$ tree
├── bridge.js
├── Cargo.toml
├── pkg
│ ├── my-module_bg.d.ts
│ ├── my-module_bg.wasm
│ ├── my-module.d.ts
│ ├── my-module.js
│ ├── package.json
│ └── snippets
│ └── my-module-91b01578bc1ce6c0
│ └── bridge.js
└── src
└── lib.rs
Démarrer un projet
$ cargo install cargo-generate
$ cargo generate --git https://github.com/rustwasm/wasm-pack-template.git
wasm-bindgen!
Facilitating high-level interactions between wasm modules and JavaScript.
window
, document
, fetch
, canvas
…)Documentations
https://talks.m4dz.net/a-taste-of-wasm/fr/atelier/ Disponible sous licence CC BY-SA 4.0
m4dz, CC BY-SA 4.0
Courtesy of Unsplash and Pexels contributors
Powered by Reveal.js
Source code available at
https://git.madslab.net/talks