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
RustからX Window Systemを触る
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
garasubo
January 27, 2020
680
0
Share
RustからX Window Systemを触る
garasubo
January 27, 2020
More Decks by garasubo
See All by garasubo
Cancel Safetyとスレッドリーク
garasubo
1
710
RustでISUCONに勝つには
garasubo
1
790
Rustでの自作OSをやってきて
garasubo
0
1.2k
Armの仮想化支援機構を用いてハイパーバイザーを自作する
garasubo
3
7.7k
Rustで始める自作組込みOS
garasubo
1
3.6k
クラウド向けOS(?)Unikernelとは何か
garasubo
0
1.8k
論文紹介:KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor
garasubo
0
670
Featured
See All Featured
Optimizing for Happiness
mojombo
378
71k
Documentation Writing (for coders)
carmenintech
77
5.3k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
260
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.2k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.6k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
120
The Pragmatic Product Professional
lauravandoore
37
7.2k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
330
How Software Deployment tools have changed in the past 20 years
geshan
0
33k
Transcript
RustからX Window Systemを触る @garasubo
きっかけ Mozillaの新しいブラウザエンジンのServoのIssueに取り掛 かろうとした https://github.com/servo/servo/issues/24724 Servoの依存するライブラリに変更が必要なことがわかり、 x11を触ることに
X Window System (X11) Linuxのウィンドウシステムの1つ C言語用のインタフェースが提供されている RustもC言語インターフェースを呼び出しをサポート しているので、Rustでも使える
RustからX11ライブラリを触る バインディングのクレートが存在している https://crates.io/crates/x11-dl いくつか対応していないインターフェースもある
RustとC言語はデータ表現が違う 構造体にはrepr(C)をつける 文字列ではStringではなくCstring、CStrを使う 関数ポインタはOptionでラップする Rustでは関数ポインタは0(Null)にならないが、Cではなりえる
Optionは0になりなりえない型ではNoneを0とする最適化を行う
C言語の型はゆるい 例:XIMのPreedit Start Callback 型定義 typedef void (*XIMProc)(XIM,XPointer,XPointer); 現実 static
int preedit_start_callback( XIC xim, XPointer client_data, XPointer call_data){}
C言語にはライフタイムがない 一度参照から生ポインタに変換するとライフタイムや Mutabilityのチェックが消える C言語から渡されてくる生ポインタにもライフタイムがな い 例:C言語からくる文字列ポインタをCString::from_rawに 渡してしまう
Rust側にオーナーシップを渡してしまい、勝手にリソースを開放し てしまう CStrを使うのが正解
まとめ C言語とRustのデータ表現の差異から来る罠はたくさんある ただのC言語バインディングではRustの旨味が消えてしまう 適切にC言語ライブラリをラップして汚いところを隠蔽しま しょう X11直接触るよりはそれをラップしたwinitを使うと楽
https://github.com/rust-windowing/winit