a Ruby project, it might not run because of version mismatches or missing libraries. • I want it to work by handing out just one file ◦ for example, when distributing a Ruby game. • Back in 2023, no one‑binary tool met my needs: ◦ easy to use ◦ cross‑platform ◦ compatible with the latest Ruby 5
a Ruby file is loaded, it is fetched from the embedded data instead of the filesystem • Statically links native extensions into the binary • For example, it could run programs built with Sinatra + SQLite ◦ Cannot yet run large Ruby projects like Rails 8
end autoload :Foo, './foo.rb' p Foo::Bar # => uninitialized constant Foo::Bar # => 🤯 class Foo autoload :Bar, './bar.rb' end class Foo class Bar; end end
• Users could not freely access files in one binary. ◦ for example, they could not use File.read. • Because it specialized only in require, it could embed only Ruby scripts, even though programs may also need YAML, CSV, and other files. • It could not handle directories, so iterating with `Dir.children` was impossible. 17
the one binary. • When Ruby calls functions such as read or open, allow it to choose whether to load data from the physical file system or from the embedded binary. 19
the data embedded in the binary when libc's read or read is called. • Supporting only read‑only functions is sufficient; covering every feature is unnecessary. 20
Ruby calls read, it must be able to choose whether to call libc's read or kompo's read. ◦ A straightforward implementation would lead to recursion. • I want to link libc's read while also linking a custom read that performs additional processing. ◦ In other words, we want to intercept the call. 22 CRuby code read(fd); kompo code ssize_t read(int fd); { … read(fd); … } Usually, libc's read is called. This read refers to itself, not to libc.
enough ◦ Simulate the filesystem • Dynamically getting a function address using `dlsym(RTLD_NEXT)` ◦ The implementation stays very simple ◦ Like `--wrap`, it is an extension, but easier to compile 24
stat(2) - opendir(2) - readdir(2) - chdir(2) - getcwd(2) … kompo wrap - Access binary data under these conditions: - Absolute path: Check the embedded file system. - Relative path: Consider the current directory and check if the file exists in the binary or file system. physical file system - /real/b/c.rb - /real/b/d.rb …
stat(2) - opendir(2) - readdir(2) - chdir(2) - getcwd(2) … kompo wrap - Access binary data under these conditions: - Absolute path: Check the embedded file system. - Relative path: Consider the current directory and check if the file exists in the binary or file system. physical file system - /real/b/c.rb - /real/b/d.rb … virtual file system - /kompo/b/c.rb - /kompo/b/d.rb …
- open(2) - read(2) - stat(2) - opendir(2) - readdir(2) - chdir(2) - getcwd(2) … physical file system - /real/b/c.rb - /real/b/d.rb … virtual file system - /kompo/b/c.rb - /kompo/b/d.rb … kompo wrap - Access binary data under these conditions: - Absolute path: Check the embedded file system. - Relative path: Consider the current directory and check if the file exists in the binary or file system.
functions in ruby - open(2) - read(2) - stat(2) - opendir(2) - readdir(2) - chdir(2) - getcwd(2) … physical file system - /real/b/c.rb - /real/b/d.rb … virtual file system - /kompo/b/c.rb - /kompo/b/d.rb … kompo wrap - Access binary data under these conditions: - Absolute path: Check the embedded file system. - Relative path: Consider the current directory and check if the file exists in the binary or file system.
functions in ruby - open(2) - read(2) - stat(2) - opendir(2) - readdir(2) - chdir(2) - getcwd(2) … physical file system - /real/b/c.rb - /real/b/d.rb … virtual file system - /kompo/b/c.rb - /kompo/b/d.rb … kompo wrap - Access binary data under these conditions: - Absolute path: Check the embedded file system. - Relative path: Consider the current directory and check if the file exists in the binary or file system.
ruby - open(2) - read(2) - stat(2) - opendir(2) - readdir(2) - chdir(2) - getcwd(2) … physical file system - /real/b/c.rb - /real/b/d.rb … virtual file system - /kompo/b/c.rb - /kompo/b/d.rb … kompo wrap - Access binary data under these conditions: - Absolute path: Check the embedded file system. - Relative path: Consider the current directory and check if the file exists in the binary or file system. current directory
binary easily ◦ Support coming soon • Cross-platform support ◦ Not yet available • Requires no additional installation ◦ Already achieved • Runs at a decent speed ◦ Needs refactoring 37
a one binary. • I tried various implementations and found a workable method. • With this implementation, I managed to make Rails run as one binary. • From now on, I want to focus on turning it into a gem and adding cross-platform support. 38