Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rustからwasmを生成してみた話
Search
rchaser53
October 27, 2017
820
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rustからwasmを生成してみた話
rchaser53
October 27, 2017
More Decks by rchaser53
See All by rchaser53
LLVM IR入門
rchaser53
4
3k
pitch loaderについて
rchaser53
1
590
Base64 VLQ概要
rchaser53
2
1.7k
sourcemap規格概要
rchaser53
1
1.3k
TypeScript+React入門
rchaser53
1
920
Featured
See All Featured
The untapped power of vector embeddings
frankvandijk
2
2k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
900
Code Reviewing Like a Champion
maltzj
529
40k
Automating Front-end Workflow
addyosmani
1370
210k
For a Future-Friendly Web
brad_frost
184
10k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Unsuck your backbone
ammeep
672
58k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
560
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
440
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
490
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Transcript
Rust からwasm を作成してみた話 @rchaser53
CAUTION! 発表内容は発表者の独自調査によるものです 間違ってたらすみません
TL;DR; 現状Emscripten でwasm を作成したいのであれば LLVM やemcc の知識が大なり小なり必要
はじめに 勉強ついでに作ったRust のゲーム Emscripten でWeb Assembly(wasm) に変換してみました
出てくる単語の概要 SDL2 ゲームエンジンとして使用 Rust wasm の変換元のアプリを作るのに使用 Cargo Rust からwasm を作成するのに使用
Emscripten wasm に変換するのに使用 LLVM コンパイラ基盤。中間コード作成に使用
SDL2 Simple DirectMedia Layer 2 クロスプラットフォームの開発ライブラリ OpenGl や様々なハードウェアへアクセスに使用 例. オーディオ,
キーボード, マウス etc...
Rust 今回重要なこと LLVM 上に構築されている言語 公式がwasm やasm.js にビルドする機能を提供
Cargo Rust のビルドシステム兼パッケージマネージャ 以下のような形でビルド対象を変更することができる (Rust 付属のrustc でもできる)
Rust 単体でwasm のビルドは不可 bit code からwasm に変換するEmscripten が必要
Emscripten bit code からasm.js やwasm に変換できるコンパイラー
Emscripten Compiler Frontend (emcc) 標準的なコンパイラーの代替を目指したもの C とかC++ からwasm を作る際にはこれ単体でOK
Emscripten Ports Emscripten 用の便利ライブラリ集 現在12 個しかない… 使用する際は以下のようにport を開ける
LLVM 様々な言語に対応可能なコンパイラ基盤 VM やClang など様々なサブプロジェクトが存在 今回はRust の中間コード(*.bc,*.o) への変換に使用
Rust 製 wasm
色々おかしい BGM 、効果音がない そもそも円じゃない
問題点 BGM 、効果音がない => emcc が正しく変換できていないっぽい そもそも円じゃない => 必要な依存ライブラリがEmscripten Ports
にない
BGM 、効果音がない Emscripten が上手く動いていない File の読み込みまでは成功 rwops がnull になってしまっている模様
ちなみに… 作成したアプリはtxt ファイルからmap を作成している 任意にmap は変更できる => ファイルを読み込むこと自体はできている模様
FS Emscripten が提供する仮想FileSystem Linux/POSIX File System とほぼ同様のinterface C やC++ なら以下のような形でemcc
が使える emcc 単体ではRust からwasm に変換できない… rustc やcargo などで中間コードを作成する必要がある
しかし… cargo から--preload-file のオプションをemcc に渡せない => js 上からファイルを読み込ませる var Module
= { prerun: [function () { FS.createPreloadedFile( '/', 'text1.txt', '/text2.txt', true, false ) }] }
公式の見解は? Emscripten 用のビルドスクリプトは作ってくれている 新しいversion がrust-sdl2 に取り込まれれば動くだろう
そもそも円じゃない Emscripten Ports に 線や円などを描画するライブラリ「SDL2_gfx 」がない => SDL2_gfx を外してSDL2 が描画できる矩形で代用
自力でemscripten 用のビルドスクリプトを書くしかない cargo はrustc でを実行した後にemcc を呼び出している emcc が読めるインプット(*.bc, *.o など)
にrustc で変換 emcc が読めるライブラリをビルドして読み込ませる
まとめというか感想 単純な変換なら特に問題なさそう ただし使えるライブラリがほぼない 自力でEmscripten 用ライブラリをビルドする必要あり LLVM とemcc の知識が必須
まとめというか感想 リベンジとして後日、別途公開します
ご静聴ありがとうございました!