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.8k
仕事がしやすくなる社内発信のすすめ/ 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
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
210
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
260
fs2-io を試してたらバグを見つけて直した話
chencmd
0
240
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
310
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
950
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
280
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
630
Exploring: Partial and Independent Composables
blackbracken
0
100
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1.1k
return文におけるstd::moveについて
onihusube
1
1.2k
歴史と現在から考えるスケーラブルなソフトウェア開発のプラクティス
i10416
0
120
nekko cloudにおけるProxmox VE利用事例
irumaru
3
450
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Navigating Team Friction
lara
183
15k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
The Language of Interfaces
destraynor
154
24k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Code Review Best Practice
trishagee
65
17k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
For a Future-Friendly Web
brad_frost
175
9.4k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Being A Developer After 40
akosma
87
590k
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