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
It’s about time to pack Ruby and Ruby scripts in one binary
Search
ahogappa
May 16, 2024
Programming
1
2.2k
It’s about time to pack Ruby and Ruby scripts in one binary
ahogappa
May 16, 2024
Tweet
Share
Other Decks in Programming
See All in Programming
Towards Structured Data: LLMs from Prototype to Production
inesmontani
PRO
0
140
Map のパフォーマンス向上のために検討されている SwissTable を理解する
andpad
1
8.6k
2024年版 Kotlin サーバーサイドプログラミング実践開発
n_takehata
2
220
デプロイ・QA・Four keys を自動化×見える化する freee の統合デリバリー基盤
akito0922
1
100
Gobra で見る形式検証 (mercari.go #26)
artoy
0
390
自分好みの TS バンドラを Rust で作れる!Deno の内部ライブラリの活用 – Denoで変わるランタイムの景色 実践事例 Lunch LT
pizzacat83
3
360
スタートアップ企業が実践する「身の丈スクラム」の現在地 / Current State of 'Right-Sized Scrum' Practices in Startups
ar_tama
6
1.3k
From Spring Boot 2 to Spring Boot 3 with Java 22 and Jakarta EE
ivargrimstad
0
540
生成AIキャラクター作成プラットフォームにおける LLM応答の柔軟性の拡張の工夫
ykimura517
3
680
あらゆるアプリをCompose Multiplatformで書きたい! -ネイティブアプリの「あの機能」を私たちはどう作るか-
subroh0508
0
160
End-to-End Encryption for Streaming Data Pipelines @ Berlin Buzzwords 2024
hpgrahsl
0
130
You may not need XXX in Node.js
masashi
5
910
Featured
See All Featured
Designing Experiences People Love
moore
136
23k
Imperfection Machines: The Place of Print at Facebook
scottboms
261
12k
Building Effective Engineering Teams - LeadDev
addyosmani
40
2.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
275
13k
Code Reviewing Like a Champion
maltzj
516
39k
Designing on Purpose - Digital PM Summit 2013
jponch
112
6.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
127
32k
Producing Creativity
orderedlist
PRO
338
39k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
23
1.5k
Visualization
eitanlees
137
14k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
228
16k
Transcript
It’s about time to pack Ruby and Ruby scripts in
one binary RubyKaigi 2024 ahogappa
About me • Sho Hirano(@ahogappa) • STORES, Inc. • #FFF613
2
What’s one binary? 3
What’s one binary? Works perfectly with just one file 4
Why one binary? 5
Why one binary in Ruby? 6
Why one binary in Ruby? e.g. distributing a Ruby project
7
Why one binary in Ruby? 💻 💻 developer user 8
Why one binary in Ruby? 💻 a.rb a.rb a.rb a.rb
💻 developer user 9
Why one binary in Ruby? 💻 a.rb a.rb a.rb a.rb
💻 Ruby 3.3.0 Sinatra 4.0.0 Sqlite3 2.0.1 developer user 10
Why one binary in Ruby? 💻 a.rb a.rb a.rb a.rb
💻🚫 Ruby 3.3.0 Sinatra 4.0.0 Sqlite3 2.0.1 Ruby 3.0.0 Sinatra 3.2.0 Sqlite3 Not installed developer user 11
Why one binary in Ruby? 💻 💻 Ruby 3.3.0 Sinatra
4.0.0 Sqlite3 2.0.1 developer user 12 Ruby 3.0.0 Sinatra 3.2.0 Sqlite3 Not installed
Why one binary in Ruby? 💻 💻 one binary developer
user Ruby 3.3.0 Sinatra 4.0.0 Sqlite3 2.0.1 13 Ruby 3.0.0 Sinatra 3.2.0 Sqlite3 Not installed
Why one binary in Ruby? 💻 💻✔ one binary Ruby
3.3.1 Sinatra 4.0.0 Sqlite3 2.0.1 a.rb a.rb a.rb a.rb developer user Ruby 3.3.1 Sinatra 4.0.0 Sqlite3 2.0.1 14 Ruby 3.0.0 Sinatra 3.2.0 Sqlite3 Not installed
Any existing tools? 15
Any existing tools? • ocra(ocran) • exerb • ruby2exe •
ruby-packer 16
🤔 Existing tools look good and useful 17
Existing tools look good and useful, but • No support
for 3.0+ • Patches Ruby • Windows only • Write temporary files 18
Time to make new one! 😄 19
Done 🔧 20
Kompo 📦 21
Kompo • 梱包(こんぽう) ◦ Means packaging, packing • A word
play on “compo” ◦ compose ◦ component ◦ composite ◦ etc… 22 https://github.com/ahogappa0613/kompo
Demo One binary with Sinatra and Sqlite3 23
Features 24
Features • Monkey patch only, not patching Ruby • No
write temporary files • Supports Gemfile • Reads local file as a fallback when failing to read from vfs 25
Demo Reads local file as a fallback when failing to
read from vfs 26
How kompo works 27
How kompo works • Ruby scripts are embedded • Patch
methods that read Ruby scripts ◦ Kernel#require ◦ Kernel#require_relative ◦ Kernel#load ◦ Kernel#autoload, Module#autoload • Native extensions are statically linked 28
29 libruby-static.a
30 libruby-static.a native extensions
main.c 31 libruby-static.a native extensions void Init_gems(void) { ruby_init_ext( "puma/puma_http11.so",
Init_puma_http11 ); ruby_init_ext( "sqlite3/sqlite3_native.so", Init_sqlite3_native ); } int main(int argc, char **argv) { ruby_sysinit(&argc, &argv); ruby_init(); Init_gems(); Init_kompo_fs(); … return ruby_run_node(node); }
main.c 32 kompofs.o +patches libruby-static.a native extensions
33 class Kompo def get_file(abs_path) # return the ruby script
from kompofs(.o) end … end main.c libruby-static.a native extensions kompofs.o +patches libkompo.a
main.c libkompo.a 34 libruby-static.a kompofs.o +patches native extensions one binary
compile and link libruby-static.a
Patches 35
Patches libruby-static.a main.rb b.rb d.rb a.rb Kernel#require Kernel#require_relative c.so 36
Patches libruby-static.a main.rb b.rb d.rb a.rb Kernel#require Kernel#require_relative c.so $
cd /workspace/sample $ kompo a.rb b.rb 37
Patches libruby-static.a main.rb b.rb Kernel#require Kernel#require_relative d.rb a.rb c.so 38
kompofs.o
Patches Ruby main.rb b.rb Kernel#require Kernel#require_relative c.o d.rb a.rb one
binary libkompo.a 39 main.c kompofs.o
Patches Ruby main.rb b.rb 🪡Kernel#require 🪡Kernel#require_relative c.o d.rb a.rb one
binary libkompo.a 40 module Kernel def require(path) eval(Kompo.get_file(path)) rescue => LoadError original_require(path) main.c kompofs.o
Patches Ruby main.rb b.rb 🪡Kernel#require 🪡Kernel#require_relative c.o d.rb a.rb one
binary require ‘a’ require_relative ‘./b’ require ‘c’ require ‘d’ libkompo.a 41 module Kernel def require(path) eval(Kompo.get_file(path)) rescue => LoadError original_require(path) main.c kompofs.o
Patches Ruby main.rb b.rb 🪡Kernel#require 🪡Kernel#require_relative c.o d.rb a.rb one
binary libkompo.a 42 module Kernel def require(path) eval(Kompo.get_file(path)) rescue => LoadError original_require(path) kompofs.o require ‘a’ require_relative ‘./b’ require ‘c’ require ‘d’ main.c
Future Works 43
Future Works • Support ways for users to access kompofs
freely • Cross-compilation • File compression 44
Let’s kompo Ruby! 45
Thank you!! 46