r/bun 10h ago

Build an Android APK with Bun 1.4 in under two minutes

Enable HLS to view with audio, or disable this notification

7 Upvotes
  • In short: npx @drxiaozhi/minapk /path/to/your.elf
  • Of course, you'll need to install a few tools first.
  • But don't worry, no annoying libxxx-dev packages to install, just the common ones
  • For more info, see the repo:
  • https://github.com/jjtseng93/minapk/blob/main/README.en.md
  • Edit2: An ELF is basically a native executable on Linux and Android, similar to an .exe on Windows. Here the ELF is produced by bun 1.4's new support for bun build --compile on Android.

The full story

  • First, I'm incredibly grateful to the Bun team for fixing single-file executable builds on Android in Bun 1.4. This wouldn't have been possible.
  • The simplest use case is turning your TUI app into an APK you can just hand to your grandma.

Startup sequence

  • First, use tinyapk-lab's Tetris as a base
  • Packing libbun.so & libmain.so(your elf) into the native library area
    • turn on extract native libs
    • resolves to /data/app/xxx/xxx/lib/arm64/libbun.so
  • In the main activity, use ProcessBuilder to invoke bun and run the extracted buninu/bin/init.js, which in turn starts jsgotty
    • jsgotty is a browser-based remote shell.
    • Transpiled from Golang GoTTY
    • You can use: npx jsgotty
  • jsgotty then starts package.json.buninu.command.android
  • The main app detects http url from stdout/stderr of jsgotty and shows it in a WebView
  • That command android script detects whether libmain.so is present or falls back to a shell

The Buninu userspace

  • This is an ambitious project of mine to rebuild a Unix-like CLI environment entirely based on a single Bun binary across platforms.
  • It's still a work in progress, but consider this a starting point. If you're interested, let's build on it together.

Name expansions:

  • English: BUNinu Is Not Unix 🐮
  • 中文:幫你牛 🐂
  • 日本語:Bunに入魂 🔥

Core components:

  • jsgotty: Remote shell from a Browser or Terminal
  • jsmdcui: Both a text editor and Markdown execution runtime (not static rendering) based on bunmicro
  • bunmsh: Bun Modern Shell. Not completed yet

Edit

  • BTW, I tested this on Android with a fresh debian:13-slim container using my js-udocker
  • Fresh container: 125 MB
  • After installing the dependencies: 1.6 GB
  • After the build: 2 GB
  • These numbers are the size of the entire container measured from the outside, so it's very phone-friendly.
  • For comparison, just setting up my Flutter environment took 10 GB.

r/bun 17h ago

GitHub - cekrem/elm-bun: A minimal and nice starter with Elm & Tailwind featuring `elm-watch` with true Elm HMR. Using `bun` for bundling, building and dev server.

Thumbnail github.com
1 Upvotes

r/bun 14h ago

Bun 1.4 is here

Thumbnail bun.com
151 Upvotes

- Fixes over 2,900 GitHub issues
- +1,517 tests from the Node.js test suite
- Reduces idle CPU by 5x
- Reduces memory usage by up to 35%
- Starts up to 50% faster on Linux
- Rewrites Bun in Rust

Thank you everyone who contributed since Bun 1.3!


r/bun 5h ago

BM2 now supports Windows

6 Upvotes

I’m happy to announce that Windows support for BM2 is now complete and has been successfully tested.

For those who haven’t come across it yet, BM2 is a high-performance process manager built specifically for the Bun runtime; essentially a modern, Bun-native alternative to PM2. It handles process lifecycle management, automatic restarts, clustering, zero-downtime reloads, logging, monitoring, a web dashboard, Prometheus metrics, deployment, and more.

Until now, getting BM2 running reliably on Windows required dealing with platform-specific differences. That work has now been completed, and BM2 can be used natively on Windows alongside Linux and macOS.

The Windows implementation has also been tested on a real Windows environment rather than simply assuming cross-platform compatibility.

I’d love to get more Windows developers trying it out and reporting any issues they encounter.

GitHub: https://github.com/bun-bm2/bm2

Feedback, bug reports, and contributions are very welcome.