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
wasm-bindgen - その魅力と面白さ -
Search
Misaki Makino
December 14, 2018
Programming
1
3.7k
wasm-bindgen - その魅力と面白さ -
2018/12/14 Emscripten & WebAssembly night !! #6
で発表した内容です。
Misaki Makino
December 14, 2018
Tweet
Share
More Decks by Misaki Makino
See All by Misaki Makino
脆弱性診断の内製化と外注
tsukushi
9
3.8k
プロダクトセキュリティにおける欠如モデルからの脱却
tsukushi
0
1k
スクラム開発経験者のエンジニアが 1年間脆弱性診断してお伝えしたいいくつかのこと
tsukushi
0
880
Attractions and interests of wasm-bindgen
tsukushi
2
770
Rust + WebAssemblyに入門した話
tsukushi
1
2.4k
未経験新卒エンジニアがRustを学び始めてよかったこと
tsukushi
2
9.6k
Other Decks in Programming
See All in Programming
Jakarta EE meets AI
ivargrimstad
0
600
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
120
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
580
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
CSC509 Lecture 11
javiergs
PRO
0
180
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
みんなでプロポーザルを書いてみた
yuriko1211
0
260
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
31
6.3k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
Making the Leap to Tech Lead
cromwellryan
133
8.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
The Cult of Friendly URLs
andyhume
78
6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Making Projects Easy
brettharned
115
5.9k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Transcript
wasm-bindgen ͦͷັྗͱ໘ന͞ emscripten & WebAssembly night !! #6 @T5uku5hi
ඒ࡙@T5uku5hi ࣗݾհ w ৽ଔ w ۀͰ+BWBΛॻ͍͍ͯ·͢ w 3VTU͕େ͖Ͱ͢ w ͖͗ͯ͢ษڧձΛ։͖·ͨ͠
͜ͷηογϣϯͷΰʔϧ ௌऺͷօ͞·͕ɺ ☺XBTNCJOEHFOࢼͯ͠ΈΑ͏ʂ ͱ͍͏ঢ়ଶʹͳΔ͜ͱ XBTNCJOEHFO͍ͬͯ͢͝ʂ
wasm-bindgenͱ ·ͣͬ͘͟Γߦ·ͱΊ w3VTUίϛϡχςΟͷެࣜϓϩμΫτͷҰͭ w3VTUͱ+4͕8FC"TTFNCMZΛ༻͍ͯγʔϜϨεʹ͑Δ w๛ͳܕͰָʹ࡞ۀͰ͖Δͷ͕͍͢͝ ৄ͘͠આ໌͍͖ͯ͠·͢ʂ
Agenda w8FC"TTFNCMZͱ w3VTUͷίʔυΛXBTNʹม͠ɺ+4Ͱݺͼग़ͯ͠ΈΔ wࣈͷ߹ͱจࣈྻͷ߹ wXBTNΛ͏্Ͱͷ՝ wXBTNCJOEHFOͱ
WebAssemblyͱ wXFCϒϥβ্Ͱ࣮ߦͰ͖ΔόΠφϦܗࣜ wਫ४ͷݴޠʹͱͬͯޮՌతͳίϯύΠϧର wϢʔβʔ࡞ΓํΛΔඞཁ͑͞ͳ͍ w8FC"TTFNCMZ+4ͷஔ͖͑Λҙਤ͍ͯ͠ͳ͍
+4ͷۤखͳ͜ͱ Λิర ੈք؍Λਤʹͯ͠Έͨ .rs .cpp .c .go .kt .wasm .wat
ςΩετԽͯ͠ ಡΉ͜ͱՄೳ ৭ʑͳݴޠͷ ίϯύΠϧର ❤ .js
ͦΕͰૣ .wasm .rs .js ❤ 3VTUͷίʔυΛ8FC"TTFNCMZʹมͯ͠ɺ +4͔Βݺͼग़ͯ͠Έ·͠ΐ͏ʂ
3VTUͷϓϩάϥϜΛॻ͘ $ cargo new --lib add_one $ cd add_one command
line [lib] crate-type = ["cdylib"] Cargo.toml #[no_mangle] pub extern fn add_one(x: u32) -> u32 { x + 1 } src/lib.rs
XBTNʹม͢Δ $ cargo build --target wasm32-unknown-unknown --release $ wasm-gc target/wasm32-unknown-unknown/release/add_one.wasm
-o add_one.gc.wasm // wasm-gc: ෆཁͳόΠφϦΛআͯ͘͠ΕΔπʔϧ command line
index.html +4͔Βݺͼग़͢
ϒϥβʹදࣔ͞ΕΔ
จࣈྻͷදࣔ src/lib.rs
จࣈྻͷදࣔ index.html
ϒϥβʹදࣔ͞Εʜ
ϒϥβʹදࣔ͞Εʜ ͳ͍
Ṗͷྻ ͱ
.wasmΛ.watʹม $ wasm2wat append_str.wasm -o append_str.wat // wabtͱ͍͏มπʔϧΛ͍ͬͯ·͢ command line
ղಡͯ͠Έ·ͨ͠ append_str.wat
ղಡͯ͠Έ·ͨ͠ append_str.wat จࣈྻ͕֨ೲ͞Ε͍ͯΔ ઢܗϝϞϦͷΞυϨε
WebAssemblyͷݴޠ༷ wίʔυͷ୯ҐϞδϡʔϧ.PEVMF w.PEVMFͭͷେ͖ͳ4ࣜͰදݱ͞ΕΔ wύϥϝʔλʹݱࡏͭͷܕ͕༗ޮ J J G G wෳࡶͳσʔλܕΛѻ͏ͨΊʹઢܗϝϞϦΛఏڙ͍ͯ͠Δ
ઢܗϝϞϦ ArrayBuffer ϝϞϦ൪ͷͱ͜Ζ͔ΒԿ͔ೖΕ·ͨ͠ɻ จࣈྻ͕ԿͰ͋Δ͔ղऍ͠ͳ͍ɻೖΕ͓͚ͯͩ͘ɻ 8FC"TTFNCMZ ͷੈք +4ͷੈք όΠτͷ"SSBZ#V⒎FSͰ͢ɻ 7JFXʹ6JOU"SSBZΛར༻͠·͢ɻ
VUGͰσίʔυ͠·͢ɻ Ͳ͜·Ͱจࣈྻͳͷ͔ఆΊɺจࣈྻͰ͋Δ͜ͱΛղऍ͢Δඞཁ͕͋Δʂ
จࣈྻѻ͏ͷ ΊΜͲ͍͘͞
ͬͱݴ͏ͱ ৭ʑΊΜͲ͍͘͞
index.html ݺͼग़͢ͷେมͰͨ͠ΑͶ
.wasm .js ❤ શવ❤ͳؔ͡Όͳ͔ͬͨ wGFUDIߏจ͕͍ w"SSBZ#V⒎FSɺ7JFXʹؔ͢Δ࣮͕ඞཁ wจࣈྻͷ߹σίʔμʔඞཁ Ϣʔβʔͷෛ୲͕େ͖͍͜ͱ͕՝
ͦΕΛղܾ͢Δͷ͕ wasm-bindgenͰ͢
wasm-bindgenͰͰ͖Δ͜ͱ .wasm .js ❤ wલड़ͨ͠ΊΜͲ͍͘͞෦Λશ෦ࣗಈͰ࣮ͯ͘͠ΕΔ w+4ͷϞδϡʔϧΛJNQPSU͢Δײ֮ͰXBTNΛ͑Δ wOQNͰαʔόʔΛ্ཱͪ͛ΒΕΔ
wasm-bindgenΛ͏ [dependencies] wasm-bindgen = “0.2” Cargo.toml src/lib.rs
wasm-bindgenΛ͏ $ wasm-pack build // wasm-pack: ͜ͷίϚϯυͰࣗಈ࡞͞ΕΔ command line
pkg/js_hello_world.js .d.ts bg.d.ts .wasm .js .json QLHԼʹࣗಈੜ
wasm-bindgenΛ͏ $ npm init $ npm install -D webpack
webpack-cli webpack-dev-server command line webpack.config.js
index.html wasm-bindgenΛ͏ index.js
wasm-bindgenΛ͏ domUtils.js src/lib.rs $ wasm-pack build $ npx webpack-dev-server
command line
ϒϥβʹදࣔ͞Ε·ͨ͠
͓·͚ lib.rs +4"1*Λ3VTUͰॻ͚·͢
͓·͚ ϚϦΦͰͨ͠ʂ
·ͱΊ w8FC"TTFNCMZ+4Λิర͢ΔͨΊʹੜ·Ε͖ͯͨ w+4Ͱ͏ʹ͍উख͕ѱ͍ͱ͍͏՝͕͋ͬͨ wXBTNCJOEHFOͦ͜Λղܾ͢Δ͍͢͝πʔϧ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ