Cosmopolitan Versions Save

build-once run-anywhere c library

2.1.1

1 year ago

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.

This release fixes bugs and makes system call wrapper improvements:

  • Fix corner case in Linux stack mappings 3b4fcd8575e2048987721fda130e501877607dfa
  • Implement clock_nanosleep() across platforms and refactor sleeping code to use it.
  • Polyfill futexes on unsupported platforms by polling memory with exponential backoff
  • Imported *NSYNC unit tests and confirmed we're passing them (except for cancellations on Windows)
  • system() now uses our builtin cocmd interpreter which offers a subset of bourne that works on windows and is fast
  • sched_setaffinty() is now explicitly for processes since we now have pthread_setaffinity_np() for threads
  • Numerous improvements to system call documentation, especially when it comes to possible errno results
  • Change accept type to struct sockaddr * (#630)
  • Rewrite brk() and sbrk() 5005f2e44651c8be30b5730398c232c4cdadefce which can be used by tiny apps that don't want to link mmap() and would rather have 4096-byte memory granularity, with the tradeoff of not working on Windows

We're working to make every Cosmopolitan binary a true operating system by introducing features like VGA support:

  • Fix sys_mmap_metal() for non-MAP_FIXED case (#651)
  • Show "screen of death" on VGA console upon program crash (#650)
  • Add basic character output for VGA graphics mode console (#649

Other changes:

  • Add imaxdiv, wcscoll, getdtablesize (#639)
  • Fix wcsdup malloc size (#641)
  • Add utime to utime.h (#648)

pledge-1.8

1 year ago

pledge.com is a tool for sandboxing CLI commands on Linux that doesn't require root privileges. It's based on the Cosmopolitan Libc polyfills for the OpenBSD pledge() and unveil() functions which we've implemented using SECCOMP BPF and Landlock LSM.

  • Fix thread killing semantics #628
  • Fix interop with Go DNS #627

redbean-2.1

1 year ago

redbean is an open source webserver in a zip executable that runs on six operating systems. The basic idea is if you want to build a web app that runs anywhere, then you download the redbean.com file, put your .html and .lua files inside it using the zip command, and then you've got a hermetic app you can deploy and share.

  • New unix.mapshared() api that lets you allocate memory that's shared between processes. It returns a module that has atomics and futexes. A demo script has been added that shows how it can be used to serialize a JSON GetPath() hit counter to shared memory.
  • This release fixes a bug with the parsing of space / plus parameters in the Request-URI.
  • Proof of concept of sqlite serialization (#436)
  • Lua's os.execute() function will now use Cosmopolitan's builtin cocmd interpreter, which provides a subset of bourne shell features, with faster performance, and consistent behavior across unixes and windows.
  • Fix re.NOSUB memory error (#645)
  • Update redbean api definitions (#652)
  • Make HTTP message parsing a little faster
  • Permit multiple certs with same common name

This is the first redbean release announcement that's been shared on GitHub. It only reflects the changes to redbean since 2.0.19. The web page for the 2.0.x release series is at https://redbean.dev/2.0.html which has links at the bottom to pages detailing older releases. For details on features and bug fixes that were introduced during the series over the past several months, please see the cosmo commit log.

2.1

1 year ago

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) 3fdb1c14f1e245d9ea16d72ce0d247d1cba3659a
  • 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 6cc9e08f1b6355381182dd9ff6261b27527c6072
  • Add lchown(), lchmod(), statvfs(), fstatvfs() 5a632cf72d5c6116a5c62ae0b9730476900b4df7
  • Add sigpending() a849a6377130a4ab63ae994f05a833637b7d0082
  • Add getgroups() and setgroups() 4c40c500b82be387a33ad5c65f084198211507f5
  • Implement inet_pton for AF_INET6 d213a481906ce7edf485009ebb486735caada9ed
  • The _gc() garbage collector is now thread safe 0e2b1bfeed2654fa425a70f7d88e5d1306611a6d
  • Use OpenBSD qsort() which is faster (quicksort) and secure (heapsort fallback) d861d2787b0decc5776db8922a68da960db16bc9
  • Add notpossible keyword and _npassert() 0c70e8963db77e4db2ee7de2da3139fa4b558171
  • IPv6 is now polyfilled on non-Linux 0547eabcd6b32cfe0335924e91ca8436fe66d3cc
  • Introduce MODE=fastbuild and shorthand notation m=fastbuild

Bug Fixes

  • Upgrade to the latest Chromium Zlib. This improves security and performance 224c12f54d58abdcc73cec60ec761814fcc219f3 775944a2d03f3f24357e90394a2bc4df0103bcff
  • Fix out of bounds read in IP address parser 775944a2d03f3f24357e90394a2bc4df0103bcff
  • APE binaries now work better with BusyBox 0305194d9854556e2bbef1fdcfda6e76910b1baf
  • Numerous fixes to bare metal support 3733b43a8fa011331fcb733680d0783dc1321384 8569704c1ddcff3403502d84ca66d65b5f22c347 e0fabd1d497fb3ffcbdb674667812aaf26d84261
  • Fix bug where SIG_IGN and SIG_DFL weren't working as advertised on BSDs c5c4dfcd218d834b94d4a73ab952f65c1a8b93d4
  • Improve quality of raise(), abort(), and tkill() c5c4dfcd218d834b94d4a73ab952f65c1a8b93d4
  • Improve quality of uname(), gethostname(), and getdomainname() b66bd064d8b026696fe1523d699724c0fe7f35fb
  • Improve quality of clock() 12d9e1e12859398c1698fcf073aa0d3c67f31a0c
  • Improve quality of copy_file_range(), sendfile(), splice(), openpty(), closefrom(), close_range(), fadvise() and posix_fadvise() c7a8cd21e90ab84be4caf5bd865ec90f17bd7017 9fa672506738cd210cb819e3fd05d2dd7d3f2997
  • Fix _Thread_local with fork() on Windows bf757c46469a5361fb00c6c3483858242087251f
  • Improve zipos path handling 1ef955c33b3092e62d5d05855b13c1fe6204006a
  • Fix preadv() and pwritev() for old distros 3f4988984183dae5bf8a39b9fcbb8cdf78ce10c7
  • Support fcntl(F_DUPFD_CLOEXEC) on more systems 3f4988984183dae5bf8a39b9fcbb8cdf78ce10c7
  • Fix POSIX advisory locks on Windows 3f4988984183dae5bf8a39b9fcbb8cdf78ce10c7
  • Fix race condition in makedirs() 571c2c3c698f31426c5ef5614745ba11e70e0783
  • Fix pledge() thread kill semantics 1ea01fc9055fae058ce1589593fb8bfbeacb5418
  • Improve open source compatibility b73e35c6fac2960b3a5fb082a712145318e2218b dbf12c30b05e8bffaa73356c229391538fd0b322 55c6297e13b49387708208d86cd0fc5d23e01678
  • Make SIG_DFL and SIG_IGN C++ compatible 8cd4248f7f74e2ea91a8ea22c6d685d5b13a0fcb
  • Discard ignored signals on New Technology 7de2f229a7e9f19074342010d57155d4fa4cc451
  • Fix inability to add some signals to mask on NT 598640864aadfe3bad418bceb9ae2fef3a0c825b
  • Fix issue with ZipOS file descriptors in MODE=asan 3265324e00634e8e9d659ba705da5b0ce88e78ef
  • The virtual memory layout is now more optimized b69f3d2488dbaf9dcc541e699f5b7c09fbf046e0
  • Repository is now buildable by GCC11

Breaking changes

  • Underscore added to many non-standard APIs to improve open source compatibility 6f7d0cb1c3962f7cb474b04de75df7cd82a3e5d3
  • Windows 7 and Vista support has now been moved to our vista branch 134ffee51900a4d70e8e68b598374856ceec8355
  • Add sys_ prefix to unwrapped system calls to improve open source compatibility aab4ee407299c5282b71a175045aa5c526ed6852
  • 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 1ad2f530f9c6197dfca199fc67a2296bbaac856e
  • 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

2.0.1

1 year ago

2.0

1 year ago

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.0.tar.gz
tar xf cosmopolitan-2.0.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.0.zip
unzip cosmopolitan-amalgamation-2.0.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 -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

Breaking Changes

  • You have to use /zip/... rather than zip:... when open()'ing assets stored in the PKZIP structure of your executable program. 00611e9b06be11e8af3a05c5d60878377aa2b0bd
  • You should use /c/... paths on Windows rather than C:/.... Your arguments and environment variables will be patched conservatively by the runtime to normalize $PATH and make life easy. It's still possible to use DOS, WIN32, NT, and other Microsoft-style paths with our APIs.
  • The default stack size has been reduced to 128kb. To learn how to increase this limit, or log your stack usage, please see 226aaf354786505e05283adfd52b43b668807336
  • We renamed LOGF to INFOF in the logging API. 0584684a8202dbdfc2861a32bee3e73d0161a537
  • We no longer define intmax_t as 128-bit. We now violate the standard like everyone else, by defining it as 64-bit. We've introduced a new %jjd formatting directive for int128_t. Functions like bsrmax() are now called bsr128(). 868af3f950c562baa1a73539703c6c78d51adceb
  • We've renamed nothrow to dontthrow and nodiscard is now dontdiscard. 868af3f950c562baa1a73539703c6c78d51adceb
  • Remove undocumented and ANSI WIN32 APIs in d3b599a79 and a157940ba61049420094a78829a062d57e78a44d

Features

  • We now favor the new APE loader (see ape-no-modify-self.o). It's extracted automatically. It's fast. It maps your programs into memory without copying or self-modifying the header. An --assimilate flag is baked-in to the shell script at the tops of your binaries, so you can convert them to the platform-local format whenever you want. If you're using binfmt_misc then a separate assimilate program is provided for doing just that. We also still distribute the classic ape.o bootloader. 47a53e143b9baf1e25b7001dd377986f8fac2989
  • Binfmt_misc support for Linux users. This is the fastest way to run APE programs. You can install it by running the ape/apeinstall.sh program in this repository.
  • We've polyfilled the OpenBSD pledge() and unveil() system calls for Linux. You can now use these APIs in your C/C++/Python/Redbean programs, or you can use the new pledge.com command to sandbox your existing Linux userspace.
  • We now use Landlock Make to build the repository, since it offers sandboxing and hermeticity guarantees. Our project will still build fine using vanilla GNU Make, since Landlock Make is backwards compatible.
  • We now offer support for threading that works on all six supported operating systems. Use the _spawn() and _join() functions. We're working on POSIX Threads support and recommend using our new pthread_mutex_lock implementation. For examples of multi-threaded programs, see examples/greenbean.c and tool/build/mkdeps.c.
  • You can now use the _Thread_local keyword. Your C runtime will now always initialize Thread-Local Storage (TLS) for your main process thread. Doing that means the minimum APE binary size had to be increased from 12kb to 16kb. We prefer using the %fs register. You must use the -mno-tls-direct-seg-refs flag. On Windows and Apple platforms, your executable will rewritten in memory at initialization to turn %fs opcodes into %gs. If you wish to control your segment registers, then you may do so by setting __tls_enabled to false and calling arch_prctl. Please note if you use threads, this will make errno no longer thread safe.
  • We now uniquely polyfill mmap(MAP_STACK) which brings the FreeBSD behavior to Linux. You must use it if you want your code to run on OpenBSD. Please see the mmap() documentation to learn more.
  • The Cosmopolitan monolithic repository now offers the LLVM LIBCXX Standard Template Library for C++ developers. This is not currently available in the amalgamation.
  • Your Cosmopolitan binaries now include an --ftrace flag which logs C function calls to standard error. Please read the Logging C Functions blog post which explains more. You need to use the -pg (and hopefully also -mnop-mcount) flag for this to work. If you don't want this functionality in your runtime, use MODE=tiny or MODE=rel.
  • Your Cosmopolitan binaries now include an --strace flag which logs system calls to standard error. This works consistently across platforms. It's especially helpful for ZIP-related system calls, which aren't handled by the kernel. Please read the Logging C Functions blog post which explains more. If you don't want this functionality in your runtime, use MODE=tiny or MODE=rel. 14e192e5ba820c60fa4aef48c1a646b151723603
  • You can now use Actually Portable Python by building o//third_party/python/python.com which includes an import cosmo module that lets you use our best features too.
  • New closefrom() system call for Linux 5.9+, FreeBSD 8+, and OpenBSD.
  • The clock_gettime and gettimeofday functions now go 10x faster on Linux via the vDSO.
  • Our ASAN module is now able to trace the origin of memory allocations when generating reports.
  • Complex math functions are now available, thanks to Musl Libc.
  • Many math functions, e.g. pow(), now go faster, thanks to ARM.
  • New nointernet() function which is similar in spirit to djb's disablenetwork() function.
  • New string appending library. See appendd, appendf, appendr, appends, appendw, appendz, kappendf, kvappendf, and vappendf. What makes this library good is it's (a) fast, and (b) strings made by these functions can be passed to free().
  • We now offer a bulletproof unbreakable kprintf() family of functions as part of the privileged runtime.
  • SSL performance is now significantly improved. See 398f0c16fbdcd356bdfc14111434b0f0f8de7de5 and f3e28aa192d433c379b86df00d760d87da25a487 and similar changes where we've added x86 optimizations for computing SHA faster, Intel ADX code that makes RSA multiplication faster, clean up code to make Everest curve25519 faster, and wrote an assembly implementation of NIST curve quasi-reduction.

Bug Fixes

  • Fork on Windows now works reliably 0cb6b6ff4b34a3503cd899ccbb12538a58d73b49 98909b13913c80e9c61035d1fe371f4a6bed9edb e5314dedde3553973a3e8692ffec7a65a6be6d20
  • Memory maps on Windows now work reliably
  • Signals on Windows now works well enough for Redbean to offer a web server with a repl 072e1d29109f835a592a7e4edf53898fcea7ae88
  • Fix %c with nul character 3c285337a
  • There's been a lot of fixes and fine tuning to the system call support magnums in consts.sh and syscalls.sh
  • Many system call polyfills have been improved, e.g. sysinfo, statfs, pselect, ppoll, sleep, sched_yield, utimensat, setsockopt, clock_gettime, sigsuspend, etc.
  • We now polyfill ENOENT vs. ENOTDIR on Windows
  • Daemonization now works on Windows

1.0

3 years ago

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 or UEFI with the best possible performance and the tiniest footprint imaginable.

Changes

  • Productionize redbean web server bf03b2e6 af59806a 01e6b3ad e56a9d0e 690be544 472b95fe c029e83d
  • Make it possible for APE binaries to modify their own ZIP contents bf03b2e6 daa32d27 b9187061 690be544
  • Introduce OpenExecutable for restoring APE bf03b2e64c1f38f2e20cbd0126dc858d31f9ead4 or alternatively ape-no-modify-self.o da8a08fd58324a87f6ac673b7774512e861fe477
  • Add Fabrice Bellard's JavaScript engine to third party 8f52c0d7 and get it to pass test262 8a915186
  • System calls now return EFAULT in ASAN mode if memory is invalid 690be544da77eb3323858df6562543db2978243d
  • Add SQLite to third party (thanks @ahgamut) #162 221817e5
  • Add sendmsg and recvmsg (thanks @fabriziobertocci) #148
  • Added LaunchBrowser API to redbean (thanks @Rotario) #153
  • Wide character classification now supports UNICODE 1b5a5719
  • Add syslog (thanks @fabriziobertocci) #136
  • Add strxfrm (thanks @ahgamut) #160
  • Add struct ip_mreq (thanks @fabriziobertocci) #143
  • Add MacOS toolchain instructions (thanks @d4tocchini) #163
  • Add 14 missing system call prototypes (thanks @dosisod) #142
  • Improve consts.sh magnums bf03b2e6 b107d2709f15341fb49940bb5ea06126d15749a1 1b5a5719c39b72089e3ba216b49e51a6ddae98ee 690be544da77eb3323858df6562543db2978243d
    • Polyfill POSIX Advisory Locks 690be544
    • Add polyfills for SO_LINGER, SO_RCVTIMEO, and SO_SNDTIMEO 48645651983ca46a31b3e85fb7b7e61500759f52
    • Polyfill TCP_CORK on BSD and XNU using TCP_NOPUSH magnums b107d2709f15341fb49940bb5ea06126d15749a1
  • Fix stdio in cases where it overflows kernel tty buffer b107d2709f15341fb49940bb5ea06126d15749a1
  • Improve backwards compatibility with GNU Make 1f2288be
  • Fix GDB attach on crash w/ OpenBSD msyscall() bf03b2e64c1f38f2e20cbd0126dc858d31f9ead4
  • Remove undefined behaviors b3838173
  • Add TUI paneling example 26ac6871
  • Add netcat clone b107d2709f15341fb49940bb5ea06126d15749a1 48645651983ca46a31b3e85fb7b7e61500759f52
  • Improve rusage accounting apis bf03b2e64c1f38f2e20cbd0126dc858d31f9ead4

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-1.0.zip
unzip cosmopolitan-amalgamation-1.0.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 patches)

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 MacOS you can install the GNU compiler collection for x86_64-elf via homebrew:

brew install x86_64-elf-gcc

Then in the above scripts just replace gcc and objcopy with x86_64-elf-gcc and x86_64-elf-objcopy to compile your APE binary.

If you're developing on Windows 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-1.0.tar.gz
tar xf cosmopolitan-1.0.tar.gz  # see releases page
cd cosmopolitan
make -j8  # should take ~30 seconds
o//examples/hello.com
o/third_party/lua/lua.com -e 'print(2 + 2)'
o/third_party/quickjs/qjs.com -e 'console.log(2+2)'
echo select 2 + 2 | o/third_party/sqlite3/sqlite3.com
printf 'GET /404.html\n\n' | o//examples/nc.com redbean.justine.lol 80
o//tool/viz/life.com

Contributing

We have automated Travis CI testing. Any pull request you send is going to get feedback in 2 minutes and 16 seconds. That's how long Travis CI takes to test this whole repository, which builds 14,507 objects, 68 libraries, and 461 static executables, 289 of which are test executables which are run too. On a real PC, building and testing everything from scratch takes 34 seconds instead of two minutes. If the hostnames freebsd, openbsd, netbsd, rhel7, rhel5, xnu, win7, and win10 can be ssh'd into, then make test -j8 takes 15 additional seconds to deploy and run all 300 test executables on those operating systems too. See CONTRIBUTING.md for further details.

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
GNU Make 3.80 2010

0.3

3 years ago

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 09bcfa23 4d21cd31 dcbd2b86 a1677d60 3c19b6e3 1753b669
  • Major improvements to stdio da36e7e2 c3ed8d6c aad84161
  • Add socketpair thanks to @fabriziobertocci ca88ce50
  • Numerous bug fixes, thanks to @alisonatwork 9c817290 6cd10376 8a6ac6dd f5da4efc 813e11b9 5d334b9c
  • Add missing math functions, and fix isystem headers, thanks to @dosisod 8a236433 fb7b7c6e
  • Fix APE error if unable to modify self, thanks to @tomberek 0eaad9dd
  • UEFI support 537c2133
  • Support proper %g, %f, and %a float formatting f0641836
  • Add posix_spawn 5ce83b08
  • Make pow() conform to standard definition 8af91bcb 43b2475a

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

0.2

3 years ago
  • VSCode support #40
  • Your executables now run on NetBSD too b2cd58a3226627179f58807bd333fbe0606ff489 23ae9dfceb6f657862f00e674a8e4dc357a9d24d
  • You can now compile your programs on BSD using the amalgamated release binaries
  • You can now build Cosmopolitan from source using LLVM e75ffde09e2db6abea0c0658d1336ec5ec57c342
  • You can now tune the source build to cherry pick which operating systems you want to support at compile time. By default, all seven are supported. To change that, simply redefine make CPPFLAGS=-DSUPPORT_VECTOR=0xFF which is a bitset defined by libc/dce.h. For example, -DSUPPORT_VECTOR=1 will ask Cosmopolitan's Makefile to produce conventional ELF binaries that only run on Linux.
  • Numerous bug fixes

0.1.2

3 years ago
  • Increase Windows stack size 393a642c2292b328017fd7f527e7e2dd738b58ae
  • Implement getcwd() for XNU 95173645a1af617730d266566f473e2ec4f2e3e0
  • Support dirfd relative iops for Windows 417797d2181dd25a423c5e6811e7b2c486fb8aa3
  • Fix fork on Windows after chdir b8d26e24188dfa0616bc8e177749fd268fdc58bb