| Serge Bazanski | 9e861a8 | 2020-09-16 13:46:41 +0200 | [diff] [blame] | 1 | musl-host-gcc |
| 2 | ============= |
| 3 | |
| 4 | musl-host-gcc is a Bazel C++ toolchain that uses the machine's host gcc in combination with a pre-built musl, musl headers, and Linux headers. |
| 5 | |
| Serge Bazanski | 662b5b3 | 2020-12-21 13:49:00 +0100 | [diff] [blame] | 6 | It is currently used to build the few C binaries we need on Metropolis nodes. |
| Serge Bazanski | 9e861a8 | 2020-09-16 13:46:41 +0200 | [diff] [blame] | 7 | |
| 8 | At some point, this toolchain should be replaced by a fully hermetic toolchain that doesn't depend on the host environment. |
| 9 | |
| 10 | Usage |
| 11 | ----- |
| 12 | |
| 13 | To use this toolchain explicitely while building a `cc_binary`, do: |
| 14 | |
| 15 | bazel build --crosstool_top=//build/toolchain/musl-host-gcc:musl_host_cc_suite //foo/bar |
| 16 | |
| 17 | During an actual build however, the right toolchain should be selected using aspects or other Bazel configurability features, instead of a hardcoded `--crosstool_top`. |
| 18 | |
| 19 | Building Toolchain Sysroot Tarball |
| 20 | ---------------------------------- |
| 21 | |
| Serge Bazanski | 662b5b3 | 2020-12-21 13:49:00 +0100 | [diff] [blame] | 22 | The toolchain's musl/linux components are currently built ahead of time and committed to this repository as `//build/toolchain/musl-host-gcc/toolchain.tar.xz`. This is the 'sysroot' tarball, that contains all headers and libraries required to build for Metropolis nodes. |
| Serge Bazanski | 9e861a8 | 2020-09-16 13:46:41 +0200 | [diff] [blame] | 23 | |
| 24 | To build this tarball, run the following commands: |
| 25 | |
| 26 | bazel build //build/toolchain/musl-host-gcc/sysroot |
| 27 | cp -f bazel-bin/build/toolchain/musl-host-gcc/sysroot/sysroot.tar.xz build/toolchain/musl-host-gcc/sysroot.tar.xz |
| 28 | |
| Lorenz Brun | bb95ebd | 2021-03-16 15:06:51 +0100 | [diff] [blame^] | 29 | As a temporary hack the compiler-specific headers of our current development container have been manually merged in. This is expected to be replaced by a proper LLVM-based toolchain. |
| 30 | |
| Serge Bazanski | 9e861a8 | 2020-09-16 13:46:41 +0200 | [diff] [blame] | 31 | Internals |
| 32 | --------- |
| 33 | |
| 34 | The toolchain is implemented in the following way: |
| 35 | |
| Serge Bazanski | 662b5b3 | 2020-12-21 13:49:00 +0100 | [diff] [blame] | 36 | 1. `//build/toolchain/musl-host-gcc/sysroot` is used to build `//build/toolchain/musl-host-gcc/sysroot.tar.xz` which is a tarball that contains all include and binary library files for building against musl for Metropolis nodes (x86\_64 / k8) - thes are musl headers, musl libraries, and linux headers. This tarball is commited to source control. |
| Serge Bazanski | 9e861a8 | 2020-09-16 13:46:41 +0200 | [diff] [blame] | 37 | 1. When building a target that uses the toolchain, the `sysroot.tar.xz` tarball is extracted into an external repository `@musl_sysroot`, via `sysroot.bzl` and `sysroot_repository.bzl`. |
| 38 | 1. A toolchain config is built using `//build/toolchain:cc_toolchain_config.bzl`, which points at `gcc-wrapper.sh` as its gcc entrypoint. `gcc-wrapper.sh` expects to be able to call the host gcc with `musl.spec`. |
| 39 | 1. A toolchain is built in `//build/toolchain/musl-host-gcc:musl_host_cc_suite`, which uses the previously mentioned config, and builds it to contain `gcc-wrapper.sh`, `musl.spec`, and the sysroot tarball. |
| 40 | |
| 41 | Quirks |
| 42 | ------ |
| 43 | |
| 44 | As mentioned above, the musl sysroot is kept in a tarball in this repository. This is obviously suboptimal, but on the other hand gives us an effectively pre-built part of a toolchain. In the future, once we have a hermetic toolchain, a similar tarball might actually contain a fully hermetic toolchain pre-built for k8. |