{"id":13751538,"url":"https://github.com/rsms/llvmbox","last_synced_at":"2025-04-09T07:10:32.866Z","repository":{"id":65642260,"uuid":"588783290","full_name":"rsms/llvmbox","owner":"rsms","description":"Self contained, fully static llvm tools \u0026 libs","archived":false,"fork":false,"pushed_at":"2023-03-01T00:20:05.000Z","size":105593,"stargazers_count":350,"open_issues_count":4,"forks_count":4,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-02T05:09:05.447Z","etag":null,"topics":["clang","llvm"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rsms.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","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}},"created_at":"2023-01-14T01:49:31.000Z","updated_at":"2025-03-30T00:50:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"6063978a-a0f5-447b-b96c-eadf1ec22f27","html_url":"https://github.com/rsms/llvmbox","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsms%2Fllvmbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsms%2Fllvmbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsms%2Fllvmbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsms%2Fllvmbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rsms","download_url":"https://codeload.github.com/rsms/llvmbox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994122,"owners_count":21030050,"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":["clang","llvm"],"created_at":"2024-08-03T09:00:47.836Z","updated_at":"2025-04-09T07:10:27.857Z","avatar_url":"https://github.com/rsms.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"llvmbox is a highly \"portable\" distribution of the LLVM tools and development libraries, without external dependencies.\n\nSimply unpack the tar file and you have a fully-functional compiler toolchain that is fully self-contained (on Linux, it does not need libc or even a dynamic linker to be present on the target system.)\n\nFeatures:\n\n- Self-contained; install with wget/curl\n- Runs on any Linux system (\"Linux-distro less\" — there's no \"gnu\", \"musl\" or \"ulibc\" variants; all it needs is linux syscall)\n- Contains its own sysroot\n  - Does not need libc nor libc++ headers to be installed on your system\n  - On Linux, does not need linux headers to be installed on your system\n  - On macOS, does not need Xcode or Command Line Developer Tools\n- LLVM development libraries in separate installable archive\n  - Separate distribution reduces file size for when you just need the toolchain.\n  - Includes ThinLTO libraries in lib-lto in addition to precompiled target code libraries, enabling you to build 100% LTOd products. This includes libc and libc++, not just LLVM libs.\n  - Includes libraries for building your own custom clang and lld tools\n  - Includes a development time-optimized library `liball_llvm_clang_lld.a` which contains all llvm libs, clang libs, lld libs and dependencies. It allows building your own clang or lld with link speeds in the 100s of milliseconds.\n\nSupported systems:\n\n  - Linux: x86_64, aarch64\n  - macOS: x86_64, aarch64/arm64 (macOS 10.15 and up with x86_64, 11.0 and up with arm64)\n\nHoping to support in the future: ([contributions welcome!](CONTRIBUTING.md))\n\n  - Windows\n  - FreeBSD\n\nCurrently the toolchain is not cross-compilation capable but that is something I'd like to enable in the future by including sysroots and sources, compiling them as needed for requested targets.\n\n\n## Usage\n\nFind the URL for [the release suitable for your system in (latest release)](https://github.com/rsms/llvmbox/releases/latest), then\n\n```sh\n# download \u0026 install in current directory\nwget -qO- https://github.com/rsms/llvmbox/.../llvmbox-VERSION.tar.xz | tar xJ\n\n# create example C++ source\ncat \u003c\u003c EXAMPLE \u003e hello.cc\n#include \u003ciostream\u003e\nint main(int argc, const char** argv) {\n  std::cout \u003c\u003c \"hello from \" \u003c\u003c argv[0] \u003c\u003c \"\\n\";\n  return 0;\n}\nEXAMPLE\n\n# compile\n[ $(uname -s) = Linux ] \u0026\u0026 LDFLAGS=-static\n./llvmbox-VERSION/bin/clang++ $LDFLAGS hello.cc -o hello\n\n# run example\n./hello\n```\n\n\n## Using LLVM libraries\n\nLLVM libraries are distributed in a separate archive \"llvmbox-dev.\" Its directory tree can either be merged into the toolchain (\"llvmbox\") tree, or placed anywhere, given appropriate compiler and linker flags are used.\n\n```sh\n# download \u0026 install in current directory\nwget -qO- https://github.com/rsms/llvmbox/.../llvmbox-dev-VERSION.tar.xz | tar xJ\n\n# fetch example program\nwget https://github.com/rsms/llvmbox/blob/954ee63a9c82c4f2dca2dd319496f1cfa5d7d06d/test/hello-llvm.c\n\n# compile\n./llvmbox-VERSION/bin/clang $CFLAGS \\\n  $(./llvmbox-dev-VERSION/bin/llvm-config --cflags) \\\n  -c hello-llvm.c -o hello-llvm.o\n\n# link\nLDFLAGS=\"$LDFLAGS -Lllvmbox-dev-VERSION/lib\"\n[ $(uname -s) = Linux ] \u0026\u0026 LDFLAGS=\"$LDFLAGS -static\"\n./llvmbox-VERSION/bin/clang++ $LDFLAGS \\\n  $(./llvmbox-dev-VERSION/bin/llvm-config --ldflags --system-libs --libs core native) \\\n  hello-llvm.o -o hello-llvm\n\n# run example\n./hello-llvm\n```\n\n\nIf you are interested in building your own C/C++ compiler based on clang \u0026 lld, have a look at the [`myclang`](myclang/) example.\n\nTo merge the two distributions toghether, use `tar --strip-components` and extract the \"dev\" package after extracting the base package:\n\n```sh\nmkdir llvmbox\ncd llvmbox\ntar --strip-components 1 -xf ../llvmbox-15.0.7+1-x86_64-linux.tar.xz\ntar --strip-components 1 -xf ../llvmbox-dev-15.0.7+1-x86_64-linux.tar.xz\n```\n\n\n### Building with LTO libs\n\n[ThinLTO](https://clang.llvm.org/docs/ThinLTO.html) performs whole-program optimization during the linker stage. This can in some cases greatly improve performance and often leads to slightly smaller binaries. The cost is longer link times. llvmbox ships with both regular machine code libraries as well as ThinLTO libraries. During development you can link with regular libraries with millisecond-fast link times and for production builds you can link with LTO for improved runtime performance.\n\nContinuing off of our \"hello-llvm\" example above, let's change compiler and linker flags. `-flto=thin` enables creation of LTO objects. We need to set library search path to the location of the LTO libraries: `lib-lto`. (The `lib` directory of llvmbox contains \"regular\" libraries with machine code.)\n\n```sh\nCFLAGS=\"$CFLAGS -flto=thin\"\nLDFLAGS=\"$LDFLAGS -Lllvmbox-dev-VERSION/lib-lto\"\n\n./llvmbox-VERSION/bin/clang \\\n  $(./llvmbox-dev-VERSION/bin/llvm-config --cflags) \\\n  -flto=thin \\\n  -c hello-llvm.c -o hello-llvm.o\n\n./llvmbox-VERSION/bin/clang++ $LDFLAGS \\\n  $(./llvmbox-dev-VERSION/bin/llvm-config --system-libs --libs core native) \\\n  hello-llvm.o -o hello-llvm\n```\n\nTurn on ThinLTO cache to enable fast incremental compilation:\n\n```sh\nmkdir -p lto-cache\ncase \"$(uname -s)\" in\n  Linux)  LDFLAGS=\"$LDFLAGS -Wl,--thinlto-cache-dir=$PWD/lto-cache\" ;;\n  Darwin) LDFLAGS=\"$LDFLAGS -Wl,-cache_path_lto,$PWD/lto-cache\" ;;\nesac\n```\n\nNow, recompiling after making a small change to a source file is much faster.\n\n### LLVM targets\n\nSupport for the following target architectures are included in the LLVM libraries:\n(from `clang --print-targets`)\n\n- aarch64    - AArch64 (little endian)\n- aarch64_32 - AArch64 (little endian ILP32)\n- aarch64_be - AArch64 (big endian)\n- arm        - ARM\n- arm64      - ARM64 (little endian)\n- arm64_32   - ARM64 (little endian ILP32)\n- armeb      - ARM (big endian)\n- riscv32    - 32-bit RISC-V\n- riscv64    - 64-bit RISC-V\n- thumb      - Thumb\n- thumbeb    - Thumb (big endian)\n- wasm32     - WebAssembly 32-bit\n- wasm64     - WebAssembly 64-bit\n- x86        - 32-bit X86: Pentium-Pro and above\n- x86-64     - 64-bit X86: EM64T and AMD64\n\n\n## Motivation\n\nllvmbox is both a necessity for some of my personal projects, like hobby OSes without anything but Linux syscalls, but also a reaction to the brutal complexity of contemporary software culture. Entangled messes of shared libraries and dynamic linkers, all with various version constraints makes it harder to develop software than it needs to be. By \"collapsing the stack\" we can isolate the complexities of certain inherently-complex systems, like llvm.\n\nI also enjoy making hobby languages and compilers. Some of them uses llvm as the \"backend\" and it is _always_ a huge hassle getting llvm building, causing directories full of patches and shell scripts to litter these hobby projects. For some projects, like [Compis](https://github.com/rsms/compis), I embed clang \u0026 lld ([Zig](https://ziglang.org/) also does this) to allow compiling C \u0026 C++, but this brings a big burden: now Compis needs to be linked with the exact C++ lib that the llvm which libs it links with was built with. It gets messier, but basically, it's too complex.\n\nThe [Zig project](https://ziglang.org/) is a great example of doing something about the complexity. They have put in a tremendous effort into building a C \u0026 C++ compatible compiler that is truly portable, which even has first-class \"cross compilation.\" Zig is an inspiration for this project and a breath of fresh air when it comes to software portability and simplicity.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsms%2Fllvmbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frsms%2Fllvmbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsms%2Fllvmbox/lists"}