Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
buildingonnonfreebsd [2021/10/11 01:21] – Remove an unnecessary ./ JessicaClarkebuildingonnonfreebsd [2023/10/02 18:13] (current) – redirect to handbook MateuszPiotrowski
Line 1: Line 1:
 ====== Building on non-FreeBSD hosts ====== ====== 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. +<callout type="info"> 
-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. +**Moved to handbook**
-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 didn't work =====+The building process is now documented in the %%FreeBSD%% Handbook. https://docs.freebsd.org/en/books/handbook/cutting-edge/#building-on-non-freebsd-hosts 
 +</callout>
  
-  * 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. +Until recently, %%FreeBSD%% could only be built on a %%FreeBSD%% host. However, most CI systems do not include %%FreeBSD%% build slaves by default. 
-  * 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%%  +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. 
-    * 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 +Furthermore, it allows developers who do not have a %%FreeBSD%% system at work to use that to work on %%FreeBSD%%.
-    * 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 [[https://reviews.freebsd.org/D16815|D16815]] fixes this problem since it requires all bootstrap tools to be listed explicitly +
- +
-===== Current status ===== +
- +
-As of September 2020 all required patches have been merged to HEAD.+
  
-==== Instructions for building on Linux/macOS ====+===== 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. 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]]. +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%%'')+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: Usage:
Line 33: Line 23:
 </code> </code>
  
-=== Prerequisites on macOS ===+==== Prerequisites on macOS ====
  
-''%%tools/build/make.py%%'' should work out-of-the box on macOS with clang and libarchive installed via homebrew:+''%%tools/build/make.py%%'' should work out-of-the box on macOS with llvm installed via homebrew:
  
 <code> <code>
-brew install clang libarchive+brew install llvm
 </code> </code>
  
-=== Prerequisites on Linux ===+==== Prerequisites on Linux ====
  
-You will need a recent version of clang (ideally 10.0) and the libarchive + libbz2 headers.+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 ===+==== 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. 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.
  
-===== Open issues =====+===== History ===== 
 + 
 +==== Why crossbuilding from non-FreeBSD didn't work ==== 
 + 
 +  * Some build tools depended on host headers being compatible with target headers (e.g. localedef). This required some refactoring of the xlocale headers to fix properly. 
 +  * The version of clang contained in the %%FreeBSD%% source tree could not be bootstrapped with the makefiles from base since the config headers depended on %%FreeBSD%% 
 +    * Could have built the in-tree clang using CMake+ninja (which should also be much faster than the current Makefile solution), but that would have been a lot of effort 
 +    * Initial solution was to just use upstream clang as an external toolchain until the config headers and build system were patched to support Linux and macOS 
 +      * 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 [[https://reviews.freebsd.org/D16815|D16815]] fixes this problem since it requires all bootstrap tools to be listed explicitly 
 + 
 +==== Issues ====
  
 | Name | STATUS | Owner | Review | Commits | Comments | | Name | STATUS | Owner | Review | Commits | Comments |
Line 65: Line 69:
 ---- ----
  
-{{tag>Project Project}}+{{tag>HowTo}}
  
  • buildingonnonfreebsd.1633915309.txt.gz
  • Last modified: 2021/10/11 01:21
  • by JessicaClarke