Building on non-FreeBSD hosts

Moved to handbook

The building process is now documented in the FreeBSD Handbook. https://docs.freebsd.org/en/books/handbook/cutting-edge/#building-on-non-freebsd-hosts

Until recently, FreeBSD could 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 is easier to use these CI systems. Furthermore, it allows developers who do not have a FreeBSD system at work to use that to work on FreeBSD.

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 not opting to use the in-tree LLVM. 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). The script also passes any additional command arguments, like -j X or targets, to bmake.

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 llvm installed via homebrew:

brew install llvm

Prerequisites on Linux

You will need a recent version of clang (ideally 10.0) and the libarchive + libbz2 headers (libarchive-dev and libbz2-dev packages)

Using the in-tree toolchain

Instead of installing clang via your system's package manager, you can pass --bootstrap-toolchain to tools/build/make.py to build the in-tree LLVM and use it for the cross-build. This more closely matches building natively on FreeBSD (where the in-tree LLVM is used unless it is the same version as the existing system build of the in-tree LLVM), but will be slower than using a pre-built LLVM for your OS.

History

Why crossbuilding from non-FreeBSD didn't work

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

Committed

AlexRichardson

D25979, D26193 and openzfs/zfs#10863

r364022 and r365901

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

Committed

D31057

31ba4ce8898f

Building without inheriting $PATH

Committed

AlexRichardson

D16815 and D16814

r340157

This avoids invoking binaries that are incompatible

Add compatibility headers for bootstrap phase

Committed

AlexRichardson

D16815 and D16814

r364757

Allows bootstrapping tools without making changing the source code to be portable

Add wrapper script to bootstrap bmake

Committed

AlexRichardson

D16767

r365949

Needed since macOS/Linux don't include bmake by default


CategoryHowTo

BuildingOnNonFreeBSD (last edited 2023-10-02T18:13:29+0000 by MateuszPiotrowski)