Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
WebAssembly Hands-on! ~ powered by Dev Containe...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Naoya
November 17, 2022
Programming
84
0
Share
WebAssembly Hands-on! ~ powered by Dev Containers ~
Naoya
November 17, 2022
More Decks by Naoya
See All by Naoya
スクラムを成功へ導くマインド
nakir323
1
110
やさしいチームトポロジー
nakir323
43
6.8k
マスタリング Credit Card
nakir323
0
150
正しいスクラムを正しく行う
nakir323
0
200
Other Decks in Programming
See All in Programming
GitHub Copilot CLIのいいところ
htkym
2
1.2k
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
300
Agentic UI beyond Chats Architecture Patterns & Open Standards @ngMunich 05/2026
manfredsteyer
PRO
0
180
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
250
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
1
520
Zod v4 Codec でスキーマに型変換を埋め込む REST API 設計 #TSKaigi2026
ryutaro_yako
0
170
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3k
誰も頼んでない機能を出荷した話
zekutax
0
150
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.3k
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
110
Oxlintはいかにしてtsgolintのlint ruleを呼び出しているのか
syumai
2
1k
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
140
Featured
See All Featured
Exploring anti-patterns in Rails
aemeredith
3
380
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
180
Skip the Path - Find Your Career Trail
mkilby
1
130
Tell your own story through comics
letsgokoyo
1
930
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
370
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.1k
Are puppies a ranking factor?
jonoalderson
1
3.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Thoughts on Productivity
jonyablonski
76
5.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Everyday Curiosity
cassininazir
0
210
Transcript
WebAssembly Hands-on! ~ powered by Dev Containers ~
▹ WebAssemblyを知る ▹ Dev Containersを知る ▹ ついでにRustの雰囲気をつかむ Purpose 2
▹ 基礎知識(座学) ▹ ハンズオン! ▹ まとめ Agenda 3
1. 基礎知識 各用語をざっくりと解説
WebAssembly? ウェブ...のアセンブリ...? 5
6 ▹ ブラウザで動作するハイパフォーマ ンスなコード ▹ バイナリ(.wasm)の手前に人が読め る中間表現であるテキスト形式 (.wat)がある ▹ C/C++やRustのコンパイル対象と
なっている ▹ jsから.wasmを呼び出して実行する WebAssembly 6 .watの例 https://developer.mozilla.org/ja/docs/WebAssembly/Understa nding_the_text_format .wasmをjsから呼び出す例 https://developer.mozilla.org/ja/docs/WebAssembly/Understa nding_the_text_format
Dev Containers? 開発用のコンテナ...? 7
Dev Containersの概念図 https://code.visualstudio.com/docs/devcontainers/containers 8 ▹ VSCodeのextension ▹ Dockerコンテナを開発環境として利 用できる ▹
extensionやコード補完もコンテナ 内で動作 ▹ VSCodeのterminalもコンテナ内で 実行される ▹ extensionを含めた開発環境の共有 が容易に Dev Containers 8
2. Hands-on! Rustからwasmを生成しjsで 読み込みhello worldするの巻
10 1. VSCode Dev ContainersでRustの開発環境を作る 2. Rustのコードを記述 3. .wasmにコンパイル 4.
JSから呼び出して、hello world! Hands-on Outline 10
11 VSCodeにDev Containers extensionをインストール ms-vscode-remote.remote-containers Step 1 11
12 wasm-rust(任意)というフォルダを作ってVSCode開き、 Dockerfileを作り、FROM rust:1.65.0と記述 Step 2 12
左下の緑色の><を押下、 → Open Folder in Container... → wasm-rust → Existing
Dockerfile 13 Step 3 13
VSCodeのterminalで下記を実行 $ cargo install wasm-pack 14 Step 4 14 ※CargoはRustのビルドシステム兼パッケージマネージャ
https://doc.rust-jp.rs/book-ja/ch01-03-hello-cargo.html
下記の通りフォルダ/ファイルを作成 15 Step 5 15 wasm-rust/ ├ index.html ├ Cargo.toml
└ src/ └ lib.rs
[package] name = "wasm-rust" version = "0.1.0" edition = "2021"
[lib] crate-type = ["cdylib"] [dependencies] wasm-bindgen = "0.2" 下記の通りCargo.tomlを記述 16 Step 6 16
use wasm_bindgen::prelude::*; #[wasm_bindgen] extern { pub fn alert(s: &str); }
#[wasm_bindgen] pub fn greet(name: &str) { alert(&format!("hello {}", name)); } 下記の通りlib.rsを記述 17 Step 7 17
VSCodeのterminalで下記を実行 $ wasm-pack build --target web 18 Step 8 18
<!DOCTYPE html> <html lang="en-US"> <head><meta charset="utf-8"></head> <body> <script type="module"> import
init, { greet } from "./pkg/wasm_rust.js"; init() .then(() => { greet("world") }); </script> </body> </html> 下記の通りindex.htmlを記述 19 Step 9 19
20 Live Server extensionをインストール。 ritwickdey.liveserver Step 10 20
index.htmlを右クリック → Open with Live Serverを選択 21 Step 11 21
🎉🎉🎉 22 Step 12 22
3. Summary さらっと要点まとめ
▹ Rustをコンパイルすると.wasmを生成できる ■ wasm-packなら、ついでにそれを呼び出 す.jsも作れる ▹ Dev Containersで楽に開発環境を作れる ■ 新たに言語を試すのがとても楽
▹ jsからWebAssembly.instantiate()等を使う ことで.wasmからexportした関数を呼び出せる Summary 24
興味が出た人向けの小ネタ 4. Appendix
▹ 実はブラウザだけじゃなくNode.jsでもWebAssemblyオブジェクトが使える ■ https://developer.mozilla.org/en-US/docs/WebAssembly#browser_com patibility ▹ Google EarthはWebAssemblyで作られている ■ https://medium.com/google-earth/google-earth-comes-to-more-brows
ers-thanks-to-webassembly-1877d95810d6 ▹ .watを手書きしている記事 ■ https://www.kabuku.co.jp/developers/webassembly ▹ 最速でWebAssemblyだけ試すならこちら(ChromeのConsoleいじるだけ) ■ https://nulab.com/ja/blog/nulab/basic-webassembly-begginer/ 26 Appendix 26
▹ 生成された /pkg/wasm_rust.jsの中で、wasm_rust_bg.wasmを呼び出したり、 WebAssembly.instantiate()しているので見てみると良いかも。 ▹ 現状、.wasmはjs経由でないとブラウザでは実行できない。 ▹ Yew等のRustのみでUIまで構築できるframeworkもあるみたい ■ https://zenn.dev/azukiazusa/articles/rust-base-web-front-fremework
-yew 27 Appendix 27