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
TinyGoでWasmを生成する / Compile Wasm by TinyGo
Search
hachi (Hayao Kimura)
May 20, 2019
Programming
1
590
TinyGoでWasmを生成する / Compile Wasm by TinyGo
TinyGoでWebAssemblyをコンパイルした話
hachi (Hayao Kimura)
May 20, 2019
Tweet
Share
More Decks by hachi (Hayao Kimura)
See All by hachi (Hayao Kimura)
Raw HID とOLEDで広げるキーボードの可能性/Expanding Keyboard Possibilities with Raw HID and OLED
hayaokimura
0
33
freee請求書プロダクトにおけるFiber活用/Utilization of Fiber in the freee Invoice Product
hayaokimura
1
91
いいチームでいるためにやっていること/Things we are doing to remain a good team
hayaokimura
2
610
やりたいことを仕事でやる技術 / The Technique of Turning Your Passion into Your Profession
hayaokimura
0
3.4k
Drive Your Code ~ Building an RC Car by Writing Only Ruby~
hayaokimura
1
1.9k
仕事がしやすくなる社内発信のすすめ/ Work happily by tweeting
hayaokimura
8
24k
Factorybot 改善ツール作成失敗と学び/ Factorybot improvement tool creation failure and learning
hayaokimura
1
1.1k
エンジニアと「書く」こと/ “Writing” with Engineers
hayaokimura
0
68
Kaigi on Rails を 512 倍楽しむための「書く」技術/ How to write to enjoy Kaigi on Rails 512 times more
hayaokimura
1
230
Other Decks in Programming
See All in Programming
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
2
130
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
180
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
800
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
180
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
340
快速入門可觀測性
blueswen
0
400
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
660
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
920
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
220
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
GitHub's CSS Performance
jonrohan
1031
460k
Automating Front-end Workflow
addyosmani
1366
200k
Being A Developer After 40
akosma
87
590k
Adopting Sorbet at Scale
ufuk
73
9.1k
BBQ
matthewcrist
85
9.4k
The Invisible Side of Design
smashingmag
298
50k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Transcript
©2019 Wantedly, Inc. TinyGoͰWasmΛੜ͢Δ golang.tokyo #24 May 21, 2019 -
Hayao Kimura
©2019 Wantedly, Inc. "CPVUNF • ଜ ॣੜ @hachiblogʢͪ΅ʔʣ • Wantedly
Inc. ͷ৽ଔʁ ̍ • goྺఔ • ΧϝϥɺμΠϏϯά • ΩʔϘʔυࣗ࡞͍ͨ͠ͻͱ
©2019 Wantedly, Inc. 1. TinyGoͱ • TinyGoͷಛ • TinyGoͰͰ͖Δ͜ͱ 2.
TinyGoͰWasmΛ࡞Δ • ͳͥTinyGoͳͷ͔ • WasmΛ࡞ͬͯΈΔ Agenda
©2019 Wantedly, Inc. TinyGoͱ
©2019 Wantedly, Inc. 5JOZ(Pͱ • GoͷܰྔίϯύΠϥ • LLVMΛͬͯίϯύΠϧ͍ͯ͠Δ • γϯάϧίΞΛఆ
TinyGoͷಛ https://github.com/tinygo-org/tinygo
©2019 Wantedly, Inc. 5JOZ(Pͱ • ༷ʑͳϚΠίϯ্Ͱಈ࡞͢Δ • ֦ுϞδϡʔϧͳͲͷύοέʔδॱ࣍Ճத • WebAssembly͕ίϯύΠϧͰ͖Δ
• ৄ͘͠ˠ TinyGoͰͰ͖Δ͜ͱ
©2019 Wantedly, Inc. TinyGoͰWasmΛ࡞Δ
©2019 Wantedly, Inc. 5JOZ(PͰ8BTNΛ࡞Δ • WebAssembly • ϒϥβ্ʹ͓͍ͯόΠφϦܗࣜͰ࣮ߦՄೳ • Wasm
1.0ओཁͳϒϥβͰಈ࡞Մೳ Wasmͱ Wikipedia ΑΓҾ༻
©2019 Wantedly, Inc. 5JOZ(PͰ8BTNΛ࡞Δ • ຊՈGoίϯύΠϥͰ1.11ͰWasmʹରԠ͍ͯ͠Δ • αΠζ͕ͱͯେ͖͘ͳΔ • TinyGoͰ͋Εখ͑͘͞ΒΕΔ
ͳͥTinyGoͳͷ͔
©2019 Wantedly, Inc. 5JOZ(PͰ8BTNΛ࡞Δ • htmlʹ͋ΔjpegΛWasmͰಡΈࠐΜͰhogehoge͍ͨ͠ • ຊՈGoίϯύΠϥͱͷWasmͷϑΝΠϧαΠζͷࠩΛΓ͍ͨ • jpegͷྔ͕૿͑ͨ࣌ɺͲΕ͘Β͍͞ʹҧ͍͕ग़Δͷ͔Γ͍ͨ
Γ͍ͨ͜ͱ
©2019 Wantedly, Inc. 5JOZ(PͰ8BTNΛ࡞Δ ͬͨ͜ͱ 1. jsͰbase64Τϯίʔυ 2. wasmʹͯ͠σίʔυ •
͜͜Ͱॏ͍ॲཧΛhogehoge͢Δ 3. base64ʹ࠶Τϯίʔυͯ͠jsʹฦ͢
©2019 Wantedly, Inc. 5JOZ(PͰ8BTNΛ࡞Δ ͬͨ͜ͱ 1. jsͰbase64Τϯίʔυ 2. wasmʹͯ͠σίʔυ •
͜͜Ͱॏ͍ॲཧΛhogehoge͢Δ 3. base64ʹ࠶Τϯίʔυͯ͠jsʹฦ͢
©2019 Wantedly, Inc. 5JOZ(PͰ8BTNΛ࡞Δ ͬͨ͜ͱ 1. jsͰbase64Τϯίʔυ 2. wasmʹͯ͠σίʔυ •
͜͜Ͱॏ͍ॲཧΛhogehoge͢Δ 3. base64ʹ࠶Τϯίʔυͯ͠jsʹฦ͢ function includeFile() { var obj = document.getElementById('getImage') var cvs = document.createElement('canvas'); cvs.width = obj.width; cvs.height = obj.height; var ctx = cvs.getContext('2d'); ctx.drawImage(obj, 0, 0); var data = cvs.toDataURL('image/jpeg'); document.getElementById('hidden').textContent = data.replace(/^data.*base64,/, '');; wasm.exports.convertFile(); }
©2019 Wantedly, Inc. 5JOZ(PͰ8BTNΛ࡞Δ ͬͨ͜ͱ 1. jsͰbase64Τϯίʔυ 2. wasmʹͯ͠σίʔυ •
͜͜Ͱॏ͍ॲཧΛhogehoge͢Δ 3. base64ʹ࠶Τϯίʔυͯ͠jsʹฦ͢
©2019 Wantedly, Inc. 5JOZ(PͰ8BTNΛ࡞Δ wasmʹͨ͠ͱ͖ͷॲཧ import ( "syscall/js" "encoding/base64" "image/jpeg"
"bytes" ) func convertFile() { global := js.Global() document := global.Get("document") image_string := document.Call("getElementById", "hidden").Get("textContent").String() data, _ := base64.StdEncoding.DecodeString(image_string) jpgI, _ := jpeg.Decode(bytes.NewReader(data)) //ॏ͍ॲཧ var buffer bytes.Buffer jpeg.Encode(&buffer,jpgI,nil) encode_string := base64.StdEncoding.EncodeToString(buffer.Bytes()) image_viewer := document.Call("getElementById", "hidden-reader") global.Call("eval","console.log('test')") image_viewer.Set("textContent",encode_string) }
©2019 Wantedly, Inc. 5JOZ(PͰ8BTNΛ࡞Δ wasmʹͨ͠ͱ͖ͷॲཧ import ( "syscall/js" "encoding/base64" "image/jpeg"
"bytes" ) func convertFile() { global := js.Global() document := global.Get("document") image_string := document.Call("getElementById", "hidden").Get("textContent").String() data, _ := base64.StdEncoding.DecodeString(image_string) jpgI, _ := jpeg.Decode(bytes.NewReader(data)) //ॏ͍ॲཧ var buffer bytes.Buffer jpeg.Encode(&buffer,jpgI,nil) encode_string := base64.StdEncoding.EncodeToString(buffer.Bytes()) image_viewer := document.Call("getElementById", "hidden-reader") global.Call("eval","console.log('test')") image_viewer.Set("textContent",encode_string) }
©2019 Wantedly, Inc. 5JOZ(PͰ8BTNΛ࡞Δ wasmʹͨ͠ͱ͖ͷॲཧ import ( "syscall/js" "encoding/base64" "image/jpeg"
"bytes" ) func convertFile() { global := js.Global() document := global.Get("document") image_string := document.Call("getElementById", "hidden").Get("textContent").String() data, _ := base64.StdEncoding.DecodeString(image_string) jpgI, _ := jpeg.Decode(bytes.NewReader(data)) //ॏ͍ॲཧ var buffer bytes.Buffer jpeg.Encode(&buffer,jpgI,nil) encode_string := base64.StdEncoding.EncodeToString(buffer.Bytes()) image_viewer := document.Call("getElementById", "hidden-reader") global.Call("eval","console.log('test')") image_viewer.Set("textContent",encode_string) }
©2019 Wantedly, Inc. ίϯύΠϧΤϥʔ 5JOZ(PͰ8BTNΛ࡞Δ ͬͨ͜ͱ > tinygo build -o
src/wasm.wasm -target=wasm src/export/wasm.go usr/local/go/src/image/ycbcr.go:176:20: todo: full slice expressions (with max): []byte
©2019 Wantedly, Inc. Θ͔ΒΜ Page Title Page Subtitle
©2019 Wantedly, Inc. ࠔͬͨ ࠔͬͨͱ͖ઌഐʹ૬ஊ Page Title Page Subtitle
©2019 Wantedly, Inc. TinyGoͰWasmΛ࡞Εͳ͔ͬͨ
©2019 Wantedly, Inc. TinyGoͰWasmΛ࡞Εͳ͔ͬͨ
©2019 Wantedly, Inc. TinyGoͰWasmΛ࡞Εͳ͔ͬͨ
©2019 Wantedly, Inc. TinyGoͰWasmΛ࡞Εͳ͔ͬͨ
©2019 Wantedly, Inc. ऴྃ Page Title Page Subtitle
©2019 Wantedly, Inc. 5JOZ(PͰ8BTNΛ࡞Εͳ͔ͬͨ • ରԠ͍ͯ͠ͳ͍ඪ४ύοέʔδ͕݁ߏ͋ͬͨ • ·ͩ·ͩTinyGoͰͰ͖ͳ͍͜ͱଟ͍ • ͱ͍͑ເͷ͋ΔʢcontributeͰ͖Ε͍ͨ͠
• ίϯύΠϥͷษڧʹͳΔ͔ʁ
©2019 Wantedly, Inc. ·ͱΊ • TinyGoΛ͑WasmΛίϯύΠϧͰ͖Δ • ͨͩ͠·࣮ͩ༻తͰͳͦ͞͏ • ϚΠίϯͷίʔυͱͯॻ͖͍͢ͷͰTinyGoΛҭ͍͖͍ͯͯͨ
©2019 Wantedly, Inc. TinyGoͰWasmΛੜ͢ΔͰ͖ͳ͔ͬͨ golang.tokyo #24 May 21, 2019 -
Hayao Kimura