Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

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

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

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_init
c = Curl.new
r = 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

Variable Default Description
COSMO_ROOT ~/cosmocc Path to cosmocc toolchain
JOBS 4 Parallel 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 methods
r = Curl.get("https://example.com")
puts r.status_code  # => 200
puts r.body

# Instance methods for reuse
c = Curl.new
c.timeout = 30

r = c.get("https://api.example.com/data", {"Authorization" => "Bearer token"})
puts r.body

r = c.post("https://api.example.com/data", '{"key":"value"}',
           {"Content-Type" => "application/json"})
puts r.body

# Other HTTP methods
c.put(url, data, headers)
c.patch(url, data, headers)
c.delete(url, headers)

# Streaming with blocks
c.get("https://example.com/large") do |header, chunk|
  print chunk
end

Dependency versions

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

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