{"id":17921561,"url":"https://github.com/theopolis/build-anywhere","last_synced_at":"2025-03-24T01:32:31.439Z","repository":{"id":56814515,"uuid":"161439364","full_name":"theopolis/build-anywhere","owner":"theopolis","description":"Scripts for building compilers that run anywhere, which build things that run anywhere","archived":false,"fork":false,"pushed_at":"2019-06-29T16:19:31.000Z","size":5937,"stargazers_count":90,"open_issues_count":4,"forks_count":10,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-19T02:38:36.202Z","etag":null,"topics":["compilers","linux-dev","portability","toolchains"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theopolis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-12T05:53:02.000Z","updated_at":"2025-01-25T02:52:56.000Z","dependencies_parsed_at":"2022-09-12T09:32:07.096Z","dependency_job_id":null,"html_url":"https://github.com/theopolis/build-anywhere","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopolis%2Fbuild-anywhere","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopolis%2Fbuild-anywhere/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopolis%2Fbuild-anywhere/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopolis%2Fbuild-anywhere/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theopolis","download_url":"https://codeload.github.com/theopolis/build-anywhere/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245194513,"owners_count":20575767,"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":["compilers","linux-dev","portability","toolchains"],"created_at":"2024-10-28T20:34:50.211Z","updated_at":"2025-03-24T01:32:29.622Z","avatar_url":"https://github.com/theopolis.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ./build-anywhere.sh /output/path\n\n[![Build Status](https://travis-ci.org/theopolis/build-anywhere.svg?branch=master)](https://travis-ci.org/theopolis/build-anywhere)\n\nThese scripts build a toolchain/runtime that runs on almost every Linux distribution. The compilers can produce libraries and executables that also run on almost every Linux distribution.\n\n\u003e anywhere (n). x86_64 Linux distributions that include a 2.13 (circa 2011+) or newer glibc.\n\nAt a very high level:\n\n- Use Crosstool-NG to build **gcc 8.3.0** linked against a **glibc 2.13**.\n- Build an older **zlib 1.2.11** to link against.\n- Build **Clang/LLVM 8.0.0** with the new GCC also linked against a **glibc 2.13**.\n- Kernel headers for **Linux 4.7** are included as they have certain bpf macros.\n- You can use the clang/gcc compiler anywhere.\n- You can use either clang or gcc's compiler runtime; recommend using linking flags to link these statically.\n- You can use either libstdc++ or libc++; recommended linking these statically.\n- You can use all of the LLVM static analysis and sanitizer frameworks.\n\nThis project builds the runtime. You can download pre-built runtimes on the [Releases](https://github.com/theopolis/build-anywhere/releases) page.\n\n## man build-anywhere.sh\n\n### build-from-source\n\n```\n$ ./build-anywhere.sh /opt/build\n```\n\nThis will create several output files/directories in `/opt/build`, at the end the important one is `x86_64-anywhere-linux-gnu`.\n\n```\n$ du -h --max-depth=2 /opt/build/x86_64-anywhere-linux-gnu\n44M   x86_64-anywhere-linux-gnu/bin\n4.0K  x86_64-anywhere-linux-gnu/include\n20K   x86_64-anywhere-linux-gnu/scripts\n54M   x86_64-anywhere-linux-gnu/libexec/gcc\n54M   x86_64-anywhere-linux-gnu/libexec\n4.0M  x86_64-anywhere-linux-gnu/x86_64-anywhere-linux-gnu/bin\n11M   x86_64-anywhere-linux-gnu/x86_64-anywhere-linux-gnu/include\n48K   x86_64-anywhere-linux-gnu/x86_64-anywhere-linux-gnu/lib64\n708M  x86_64-anywhere-linux-gnu/x86_64-anywhere-linux-gnu/sysroot\n4.0K  x86_64-anywhere-linux-gnu/x86_64-anywhere-linux-gnu/lib\n4.0K  x86_64-anywhere-linux-gnu/x86_64-anywhere-linux-gnu/debug-root\n718M  x86_64-anywhere-linux-gnu/x86_64-anywhere-linux-gnu\n1.5M  x86_64-anywhere-linux-gnu/lib/ldscripts\n9.8M  x86_64-anywhere-linux-gnu/lib/gcc\n12M   x86_64-anywhere-linux-gnu/lib\n1.5M  x86_64-anywhere-linux-gnu/share/licenses\n120K  x86_64-anywhere-linux-gnu/share/gcc-8.3.0\n1.7M  x86_64-anywhere-linux-gnu/share\n829M  x86_64-anywhere-linux-gnu\n```\n\n**Remember** you can build this once and run it from any directory on any x86_64 Linux created in 2011 or newer.\n\n### download-prebuilt\n\nYou can also download a prebuilt version, [`x86_64-anywhere-linux-gnu-VERSION.tar.gz`](https://github.com/theopolis/build-anywhere/releases), from the GitHub releases page.\n\nYou can untar this and run from any directory. See below for guidance on how to use the toolchain.\n\n## Using the anywhere toolchain\n\nSourcing the `./scripts/anywhere-setup.sh` script should set up your environment.\n\n```\nsource ./x86_64-anywhere-linux-gnu/scripts/anywhere-setup.sh\n```\n\nImportant variables:\n\n```\nSYSROOT=x86_64-anywhere-linux-gnu/x86_64-anywhere-linux-gnu/sysroot\nPATH=$PREFIX/bin:$PATH\nCXX=clang++\nCC=clang\n```\n\nThere are several optional variables you may want to include. If you intend to install into the build-anywhere toolchain, also set the following:\n\n```\nPREFIX=$SYSROOT/usr\nPKG_CONFIG_PATH=$PREFIX/lib/pkgconfig\nACLOCAL_PATH=$PREFIX/share/aclocal\n```\n\n## (Somewhat) security-enhanced toolchain\n\nSource the `./scripts/anywhere-setup-security.sh` script adds extra linker and compiler flags.\n\n```\nsource ./x86_64-anywhere-linux-gnu/scripts/anywhere-setup-security.sh\n```\n\n## Accuracy\n\nThere are some excessive linking options included.\n\n```\n-fuse-ld=lld -Wl,-z,relro,-z,now -pie -l:libc++.a -l:libc++abi.a -l:libunwind.a -lpthread -ldl -lrt -lz -lm\n```\n\nAnd the compiler flags attempt to make small binaries, with PIC, and without newer ASM.\n\n```\n-march=x86-64 -fPIC -Oz\n```\n\nThis is a best-effort solution that covers most bases. Every project's build system is different and may not respect the variable this toolchain sets. Most problems can be resolved by telling autotools, cmake, etc, system about the explicit linking and include paths.\n\nAs an example, SleuthKit will still find the system `libstdc++.so` and OpenSSL needs an explicit `--prefix=$PREFIX`.\n\nA more-accurate version forces the use of clang, clang's compiler runtime, and LLVM's `libc++`. This is more accurate because it is harder for build systems to work if they make assumptions (e.g., we did not read their documentation closely). So you either break it or it works, which is better. The side effect of this is about 100kB additional code from static linking compared to gcc's runtime and c++ implementation.\n\nYou can also remove the libc dynamic libraries to force anything trying to link them statically.\n- `$PREFIX/lib/libc++*.so*`\n- `$PREFIX/lib/libunwind*.so*`\n\nNow build systems have no choice.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopolis%2Fbuild-anywhere","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheopolis%2Fbuild-anywhere","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopolis%2Fbuild-anywhere/lists"}