Cosmopolitan Libc makes C a build-once run-anywhere language, like Java, except it doesn't need an interpreter or virtual machine. Instead, it reconfigures stock GCC and Clang to output a POSIX-approved polyglot format that runs natively on Linux + Mac + Windows + FreeBSD + OpenBSD + NetBSD + BIOS with the best possible performance and the tiniest footprint imaginable.
This release adds features such as Lua server pages to redbean (which last month became the third most popular "Show HN" thread). There's been a number of performance enhancements, improvements to compatibility, and bug fixes. We also managed to port several high-level languages to Cosmopolitan with passing test suites. This project has also received its first thirty sponsors. Thank you for your support!
Changes
- Major improvements to redbean 09bcfa2 4d21cd3 dcbd2b8 a1677d6 3c19b6e 1753b66
- Major improvements to stdio da36e7e c3ed8d6 aad8416
- Add socketpair thanks to @fabriziobertocci ca88ce5
- Numerous bug fixes, thanks to @alisonatwork 9c81729 6cd1037 8a6ac6d f5da4ef 813e11b 5d334b9
- Add missing math functions, and fix isystem headers, thanks to @dosisod 8a23643 fb7b7c6
- Fix APE error if unable to modify self, thanks to @tomberek 0eaad9d
- UEFI support 537c213
- Support proper %g, %f, and %a float formatting f064183
- Add posix_spawn 5ce83b0
- Make pow() conform to standard definition 8af91bc 43b2475
Getting Started
If you're doing your development work on Linux or BSD then you need just five files to get started. Here's what you do on Linux:
wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-0.3.zip
unzip cosmopolitan-amalgamation-0.3.zip
printf 'main() { printf("hello world\\n"); }\n' >hello.c
gcc -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
-fno-omit-frame-pointer -pg -mnop-mcount \
-o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds \
-include cosmopolitan.h crt.o ape.o cosmopolitan.a
objcopy -S -O binary hello.com.dbg hello.com
You now have a portable program. Please note that your APE binary will assimilate itself as a conventional resident of your platform after the first run, so it can be fast and efficient for subsequent executions.
./hello.com
bash -c './hello.com' # zsh/fish workaround (we upstreamed a patch)
So if you intend to copy the binary to Windows or Mac then please do that before you run it, not after.
If you're developing on Windows or MacOS then you need to download an x86_64-pc-linux-gnu toolchain beforehand. See the Compiling on Windows tutorial. It's needed because the ELF object format is what makes universal binaries possible.
Cosmopolitan can also be compiled from source on any Linux distro.
wget https://justine.lol/cosmopolitan/cosmopolitan-0.3.tar.gz
tar xf cosmopolitan-0.3.tar.gz # see releases page
cd cosmopolitan
make -j16
o//examples/hello.com
find o -name \*.com | xargs ls -rShal | less
Contributing
We now have automated Travis CI testing. That means any pull request you send is going to get feedback in two minutes, which is how long it takes to build and test this whole repository inside a tiny VM.
Support Vector
Platform | Min Version | Circa |
---|---|---|
AMD | K8 Venus | 2005 |
Intel | Core | 2006 |
New Technology | Vista | 2006 |
GNU/Systemd | 2.6.18 | 2007 |
XNU's Not UNIX! | 15.6 | 2018 |
FreeBSD | 12 | 2018 |
OpenBSD | 6.4 | 2018 |
NetBSD | 9.1 | 2020 |