1.0
版本发布时间: 2021-05-17 12:51:44
jart/cosmopolitan最新发布版本:3.8.0(2024-08-31 11:52:21)
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 alternativelyape-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 |
1、 cosmopolitan-1.0.tar.gz 36.33MB
2、 cosmopolitan-amalgamation-1.0.zip 5.55MB