This is an old revision of the document!
Building on non-FreeBSD hosts
Currently, FreeBSD can only be built on a FreeBSD host. However, most CI systems do not include FreeBSD build slaves by default. If we allow FreeBSD to be compiled on a non-FreeBSD host (current target is Linux and macOS) it would be much easier to use these CI systems. Furthermore, it would allow developers who do not have a FreeBSD system at work to use that to work on FreeBSD.
Why crossbuilding from non-FreeBSD doesn't work yet
- Some build tools depend on host headers being compatible with target headers (e.g. localedef). This would require some refactoring of the xlocale headers to fix properly.
- The version of clang contained in the FreeBSD source tree cannot be bootstrapped with the makefiles from base since the config headers depend on FreeBSD
- Could build the bootstrap clang using CMake+ninja (which should also be much faster than the current Makefile solution), but that will be a lot of effort
- Current solution is to use upstream clang
- However, some features such as ifunc-noplt are not in upstream clang
- The build system often falls back to invoking binaries in $PATH
- This can cause strange build errors if that binary was not bootstrapped and an incompatible versions is executed
- can also happen when building on FreeBSD (e.g. running dtc from an old FreeBSD version)
- Building with a clean $PATH D16815 fixes this problem since it requires all bootstrap tools to be listed explicitly
Current status
A mostly working prototype can be found at github.com/CTSRD-CHERI/cheribsd in the branch freebsd-crossbuild. This branch is regularly merged with HEAD.
Instructions for building on Linux/macOS
Since Linux and macOS don't include a version of bmake by default, building should be done using the script tools/build/make.py which will bootstrap bmake before attempting to build.
Additionally it will set the required XCC,XLD etc variables that are needed to build with an ExternalToolchain.
If you have a recent version of bmake installed using homebrew or another package manager you can also set the required variables manually (the easiest way to obtain them is by running tools/build/make.py --debug)
Usage:
MAKEOBJDIRPREFIX=... ./tools/build/make.py buildworld TARGET=foo TARGET_ARCH=bar ...
Prerequisites on macOS
tools/build/make.py should work out-of-the box on macOS with clang and libarchive installed via homebrew:
brew install clang libarchive
Prerequisites on Linux
You will need a recent version of clang (ideally 10.0) and the libarchive + libbz2 headers.
See tools/build/cross-build/docker/<distribution>/Dockerfile for the required packages for some distributions.
Building in a docker container
The GitHub repo also contains a script tools/build/cross-build/docker-make.py that will attempt to build inside a docker container.
It also contains dockerfiles with clang+other build tools preinstalled for
openSUSE,
Ubuntu,
Arch Linux.
MAKEOBJDIRPREFIX=... ./tools/build/cross-build/docker-make.py --local-docker-image <opensuse|ubuntu|arch> buildworld TARGET=foo TARGET_ARCH=bar ...
Open issues
| Name | STATUS | Owner | Review | Commits | Comments |
| MK_PMC broken | Committed | AlexRichardson | D17682 | r339880 | jevents doesn't emit output on macOS |
| MK_BSNMP broken | Committed | D21605 | r352220 | The makefiles for libsnmp use ls -D which is not supported on macOS+Linux | |
| MK_CDDL broken | Patch not uploaded yet | AlexRichardson | Some of the CDDL bootstrap tools don't compile yet | ||
| MK_BOOT broken | Committed | ? | ? | BOOT contains some assembly files that cannot be built with clang | |
| MK_TESTS broken | Committed | AlexRichardson | D24788 | rS360894 | at least one of the test makefiles uses dd status=none which is not supported on Linux/macOS |
| MK_LOCALES broken | Committed | AlexRichardson | D25229 | rS363218 | localedef requires the host xlocale headers to be compatible with the target. Would need to namespace those headers to avoid conflicting with the host |
| Clang+LLD cannot be built | Not started/Bad idea | This requires tablegen to be bootstrapped but won't work with the existing makefiles/config.h. Using an external toolchain is preferable | |||
| Building without inheriting $PATH | Committed | AlexRichardson | D16815 and D16814 | r340157 | This avoids invoking binaries that are incompatible |
| Add compatibility headers for bootstrap phase | Needs review | AlexRichardson | D16815 and D16814 | Allows bootstrapping tools without making changing the source code to be portable |