HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
jart
cosmopolitan
C2020–2026
jart / cosmopolitan

cosmopolitan

build-once run-anywhere c library

135Distinct people
293Mentions
3Explicit recommenders
21.4KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

build-once run-anywhere c library

GitHub

Where it is used

  • Blink — Blink uses Cosmopolitan Libc as the primary target for the binaries it runs. It is designed to support Cosmopolitan-built APE executables and relies on them heavily in testing. Source

What people are saying

JVM bytecode is obviously not what I was talking about - it is neither low-level (if you can't efficiently compile the entirety of C into it, it's not good enough for this…

int_19h used a recommendation phrase. 8 indexed comments match. This is a phrase match, not a verdict.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 9–Nov 16 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/16/2026, 8:59:02 AM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year293 dated mentions

Observed mentions: 2020-06-20 21:16:58 UTC to 2026-10-11 05:47:52 UTC.

02040602020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 26 mentions; 1 submissions, 25 comments20202021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 69 mentions; 4 submissions, 65 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 69 mentions; 5 submissions, 64 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 35 mentions; 1 submissions, 34 comments20232024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 55 mentions; 9 submissions, 46 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 22 mentions; 3 submissions, 19 comments2026-01-01 00:00:00 UTC to 2027-01-01 00:00:00 UTC (exclusive): 17 mentions; 1 submissions, 16 comments. Incomplete calendar period.2026*

* An incomplete calendar period is marked with an outlined bar. Its count is not directly comparable with a full period.

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC26125
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC69465
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC69564
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC35134
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC55946
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC22319
2026 (partial)2026-01-01 00:00:00 UTC2027-01-01 00:00:00 UTC17116

From the project README

An excerpt from the repository, fetched Nov 12, 2026.

Read the project’s introduction
Cosmopolitan 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 and Clang to output a POSIX-approved polyglot format that runs natively on Linux + Mac + Windows + FreeBSD + OpenBSD 7.3 + NetBSD + BIOS with the best possible performance and the tiniest footprint imaginable. Background For an introduction to this project, please read the actually portable executable blog post and cosmopolitan libc website. We also have API documentation. Getting Started You can start by obtaining a release of our cosmocc compiler from https://cosmo.zip/pub/cosmocc/. mkdir -p cosmocc cd cosmocc wget https://cosmo.zip/pub/cosmocc/cosmocc.zip unzip cosmocc.zip Here's an example program we can write: // hello.c #include <stdio.h> int main() { printf("hello world\n"); } It can be compiled as follows: cosmocc -o hello hello.c ./hello The Cosmopolitan Libc runtime links some heavyweight troubleshooting features by default, which are very useful for developers and admins. Here's how you can log system calls: ./hello --strace Here's how you can get a much more verbose log of function calls: ./hello --ftrace You can use the Cosmopolitan's toolchain to build conventional open source projects which use autotools. This strategy normally works: export CC=x86_64-unknown-cosmo-cc export CXX=x86_64-unknown-cosmo-c++ ./configure --prefix=/opt/cosmos/x86_64 make -j make install Cosmopolitan Source Builds Cosmopolitan can be compiled from source on any of our supported platforms. The Makefile will download cosmocc automatically. It's recommended that you install a systemwide APE Loader. This command requires sudo access to copy the ape command to a system folder and register with binfmt_misc on Linux, for even more performance. ape/apeinstall.sh You can now build the mono repo with any modern version of GNU Make. To bootstrap your build, you can install Cosmopolitan Make from this site: https://cosmo.zip/pub/cosmos/bin/make E.g.: curl -LO https://cosmo.zip/pub/cosmos/bin/make ./make -j8 o//examples/hello After you've built the repo once, you can also use the make from your cosmocc at .cosmocc/current/bin/make. You might even prefer to alias make to $COSMO/.cosmocc/current/bin/make. Since the Cosmopolitan repository is very large, you might only want to build one particular thing. Here's an example of a target that can be compiled relatively quickly, which is a simple POSIX test that only depends on core LIBC packages. rm -rf o//libc o//test .cosmocc/current/bin/make o//test/posix/signal_test o//test/posix/signal_test Sometimes it's desirable to build a subset of targets, without having to list out each individual one. For example if you wanted to build and run all the unit tests in the TEST_POSIX package, you could say: .cosmocc/current/bin/make o//test/posix Cosmopolitan provides a variety of build modes. For example, if you want really tiny binaries (as small as 12kb in size) then you'd say: .cosmocc/current/bin/make m=tiny You can furthermore cut out the bloat of other operating systems, and have Cosmopolitan become much more similar to Musl Libc. .cosmocc/current/bin/make m=tinylinux For further details, see //build/config.mk. Debugging To print a log of system calls to stderr: cosmocc -o hello hello.c ./hello --strace To print a log of function calls to stderr: cosmocc -o hello hello.c ./hello --ftrace Both strace and ftrace use the unbreakable kprintf() facility, which is able to be sent to a file by setting an environment variable. export KPRINTF_LOG=log ./hello --strace GDB Here's the recommended ~/.gdbinit config: set host-charset UTF-8 set target-charset UTF-8 set target-wide-charset UTF-8 set osabi none set complaints 0 set confirm off set history save on set history filename ~/.gdb_history define asm layout asm layout reg end define src layout src layout reg end src You normally run the .dbg file under gdb. If you need to debug the `` file itself, then you can load the debug symbols independently as gdb foo -ex 'add-symbol-file foo.dbg 0x401000' Platform Notes Shells If you use zsh and have trouble running APE programs try sh -c ./prog or simply upgrade to zsh 5.9+ (since we patched it two years ago). The same is the case for Python subprocess, old versions of fish, etc. Linux Some Linux systems are configured to launch MZ executables under WINE. Other distros configure their stock installs so that APE programs will print "run-detectors: unable to find an interpreter". For example: jart@ubuntu:~$ wget https://cosmo.zip/pub/cosmos/bin/dash jart@ubuntu:~$ chmod +x dash jart@ubuntu:~$ ./dash run-detectors: unable to find an interpreter for ./dash You can fix that by registering APE with binfmt_misc: sudo wget -O /usr/bin/ape https://cosmo.zip/pub/cosmos/bin/ape-$(uname -m).elf sudo chmod +x /usr/bin/ape sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" sudo sh -c "echo ':APE-jart:M::jartsr::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" You should be good now. APE will not only work, it'll launch executables 400µs faster now too. However if things still didn't work out, it's also possible to disable binfmt_misc as follows: sudo sh -c 'echo -1 > /proc/sys/fs/binfmt_misc/cli' # remove Ubuntu's MZ interpreter sudo sh -c 'echo -1 > /proc/sys/fs/binfmt_misc/status' # remove ALL binfmt_misc entries WSL It's normally unsafe to use APE in a WSL environment, because it tries to run MZ executables as WIN32 binaries within the WSL environment. In order to make it safe to use Cosmopolitan software on WSL, run this: sudo sh -c "echo -1 > /proc/sys/fs/binfmt_misc/WSLInterop" Discord Chatroom The Cosmopolitan development team collaborates on the Redbean Discord server. You're welcome to join us! https://discord.gg/FwAVVu7eJ4 Support Vector Platform Min Version Circa AMD K8 2003 Intel Core 2006 Linux 2.6.18 2007 Windows 8 [1] 2012 Darwin (macOS) 2
Read the full README on GitHub

What Hacker News says

69 sources
Here's a 2000 line web server I wrote in C (with a focus on readability) which runs https://ipv4.games/ You can read the code at https://github.com/jart/cosmopolitan/blob/master/net/turfwar... This web server runs on a single VM. It was handling about 300 write requests per second earlier today. You can monitor its metrics here: https://ipv4.games/statusz It uses *NSYNC as its multi-threaded locking primitives, which was designed by the guy who created Google's lock server. This service is frequently targeted by hackers so you can learn a lot about things like DDOS protection by reading the source.
In Ask HN: Resources for Building a Webserver in C?
Indeed! If your dependencies are able to be command line programs that are shell scripted together, then you can in fact have an access policy on a per-dependency basis, using the pledge.com program linked on my website. So shell scripters rejoice. But it gets better. If you build Python in the Cosmopolitan Libc repository: git clone https://github.com/jart/cosmopolitan cd cosmopolitan build/bootstrap/make.com -j8 o//third_party/python/python.com Then you can use cosmo.pledge() directly from Python. $ o//third_party/python/python.com Python 3.6.14+ (Actually Portable Python) [GCC 9.2.0] on cosmo Type "help", "copyright", "credits" or "license" for more information. >>: import cosmo, socket >>: cosmo.pledge('stdio rpath wpath tty', None) >>: print('hi') hi >>: socket.socket() Traceback (most
Read the rest
recent call last): File "<stdin>", line 1, in <module> File "/zip/.python/socket.py", line 144, in __init__ _socket.socket.__init__(self, family, type, proto, fileno) PermissionError: [Errno 1] EPERM/1/Operation not permitted Since we didn't put "inet" in the pledge, you can now be certain your PyPi deps aren't spying on you or uploading your bitcoin wallet to the cloud. You can even use os.fork() to rapidly put each dependency in its own process, then call cosmo.pledge() afterwards to grant each component of your app its own maximally restrictive policy. Cosmopolitan Python also ports OpenBSD's unveil() system call to Linux too. For example, to disallow all file system access, just call cosmo.unveil(None, None). You need a very recent version of Linux though. For instance, I use unveil() in production on GCE but I had to apt install linux-image-5.18.0-0.deb11.4-cloud-amd64 in order for Landlock LSM to be available to use unveil().
In Dozens of malicious PyPI packages discovered targeting developers
We don't use SYSCALL on Windows. We link KERNEL32 and friends. It adds bloat to our binaries (for instance, hello world could be 4kb rather than 16kb if we didn't need DLLs) but Microsoft leaves us with little other option, since it'd require just as much bloat to use Xed to wrangle the syscall ordinals out of NTDLL. Our policy is to stick with stable supported interfaces whenever possible. Since XNU's SYSCALL interface is allowed, and it's nearly identical to those of Linux and BSDs, it'd be tragic to not use something that fits so perfectly hand in glove with the rest of our system call support. Look here, all we need to support a XNU system call is 16-bits of a word. https://github.com/jart/cosmopolitan/blob/2.1/libc/sysv/sysc...
In Can I use a system call?
Redbean is a webserver. Go is not a webserver. Redbean cannot be "faster than Go". That's like saying that a car is faster than aluminum. Do you have benchmarks of Redbean versus Caddy that you can point to? I certainly haven't been able to find any. I also haven't been able to find any in-depth independent benchmarks of Redbean. About the only thing I could find was someone struggling to reproduce the benchmark results.[0] Personally, I've dealt with more than enough memory safety vulnerabilities caused by no programmer being good enough to write safe and correct C (or C++). Those vulnerabilities are easily prevented by choosing just about any other language people are likely to know about... so, I have no desire to deploy anything like Redbean when alternatives exist. It's cool to see the hacks they've been able to do with Cosmopolitan
Read the rest
to make cross platform binaries, but hacks like that are not what I want for anything other than educational purposes, at least not until they've been more battle tested. [0]: https://github.com/jart/cosmopolitan/issues/72
In Caddyhttp: Enable HTTP/3 by Default
https://github.com/jart/cosmopolitan/issues/140 https://github.com/golang/go/issues/51900 & from what I gather, APE is tightly-bound to x86_64, & depends on an embedded emulator for other architectures: > All we have to do embed an ARM build of the emulator above within our x86 executables, and have them morph and re-exec appropriately, similar to how Cosmopolitan is already doing doing with qemu-x86_64, except that this wouldn't need to be installed beforehand. The tradeoff is that, if we do this, binaries will only be 10x smaller than Go's Hello World, instead of 100x smaller. could still be useful as an optional build target though... (i.e. GOOS=cosmopolitan)
In How fat does a fat binary need to be? (2021)

Showing the 15 most recent of 69 sources. Enable JavaScript to search and browse every indexed mention.

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.