2 min read

Shipping a Rust sidecar inside a desktop app

Eben's window is Kotlin, and time tracking lives in a Rust service the app starts itself. Getting that second program to start on every installed machine took more work than writing it.

  • Rust
  • Kotlin
  • Packaging

Eben is two programs. The window is Kotlin with Compose Multiplatform. Next to it runs eben-sidecar, a Rust service that talks to PostgreSQL and answers the window over gRPC on 127.0.0.1. Time tracking depends on it; the boards can work without it.

Finding the binary

The window looks for the service in a fixed order: inside the installed app first, then in a developer checkout's build output. If none exists, the error names every path it tried, so a broken package says where the file should have been.

The executable bit

The Linux package installed cleanly, and then the service would not start. The packaging step copies bundled files byte for byte, so the service arrived without its executable bit, as 0644. No build hook runs late enough to fix that.

The app can't chmod a file it doesn't own, and a system install under /opt belongs to root. So when the bundled binary can't run, Eben copies it into its own config folder and runs the copy. It refreshes that copy whenever the size or the timestamp differs, because running last version's service against this version's schema is exactly the failure to avoid.

Which port?

A fixed port collides sooner or later. The service binds to port 0, the operating system picks a free one, and the service prints it on its first line:

SIDECAR_LISTENING 49731

The window reads that line and connects. It waits up to 30 seconds. If the service exits first, the error carries its exit code and the last 40 lines it wrote to stderr, which usually say why: no database configured, or migrations refused.

When it won't start

A frozen window is the worst answer. When the service fails, Eben shows the reason and two buttons: Try again, or Continue without it. Boards keep working, and only time tracking is unavailable until the next start.

Give the user a way out. A clear error with a choice beats a spinner that never ends.

Shutting down

Closing the window stops the service: a polite stop, two seconds of grace, then a forced kill. A shutdown hook covers crashes too, so the service never outlives the app that started it.

What I'd keep

  • Treat the second program as a dependency with a lifecycle, not as a library call.
  • Let the service announce its port; never guess.
  • Install every package on a clean machine before a release.
  • Rust
  • Kotlin
  • Packaging

Stuck on a problem like this one? Describe it in a few lines and I'll tell you how I'd approach it.

Describe your problem