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
600
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
40
freee請求書プロダクトにおけるFiber活用/Utilization of Fiber in the freee Invoice Product
hayaokimura
1
97
いいチームでいるためにやっていること/Things we are doing to remain a good team
hayaokimura
2
630
やりたいことを仕事でやる技術 / The Technique of Turning Your Passion into Your Profession
hayaokimura
0
4k
Drive Your Code ~ Building an RC Car by Writing Only Ruby~
hayaokimura
1
1.9k
仕事がしやすくなる社内発信のすすめ/ Work happily by tweeting
hayaokimura
8
25k
Factorybot 改善ツール作成失敗と学び/ Factorybot improvement tool creation failure and learning
hayaokimura
1
1.1k
エンジニアと「書く」こと/ “Writing” with Engineers
hayaokimura
0
69
Kaigi on Rails を 512 倍楽しむための「書く」技術/ How to write to enjoy Kaigi on Rails 512 times more
hayaokimura
1
250
Other Decks in Programming
See All in Programming
.NETでOBS Studio操作してみたけど…… / Operating OBS Studio by .NET
skasweb
0
130
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
270
SRE、開発、QAが協業して挑んだリリースプロセス改革@SRE Kaigi 2025
nealle
1
2.8k
Внедряем бюджетирование, или Как сделать хорошо?
lamodatech
0
970
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
140
自分ひとりから始められる生産性向上の取り組み #でぃーぷらすオオサカ
irof
8
2k
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
3
190
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
440
HTML/CSS超絶浅い説明
yuki0329
0
200
AWS re:Invent 2024個人的まとめ
satoshi256kbyte
0
140
Amazon Nova Reelの可能性
hideg
0
240
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
4
1.1k
Featured
See All Featured
Making Projects Easy
brettharned
116
6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Statistics for Hackers
jakevdp
797
220k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The Invisible Side of Design
smashingmag
299
50k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.5k
Into the Great Unknown - MozCon
thekraken
34
1.6k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
6
210
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
52k
Making the Leap to Tech Lead
cromwellryan
133
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