Build a standalone Actually Portable Executable (APE) of mruby with the mruby-curl gem, statically linked against libcurl, OpenSSL, and zlib — all compiled with the Cosmopolitan Libc toolchain.
The resulting mruby.com binary runs unmodified on Linux, macOS, Windows, FreeBSD,
OpenBSD, and NetBSD — on both x86-64 and ARM64 — without recompilation.
| Binary | Size | Description |
|---|---|---|
mruby.com | ~7.5 MB | mruby interpreter with HTTP/HTTPS support |
mirb.com | ~7.5 MB | Interactive mruby REPL |
mrbc.com | ~1.7 MB | mruby bytecode compiler |
mrdb.com | ~7.5 MB | mruby debugger |
# 1. Install cosmocc toolchain
mkdir -p ~/cosmocc &&cd~/cosmocc
wget https://cosmo.zip/pub/cosmocc/cosmocc.zip
unzip cosmocc.zip
# 2. Clone and build
git clone https://github.com/<your-username>/mruby-cosmo-curl.git
cd mruby-cosmo-curl
./build.sh
# 3. Run
./mruby/build/host/bin/mruby.com -e 'Curl.global_initc = Curl.newr = c.get("https://httpbin.org/get")puts r.body'- cosmocc toolchain — download from https://cosmo.zip/pub/cosmocc/
- Set
COSMO_ROOTenv var if not at~/cosmocc
- Set
- Ruby — needed to run mruby's Rake-based build system
- Standard build tools —
curl,tar,make,perl(for OpenSSL Configure)
./build.sh # Full build: dependencies + mruby
./build.sh deps # Build only static libraries (zlib, OpenSSL, libcurl)
./build.sh mruby # Build only mruby (requires deps already built)
./build.sh clean # Remove all build artifacts| Variable | Default | Description |
|---|---|---|
COSMO_ROOT | ~/cosmocc | Path to cosmocc toolchain |
JOBS | 4 | Parallel make jobs |
build.sh
├── Downloads & builds zlib 1.3.1 (static, dual-arch)
├── Downloads & builds OpenSSL 1.1.1w (static, dual-arch)
├── Downloads & builds libcurl 8.10.1 (static, dual-arch)
└── Builds mruby with:
├── mattn/mruby-http (HTTP response parser)
├── mattn/mruby-curl (libcurl bindings)
└── All standard mruby gems (IO, socket, math, etc.)
cosmocc compiles every .c file for both x86_64 and aarch64.
The linker produces a single "fat" APE binary that works on all platforms.
The cosmocc compiler expects dual-architecture libraries:
sysroot/lib/
├── libcurl.a # x86_64
├── libssl.a
├── libcrypto.a
├── libz.a
└── .aarch64/ # aarch64 variants
├── libcurl.a
├── libssl.a
├── libcrypto.a
└── libz.a
When cosmocc sees -L/path, it automatically looks in /path/.aarch64/ for
the aarch64 linker.
# Initialize (call once)Curl.global_init# Simple class methodsr=Curl.get("https://example.com")putsr.status_code# => 200putsr.body# Instance methods for reusec=Curl.newc.timeout=30r=c.get("https://api.example.com/data",{"Authorization"=>"Bearer token"})putsr.bodyr=c.post("https://api.example.com/data",'{"key":"value"}',{"Content-Type"=>"application/json"})putsr.body# Other HTTP methodsc.put(url,data,headers)c.patch(url,data,headers)c.delete(url,headers)# Streaming with blocksc.get("https://example.com/large")do |header,chunk|
printchunkend| Library | Version | License |
|---|---|---|
| mruby | 4.0.0 (HEAD) | MIT |
| libcurl | 8.10.1 | MIT/X |
| OpenSSL | 1.1.1w | Apache-2.0 |
| zlib | 1.3.1 | zlib |
| mruby-curl | latest | MIT |
| mruby-http | latest | MIT |
cosmocc is a GCC wrapper that compiles C code for both x86_64 and aarch64 simultaneously, producing ELF objects for each architecture.
cosmoar creates archives containing both architecture variants — the x86_64
.ain the current directory and the aarch64.ain.aarch64/.The final link step uses apelink to combine both architecture binaries into a single polyglot file that identifies itself correctly on each OS/arch.
The resulting
.comfile is simultaneously a valid DOS MBR, Windows PE, Linux ELF, macOS Mach-O, and more.
This build scaffolding is MIT licensed. Individual components retain their original licenses (see table above).