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
580
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
600
やりたいことを仕事でやる技術 / The Technique of Turning Your Passion into Your Profession
hayaokimura
0
2.9k
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
1k
エンジニアと「書く」こと/ “Writing” with Engineers
hayaokimura
0
67
Kaigi on Rails を 512 倍楽しむための「書く」技術/ How to write to enjoy Kaigi on Rails 512 times more
hayaokimura
1
210
Other Decks in Programming
See All in Programming
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
200
Better Code Design in PHP
afilina
PRO
0
130
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
Jakarta EE meets AI
ivargrimstad
0
690
受け取る人から提供する人になるということ
little_rubyist
0
250
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
Functional Event Sourcing using Sekiban
tomohisa
0
100
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
200
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
240
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
Featured
See All Featured
RailsConf 2023
tenderlove
29
900
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Done Done
chrislema
181
16k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
How GitHub (no longer) Works
holman
310
140k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Happy Clients
brianwarren
98
6.7k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
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