Skip to content

Latest commit

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

mruby-cosmo-curl

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.

What you get

BinarySizeDescription
mruby.com~7.5 MBmruby interpreter with HTTP/HTTPS support
mirb.com~7.5 MBInteractive mruby REPL
mrbc.com~1.7 MBmruby bytecode compiler
mrdb.com~7.5 MBmruby debugger

Quick start

# 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'

Prerequisites

  • cosmocc toolchain — download from https://cosmo.zip/pub/cosmocc/
    • Set COSMO_ROOT env var if not at ~/cosmocc
  • Ruby — needed to run mruby's Rake-based build system
  • Standard build toolscurl, tar, make, perl (for OpenSSL Configure)

Build options

./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

Environment variables

VariableDefaultDescription
COSMO_ROOT~/cosmoccPath to cosmocc toolchain
JOBS4Parallel make jobs

Architecture

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.

Static library layout

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.

API usage

# 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

Dependency versions

LibraryVersionLicense
mruby4.0.0 (HEAD)MIT
libcurl8.10.1MIT/X
OpenSSL1.1.1wApache-2.0
zlib1.3.1zlib
mruby-curllatestMIT
mruby-httplatestMIT

How it works

  1. cosmocc is a GCC wrapper that compiles C code for both x86_64 and aarch64 simultaneously, producing ELF objects for each architecture.

  2. cosmoar creates archives containing both architecture variants — the x86_64 .a in the current directory and the aarch64 .a in .aarch64/.

  3. The final link step uses apelink to combine both architecture binaries into a single polyglot file that identifies itself correctly on each OS/arch.

  4. The resulting .com file is simultaneously a valid DOS MBR, Windows PE, Linux ELF, macOS Mach-O, and more.

License

This build scaffolding is MIT licensed. Individual components retain their original licenses (see table above).

About

mruby compiled with cosmopolitan to embed into rapidforge

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages