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
570
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)
いいチームでいるためにやっていること/Things we are doing to remain a good team
hayaokimura
2
580
やりたいことを仕事でやる技術 / The Technique of Turning Your Passion into Your Profession
hayaokimura
0
2k
Drive Your Code ~ Building an RC Car by Writing Only Ruby~
hayaokimura
1
1.7k
仕事がしやすくなる社内発信のすすめ/ Work happily by tweeting
hayaokimura
8
23k
Factorybot 改善ツール作成失敗と学び/ Factorybot improvement tool creation failure and learning
hayaokimura
1
940
エンジニアと「書く」こと/ “Writing” with Engineers
hayaokimura
0
66
Kaigi on Rails を 512 倍楽しむための「書く」技術/ How to write to enjoy Kaigi on Rails 512 times more
hayaokimura
1
180
Other Decks in Programming
See All in Programming
オートマトン学習しろ / Do automata learning
makenowjust
3
130
Prompt Cachingは本当に効果的なのか検証してみた.pdf
ttnyt8701
0
530
Crafting Cross-Platform Adventures: Building a Game Engine with Kotlin Multiplatform
dwursteisen
0
120
Debugging: All you need to know (for simultaneous interpreting)
jmatsu
2
800
GraphQL あるいは React における自律的なデータ取得について
quramy
11
3k
Why Prism?
kddnewton
4
1.7k
事業フェーズの変化に対応する 開発生産性向上のゼロイチ
masaygggg
0
200
Perl 5 OOP機構30年史 - Perl 5's OOP Mechanism over the past 30 years
moznion
0
300
AndroidアプリのUIバリエーションをあの手この手で確認する / Check UI variations of Android apps by various means
tkmnzm
1
180
A New Era of Testing
mannodermaus
2
510
RAGの回答精度評価用のQAデータセットを生成AIに作らせた話
kurahara
0
250
rails_girls_is_my_gate_to_join_the_ruby_commuinty
maimux2x
0
200
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
36
2.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
278
13k
Designing on Purpose - Digital PM Summit 2013
jponch
114
6.8k
Imperfection Machines: The Place of Print at Facebook
scottboms
263
13k
Scaling GitHub
holman
458
140k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
5
480
Building Applications with DynamoDB
mza
90
6k
A designer walks into a library…
pauljervisheath
201
24k
Code Review Best Practice
trishagee
62
16k
Build your cross-platform service in a week with App Engine
jlugia
228
18k
For a Future-Friendly Web
brad_frost
174
9.3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.3k
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