Cosmopolitan v2.1
Cosmopolitan Libc makes C/C++ a build-once run-anywhere language, like Java, except it doesn't need an interpreter or virtual machine. Instead, it reconfigures stock GCC to output a POSIX-approved polyglot format that runs natively on Linux + Mac + Windows + FreeBSD + OpenBSD + NetBSD + BIOS or UEFI with the best possible performance and the tiniest footprint imaginable.
Getting Started
If you use Linux, then you can build Cosmopolitan and its included software from source as follows:
wget https://justine.lol/cosmopolitan/cosmopolitan-2.1.tar.gz
tar xf cosmopolitan-2.1.tar.gz
cd cosmopolitan
build/bootstrap/make.com -j8
o//examples/hello.com
If you're doing your development work on Linux or BSD and you want to bring your own build system, then you need just five files to get started:
wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-2.1.zip
unzip cosmopolitan-amalgamation-2.1.zip
printf 'main() { printf("hello world\\n"); }\n' >hello.c
gcc -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone -gdwarf-4 \
-fno-omit-frame-pointer -pg -mnop-mcount -mno-tls-direct-seg-refs \
-o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds -Wl,--gc-sections \
-include cosmopolitan.h crt.o ape-no-modify-self.o cosmopolitan.a
objcopy -S -O binary hello.com.dbg hello.com
Features
- Introduce POSIX threads support with locking primitives based on *NSYNC
- Add VGA terminal support on bare metal (see examples/vga.c) 3fdb1c1
- System call portability is now documented at https://justine.lol/cosmopolitan/functions.html
- Add cosmocc and cosmoc++ scripts which can serve as an open source toolchain 6cc9e08
- Add lchown(), lchmod(), statvfs(), fstatvfs() 5a632cf
- Add sigpending() a849a63
- Add getgroups() and setgroups() 4c40c50
- Implement inet_pton for AF_INET6 d213a48
- The _gc() garbage collector is now thread safe 0e2b1bf
- Use OpenBSD qsort() which is faster (quicksort) and secure (heapsort fallback) d861d27
- Add notpossible keyword and _npassert() 0c70e89
- IPv6 is now polyfilled on non-Linux 0547eab
- Introduce
MODE=fastbuild
and shorthand notationm=fastbuild
Bug Fixes
- Upgrade to the latest Chromium Zlib. This improves security and performance 224c12f 775944a
- Fix out of bounds read in IP address parser 775944a
- APE binaries now work better with BusyBox 0305194
- Numerous fixes to bare metal support 3733b43 8569704 e0fabd1
- Fix bug where SIG_IGN and SIG_DFL weren't working as advertised on BSDs c5c4dfc
- Improve quality of raise(), abort(), and tkill() c5c4dfc
- Improve quality of uname(), gethostname(), and getdomainname() b66bd06
- Improve quality of clock() 12d9e1e
- Improve quality of copy_file_range(), sendfile(), splice(), openpty(), closefrom(), close_range(), fadvise() and posix_fadvise() c7a8cd2 9fa6725
- Fix _Thread_local with fork() on Windows bf757c4
- Improve zipos path handling 1ef955c
- Fix preadv() and pwritev() for old distros 3f49889
- Support fcntl(F_DUPFD_CLOEXEC) on more systems 3f49889
- Fix POSIX advisory locks on Windows 3f49889
- Fix race condition in makedirs() 571c2c3
- Fix pledge() thread kill semantics 1ea01fc
- Improve open source compatibility b73e35c dbf12c3 55c6297
- Make
SIG_DFL
andSIG_IGN
C++ compatible 8cd4248 - Discard ignored signals on New Technology 7de2f22
- Fix inability to add some signals to mask on NT 5986408
- Fix issue with ZipOS file descriptors in MODE=asan 3265324
- The virtual memory layout is now more optimized b69f3d2
- Repository is now buildable by GCC11
Breaking changes
- Underscore added to many non-standard APIs to improve open source compatibility 6f7d0cb
- Windows 7 and Vista support has now been moved to our vista branch 134ffee
- Add sys_ prefix to unwrapped system calls to improve open source compatibility aab4ee4
- Debug symbols now removed from
MODE=tiny*
builds by default - Removed
testonly
keyword
Third Party
- FreeBSD's
o//examples/script.com
can record and playback terminal screencasts on five OSes 1ad2f53 - NetBSD's
sed
command is now available in third_party/sed/ - The One True Awk is now available in third_party/awk/ and https://justine.lol/awk/
Community
- We built an online game (https://ipv4.games/) based on Redbean that handled 600 qps on just 2 vcpu (Loam and https://github.com/shamblesides/turfwar/)
- We got Actually Portable Perl 96% passing test suites (G4Vi https://github.com/G4Vi/perl5/blob/cosmo/README.cosmo)
- We got Actually Portable Python 3.11.0rc1 passing 96% test suites (ahgamut https://github.com/ahgamut/cpython/tree/cosmo_py311)
- We got 176 Actually Portable Rust demo programs to build (ahgamut https://github.com/ahgamut/rust-ape-example)