{"id":13423373,"url":"https://github.com/jart/cosmopolitan","last_synced_at":"2025-05-13T18:05:01.777Z","repository":{"id":37050368,"uuid":"272457606","full_name":"jart/cosmopolitan","owner":"jart","description":"build-once run-anywhere c library","archived":false,"fork":false,"pushed_at":"2025-04-25T22:47:51.000Z","size":306055,"stargazers_count":19304,"open_issues_count":173,"forks_count":681,"subscribers_count":173,"default_branch":"master","last_synced_at":"2025-05-06T17:13:48.483Z","etag":null,"topics":["bios","containers","darwin","efi","freebsd","libc","linux","netbsd","openbsd","polyglot","windows","zip"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["jart"]}},"created_at":"2020-06-15T14:16:13.000Z","updated_at":"2025-05-06T13:46:52.000Z","dependencies_parsed_at":"2023-10-14T14:04:20.868Z","dependency_job_id":"a638a1f4-f66a-47ae-ae68-c24d26ffe772","html_url":"https://github.com/jart/cosmopolitan","commit_stats":{"total_commits":2666,"total_committers":82,"mean_commits":32.51219512195122,"dds":0.2306826706676669,"last_synced_commit":"26c051c297b562a073ac2cfcb40f25da4f755644"},"previous_names":[],"tags_count":118,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jart%2Fcosmopolitan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jart%2Fcosmopolitan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jart%2Fcosmopolitan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jart%2Fcosmopolitan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jart","download_url":"https://codeload.github.com/jart/cosmopolitan/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254000824,"owners_count":21997441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bios","containers","darwin","efi","freebsd","libc","linux","netbsd","openbsd","polyglot","windows","zip"],"created_at":"2024-07-31T00:00:33.054Z","updated_at":"2025-05-13T18:04:56.750Z","avatar_url":"https://github.com/jart.png","language":"C","readme":"![Cosmopolitan Honeybadger](usr/share/img/honeybadger.png)\n\n[![build](https://github.com/jart/cosmopolitan/actions/workflows/build.yml/badge.svg)](https://github.com/jart/cosmopolitan/actions/workflows/build.yml)\n# Cosmopolitan\n\n[Cosmopolitan Libc](https://justine.lol/cosmopolitan/index.html) makes C\na build-once run-anywhere language, like Java, except it doesn't need an\ninterpreter or virtual machine. Instead, it reconfigures stock GCC and\nClang to output a POSIX-approved polyglot format that runs natively on\nLinux + Mac + Windows + FreeBSD + OpenBSD 7.3 + NetBSD + BIOS with the\nbest possible performance and the tiniest footprint imaginable.\n\n## Background\n\nFor an introduction to this project, please read the [actually portable\nexecutable](https://justine.lol/ape.html) blog post and [cosmopolitan\nlibc](https://justine.lol/cosmopolitan/index.html) website. We also have\n[API\ndocumentation](https://justine.lol/cosmopolitan/documentation.html).\n\n## Getting Started\n\nYou can start by obtaining a release of our `cosmocc` compiler from\n\u003chttps://cosmo.zip/pub/cosmocc/\u003e.\n\n```sh\nmkdir -p cosmocc\ncd cosmocc\nwget https://cosmo.zip/pub/cosmocc/cosmocc.zip\nunzip cosmocc.zip\n```\n\nHere's an example program we can write:\n\n```c\n// hello.c\n#include \u003cstdio.h\u003e\n\nint main() {\n  printf(\"hello world\\n\");\n}\n```\n\nIt can be compiled as follows:\n\n```sh\ncosmocc -o hello hello.c\n./hello\n```\n\nThe Cosmopolitan Libc runtime links some heavyweight troubleshooting\nfeatures by default, which are very useful for developers and admins.\nHere's how you can log system calls:\n\n```sh\n./hello --strace\n```\n\nHere's how you can get a much more verbose log of function calls:\n\n```sh\n./hello --ftrace\n```\n\nYou can use the Cosmopolitan's toolchain to build conventional open\nsource projects which use autotools. This strategy normally works:\n\n```sh\nexport CC=x86_64-unknown-cosmo-cc\nexport CXX=x86_64-unknown-cosmo-c++\n./configure --prefix=/opt/cosmos/x86_64\nmake -j\nmake install\n```\n\n## Cosmopolitan Source Builds\n\nCosmopolitan can be compiled from source on any of our supported\nplatforms. The Makefile will download cosmocc automatically.\n\nIt's recommended that you install a systemwide APE Loader. This command\nrequires `sudo` access to copy the `ape` command to a system folder and\nregister with binfmt_misc on Linux, for even more performance.\n\n```sh\nape/apeinstall.sh\n```\n\nYou can now build the mono repo with any modern version of GNU Make. To\nbootstrap your build, you can install Cosmopolitan Make from this site:\n\nhttps://cosmo.zip/pub/cosmos/bin/make\n\nE.g.:\n\n```sh\ncurl -LO https://cosmo.zip/pub/cosmos/bin/make\n./make -j8\no//examples/hello\n```\n\nAfter you've built the repo once, you can also use the make from your\ncosmocc at `.cosmocc/current/bin/make`. You might even prefer to alias\nmake to `$COSMO/.cosmocc/current/bin/make`.\n\nSince the Cosmopolitan repository is very large, you might only want to\nbuild one particular thing. Here's an example of a target that can be\ncompiled relatively quickly, which is a simple POSIX test that only\ndepends on core LIBC packages.\n\n```sh\nrm -rf o//libc o//test\n.cosmocc/current/bin/make o//test/posix/signal_test\no//test/posix/signal_test\n```\n\nSometimes it's desirable to build a subset of targets, without having to\nlist out each individual one. For example if you wanted to build and run\nall the unit tests in the `TEST_POSIX` package, you could say:\n\n```sh\n.cosmocc/current/bin/make o//test/posix\n```\n\nCosmopolitan provides a variety of build modes. For example, if you want\nreally tiny binaries (as small as 12kb in size) then you'd say:\n\n```sh\n.cosmocc/current/bin/make m=tiny\n```\n\nYou can furthermore cut out the bloat of other operating systems, and\nhave Cosmopolitan become much more similar to Musl Libc.\n\n```sh\n.cosmocc/current/bin/make m=tinylinux\n```\n\nFor further details, see [//build/config.mk](build/config.mk).\n\n## Debugging\n\nTo print a log of system calls to stderr:\n\n```sh\ncosmocc -o hello hello.c\n./hello --strace\n```\n\nTo print a log of function calls to stderr:\n\n```sh\ncosmocc -o hello hello.c\n./hello --ftrace\n```\n\nBoth strace and ftrace use the unbreakable kprintf() facility, which is\nable to be sent to a file by setting an environment variable.\n\n```sh\nexport KPRINTF_LOG=log\n./hello --strace\n```\n\n## GDB\n\nHere's the recommended `~/.gdbinit` config:\n\n```gdb\nset host-charset UTF-8\nset target-charset UTF-8\nset target-wide-charset UTF-8\nset osabi none\nset complaints 0\nset confirm off\nset history save on\nset history filename ~/.gdb_history\ndefine asm\n  layout asm\n  layout reg\nend\ndefine src\n  layout src\n  layout reg\nend\nsrc\n```\n\nYou normally run the `.dbg` file under gdb. If you need to debug the\n`` file itself, then you can load the debug symbols independently as\n\n```sh\ngdb foo -ex 'add-symbol-file foo.dbg 0x401000'\n```\n\n## Platform Notes\n\n### Shells\n\nIf you use zsh and have trouble running APE programs try `sh -c ./prog`\nor simply upgrade to zsh 5.9+ (since we patched it two years ago). The\nsame is the case for Python `subprocess`, old versions of fish, etc.\n\n### Linux\n\nSome Linux systems are configured to launch MZ executables under WINE.\nOther distros configure their stock installs so that APE programs will\nprint \"run-detectors: unable to find an interpreter\". For example:\n\n```sh\njart@ubuntu:~$ wget https://cosmo.zip/pub/cosmos/bin/dash\njart@ubuntu:~$ chmod +x dash\njart@ubuntu:~$ ./dash\nrun-detectors: unable to find an interpreter for ./dash\n```\n\nYou can fix that by registering APE with `binfmt_misc`:\n\n```sh\nsudo wget -O /usr/bin/ape https://cosmo.zip/pub/cosmos/bin/ape-$(uname -m).elf\nsudo chmod +x /usr/bin/ape\nsudo sh -c \"echo ':APE:M::MZqFpD::/usr/bin/ape:' \u003e/proc/sys/fs/binfmt_misc/register\"\nsudo sh -c \"echo ':APE-jart:M::jartsr::/usr/bin/ape:' \u003e/proc/sys/fs/binfmt_misc/register\"\n```\n\nYou should be good now. APE will not only work, it'll launch executables\n400µs faster now too. However if things still didn't work out, it's also\npossible to disable `binfmt_misc` as follows:\n\n```sh\nsudo sh -c 'echo -1 \u003e /proc/sys/fs/binfmt_misc/cli'     # remove Ubuntu's MZ interpreter\nsudo sh -c 'echo -1 \u003e /proc/sys/fs/binfmt_misc/status'  # remove ALL binfmt_misc entries\n```\n\n### WSL\n\nIt's normally unsafe to use APE in a WSL environment, because it tries\nto run MZ executables as WIN32 binaries within the WSL environment. In\norder to make it safe to use Cosmopolitan software on WSL, run this:\n\n```sh\nsudo sh -c \"echo -1 \u003e /proc/sys/fs/binfmt_misc/WSLInterop\"\n```\n\n## Discord Chatroom\n\nThe Cosmopolitan development team collaborates on the Redbean Discord\nserver. You're welcome to join us! \u003chttps://discord.gg/FwAVVu7eJ4\u003e\n\n## Support Vector\n\n| Platform       | Min Version    | Circa |\n| :---           | ---:           | ---:  |\n| AMD            | K8             | 2003  |\n| Intel          | Core           | 2006  |\n| Linux          | 2.6.18         | 2007  |\n| Windows        | 8 [1]          | 2012  |\n| Darwin (macOS) | 23.1.0+        | 2023  |\n| OpenBSD        | 7.3 or earlier | 2023  |\n| FreeBSD        | 13             | 2020  |\n| NetBSD         | 9.2            | 2021  |\n\n[1] See our [vista branch](https://github.com/jart/cosmopolitan/tree/vista)\n    for a community supported version of Cosmopolitan that works on Windows\n    Vista and Windows 7.\n\n## Special Thanks\n\nFunding for this project is crowdsourced using\n[GitHub Sponsors](https://github.com/sponsors/jart) and\n[Patreon](https://www.patreon.com/jart). Your support is what makes this\nproject possible. Thank you! We'd also like to give special thanks to\nthe following groups and individuals:\n\n- [Joe Drumgoole](https://github.com/jdrumgoole)\n- [Rob Figueiredo](https://github.com/robfig)\n- [Wasmer](https://wasmer.io/)\n\nFor publicly sponsoring our work at the highest tier.\n","funding_links":["https://github.com/sponsors/jart","https://www.patreon.com/jart"],"categories":["C","HarmonyOS","Libraries","Embed-Script/VM/","Utilities","windows","公用事业","C/C++ 程序设计","Cosmopolitan"],"sub_categories":["Windows Manager","C","Lua","YAML","网络服务_其他","Ports"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjart%2Fcosmopolitan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjart%2Fcosmopolitan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjart%2Fcosmopolitan/lists"}