2024-05-27 19:08:14 +00:00
# afaik the longest dependency chain is stdenv -> stdenv-1#coreutils -> stdenv-1#gmp -> stdenv-0#libcxx -> stdenv-0#libc
# this is only possible through aggressive hacking to make libcxx build with stdenv-0#libc instead of bootstrapTools.libc.
{
lib ,
localSystem ,
crossSystem ,
config ,
overlays ,
crossOverlays ? [ ] ,
2024-07-17 09:08:06 +00:00
bootstrapFiles ?
let table = {
x86_64-freebsd = import ./bootstrap-files/x86_64-unknown-freebsd.nix ;
} ;
files = table . ${ localSystem . system } or ( throw " u n s u p p o r t e d p l a t f o r m ${ localSystem . system } f o r t h e p u r e F r e e B S D s t d e n v " ) ;
in files
2015-11-26 02:35:12 +00:00
} :
2018-12-05 03:06:46 +00:00
assert crossSystem == localSystem ;
2024-05-27 19:08:14 +00:00
let
inherit ( localSystem ) system ;
mkExtraBuildCommands0 = cc : ''
rsrc = " $ o u t / r e s o u r c e - r o o t "
mkdir " $ r s r c "
2024-07-24 22:52:10 +00:00
ln - s " ${ lib . getLib cc } / l i b / c l a n g / ${ lib . versions . major cc . version } / i n c l u d e " " $ r s r c "
2024-05-27 19:08:14 +00:00
echo " - r e s o u r c e - d i r = $ r s r c " > > $ out/nix-support/cc-cflags
'' ;
mkExtraBuildCommands =
cc : compiler-rt :
mkExtraBuildCommands0 cc
+ ''
ln - s " ${ compiler-rt . out } / l i b " " $ r s r c / l i b "
ln - s " ${ compiler-rt . out } / s h a r e " " $ r s r c / s h a r e "
'' ;
bootstrapArchive = (
derivation {
inherit system ;
name = " b o o t s t r a p - a r c h i v e " ;
pname = " b o o t s t r a p - a r c h i v e " ;
version = " 9 . 9 . 9 " ;
2024-07-17 09:08:06 +00:00
builder = " ${ bootstrapFiles . unpack } / l i b e x e c / l d - e l f . s o . 1 " ;
args = [ " ${ bootstrapFiles . unpack } / b i n / b a s h " ./unpack-bootstrap-files.sh ] ;
LD_LIBRARY_PATH = " ${ bootstrapFiles . unpack } / l i b " ;
src = bootstrapFiles . unpack ;
inherit ( bootstrapFiles ) bootstrapTools ;
2024-05-27 19:08:14 +00:00
}
) ;
2024-07-20 16:21:23 +00:00
linkBootstrap = (
2024-05-27 19:08:14 +00:00
attrs :
derivation (
attrs
// {
inherit system ;
name = attrs . name or ( builtins . baseNameOf ( builtins . elemAt attrs . paths 0 ) ) ;
src = bootstrapArchive ;
builder = " ${ bootstrapArchive } / b i n / b a s h " ;
2024-07-20 16:21:23 +00:00
args = [ ./linkBootstrap.sh ] ;
2024-05-27 19:08:14 +00:00
PATH = " ${ bootstrapArchive } / b i n " ;
paths = attrs . paths ;
}
)
) ;
2024-07-20 16:21:23 +00:00
# commented linkBootstrap entries are provided but unused
2024-05-27 19:08:14 +00:00
bootstrapTools = {
expand-response-params = " " ;
2024-07-20 16:21:23 +00:00
bsdcp = linkBootstrap { paths = [ " b i n / b s d c p " ] ; } ;
patchelf = linkBootstrap { paths = [ " b i n / p a t c h e l f " ] ; } ;
bash = linkBootstrap {
2024-05-27 19:08:14 +00:00
paths = [
" b i n / b a s h "
" b i n / s h "
] ;
shell = " b i n / b a s h " ;
shellPath = " / b i n / b a s h " ;
2020-03-01 19:22:16 +00:00
} ;
2024-07-20 16:21:23 +00:00
curl = linkBootstrap {
2024-05-27 19:08:14 +00:00
paths = [
" b i n / c u r l "
] ;
2020-03-01 19:22:16 +00:00
} ;
2024-05-27 19:08:14 +00:00
llvmPackages = {
2024-07-20 16:21:23 +00:00
clang-unwrapped = linkBootstrap {
2024-05-27 19:08:14 +00:00
paths = [
" b i n / c l a n g "
" b i n / c l a n g + + "
" b i n / c p p "
] ;
2024-07-24 22:52:10 +00:00
# SYNCME: this version number must be synced with the one in make-bootstrap-tools.nix
version = " 1 8 " ;
2024-05-27 19:08:14 +00:00
} ;
2024-07-20 16:21:23 +00:00
libunwind = linkBootstrap {
2024-05-27 19:08:14 +00:00
name = " l i b u n w i n d " ;
paths = [
" l i b / l i b u n w i n d . a "
" l i b / l i b u n w i n d . s o "
" l i b / l i b u n w i n d . s o . 1 "
" l i b / l i b u n w i n d . s o . 1 . 0 "
" l i b / l i b u n w i n d _ s h a r e d . s o "
] ;
} ;
2020-03-01 19:22:16 +00:00
} ;
2024-07-20 16:21:23 +00:00
coreutils = linkBootstrap {
2024-05-27 19:08:14 +00:00
name = " c o r e u t i l s " ;
paths = map ( str : " b i n / " + str ) [
" b a s e 6 4 "
" b a s e n a m e "
" c a t "
" c h c o n "
" c h g r p "
" c h m o d "
" c h o w n "
" c h r o o t "
" c k s u m "
" c o m m "
" c p "
" c s p l i t "
" c u t "
" d a t e "
" d d "
" d f "
" d i r "
" d i r c o l o r s "
" d i r n a m e "
" d u "
" e c h o "
" e n v "
" e x p a n d "
" e x p r "
" f a c t o r "
" f a l s e "
" f m t "
" f o l d "
" g r o u p s "
" h e a d "
" h o s t i d "
" i d "
" i n s t a l l "
" j o i n "
" k i l l "
" l i n k "
" l n "
" l o g n a m e "
" l s "
" m d 5 s u m "
" m k d i r "
" m k f i f o "
" m k n o d "
" m k t e m p "
" m v "
" n i c e "
" n l "
" n o h u p "
" n p r o c "
" n u m f m t "
" o d "
" p a s t e "
" p a t h c h k "
" p i n k y "
" p r "
" p r i n t e n v "
" p r i n t f "
" p t x "
" p w d "
" r e a d l i n k "
" r e a l p a t h "
" r m "
" r m d i r "
" r u n c o n "
" s e q "
" s h r e d "
" s h u f "
" s l e e p "
" s o r t "
" s p l i t "
" s t a t "
" s t d b u f "
" s t t y "
" s u m "
" t a c "
" t a i l "
" t e e "
" t e s t "
" t i m e o u t "
" t o u c h "
" t r "
" t r u e "
" t r u n c a t e "
" t s o r t "
" t t y "
" u n a m e "
" u n e x p a n d "
" u n i q "
" u n l i n k "
" u s e r s "
" v d i r "
" w c "
" w h o "
" w h o a m i "
" y e s "
" [ "
] ;
2020-03-01 19:22:16 +00:00
} ;
2024-07-20 16:21:23 +00:00
diffutils = linkBootstrap {
2024-05-27 19:08:14 +00:00
name = " d i f f u t i l s " ;
paths = map ( str : " b i n / " + str ) [
" d i f f "
" c m p "
#"diff3"
#"sdiff"
] ;
2020-03-01 19:22:16 +00:00
} ;
2024-07-20 16:21:23 +00:00
findutils = linkBootstrap {
2024-05-27 19:08:14 +00:00
name = " f i n d u t i l s " ;
paths = [
" b i n / f i n d "
" b i n / x a r g s "
] ;
2020-03-01 19:22:16 +00:00
} ;
2024-07-20 16:21:23 +00:00
iconv = linkBootstrap { paths = [ " b i n / i c o n v " ] ; } ;
patch = linkBootstrap { paths = [ " b i n / p a t c h " ] ; } ;
gnutar = linkBootstrap { paths = [ " b i n / t a r " ] ; } ;
gawk = linkBootstrap {
2024-05-27 19:08:14 +00:00
paths = [
" b i n / a w k "
" b i n / g a w k "
] ;
2020-03-01 19:22:16 +00:00
} ;
2024-07-20 16:21:23 +00:00
gnumake = linkBootstrap { paths = [ " b i n / m a k e " ] ; } ;
gnugrep = linkBootstrap {
2024-05-27 19:08:14 +00:00
paths = [
" b i n / g r e p "
" b i n / e g r e p "
" b i n / f g r e p "
] ;
2020-03-01 19:22:16 +00:00
} ;
2024-07-20 16:21:23 +00:00
gnused = linkBootstrap { paths = [ " b i n / s e d " ] ; } ;
gzip = linkBootstrap {
2024-05-27 19:08:14 +00:00
paths = [
" b i n / g z i p "
#"bin/gunzip"
] ;
2020-03-01 19:22:16 +00:00
} ;
2024-11-17 04:33:54 +00:00
bzip2 = linkBootstrap { paths = [ " b i n / b z i p 2 " " l i b / l i b b z 2 . s o " " l i b / l i b b z 2 . s o . 1 " ] ; } ;
2024-07-20 16:21:23 +00:00
xz = linkBootstrap {
2024-05-27 19:08:14 +00:00
paths = [
" b i n / x z "
" b i n / u n x z "
2024-11-17 04:33:54 +00:00
" l i b / l i b l z m a . s o "
" l i b / l i b l z m a . s o . 5 "
2024-05-27 19:08:14 +00:00
] ;
2020-03-01 19:22:16 +00:00
} ;
2024-07-20 16:21:23 +00:00
binutils-unwrapped = linkBootstrap {
2024-05-27 19:08:14 +00:00
name = " b i n u t i l s " ;
paths = map ( str : " b i n / " + str ) [
" l d "
#"as"
#"addr2line"
" a r "
#"c++filt"
#"elfedit"
#"gprof"
#"objdump"
" n m "
" o b j c o p y "
" r a n l i b "
" r e a d e l f "
" s i z e "
" s t r i n g s "
" s t r i p "
] ;
2016-12-16 13:22:02 +00:00
} ;
2024-05-27 19:08:14 +00:00
freebsd = {
2024-07-20 16:21:23 +00:00
locales = linkBootstrap { paths = [ " s h a r e / l o c a l e " ] ; } ;
libc = linkBootstrap {
2024-05-27 19:08:14 +00:00
name = " b o o t s t r a p L i b s " ;
paths = [
2024-11-17 04:33:54 +00:00
" l i b / S c r t 1 . o "
" l i b / c r t 1 . o "
" l i b / c r t b e g i n . o "
" l i b / c r t b e g i n S . o "
" l i b / c r t b e g i n T . o "
" l i b / c r t e n d . o "
" l i b / c r t e n d S . o "
" l i b / c r t i . o "
" l i b / c r t n . o "
" l i b / l i b c + + . a "
" l i b / l i b c + + . s o "
" l i b / l i b c + + . s o . 1 "
" l i b / l i b c . a "
" l i b / l i b c . s o "
" l i b / l i b c . s o . 7 "
" l i b / l i b c _ n o n s h a r e d . a "
" l i b / l i b c r y p t . s o "
" l i b / l i b c r y p t . s o . 5 "
" l i b / l i b c x x r t . a "
" l i b / l i b c x x r t . s o "
" l i b / l i b c x x r t . s o . 1 "
" l i b / l i b d e v s t a t . s o "
" l i b / l i b d e v s t a t . s o . 7 "
" l i b / l i b d l . s o "
" l i b / l i b d l . s o . 1 "
" l i b / l i b e l f . s o "
" l i b / l i b e l f . s o . 2 "
" l i b / l i b e x e c i n f o . s o "
" l i b / l i b e x e c i n f o . s o . 1 "
" l i b / l i b g c c . a "
" l i b / l i b g c c _ e h . a "
" l i b / l i b g c c _ s . s o "
" l i b / l i b g c c _ s . s o . 1 "
" l i b / l i b k v m . s o "
" l i b / l i b k v m . s o . 7 "
" l i b / l i b m . a "
" l i b / l i b m . s o "
" l i b / l i b m . s o . 5 "
" l i b / l i b m d . s o "
" l i b / l i b m d . s o . 6 "
" l i b / l i b n c u r s e s . s o "
" l i b / l i b n c u r s e s . s o . 6 "
" l i b / l i b n c u r s e s w . s o "
" l i b / l i b n c u r s e s w . s o . 6 "
" l i b / l i b p t h r e a d . s o "
" l i b / l i b r t . s o "
" l i b / l i b r t . s o . 1 "
" l i b / l i b t h r . s o "
" l i b / l i b t h r . s o . 3 "
" l i b / l i b u t i l . s o "
" l i b / l i b u t i l . s o . 9 "
" l i b / l i b x n e t . s o "
2024-05-27 19:08:14 +00:00
" i n c l u d e "
" s h a r e "
" l i b e x e c "
] ;
pname = " l i b s " ;
version = " b o o t s t r a p " ;
2015-11-28 15:06:15 +00:00
} ;
2016-12-16 13:22:02 +00:00
} ;
2024-05-27 19:08:14 +00:00
} ;
2020-03-01 19:22:16 +00:00
2024-05-27 19:08:14 +00:00
mkStdenv =
{
name ? " f r e e b s d " ,
overrides ?
prevStage : super : self :
{ } ,
hascxx ? true ,
} :
prevStage :
let
bsdcp =
prevStage . bsdcp or ( prevStage . runCommand " b s d c p " { }
" m k d i r - p $ o u t / b i n ; c p ${ prevStage . freebsd . cp } / b i n / c p $ o u t / b i n / b s d c p "
) ;
initialPath = with prevStage ; [
coreutils
gnutar
findutils
gnumake
gnused
patchelf
gnugrep
gawk
diffutils
patch
bash
xz
gzip
bzip2
bsdcp
] ;
shell = " ${ prevStage . bash } / b i n / b a s h " ;
stdenvNoCC = import ../generic {
inherit
config
initialPath
shell
fetchurlBoot
;
name = " s t d e n v N o C C - ${ name } " ;
buildPlatform = localSystem ;
hostPlatform = localSystem ;
targetPlatform = localSystem ;
cc = null ;
} ;
fetchurlBoot = import ../../build-support/fetchurl {
inherit lib stdenvNoCC ;
inherit ( prevStage ) curl ;
} ;
stdenv = import ../generic {
inherit
config
initialPath
shell
fetchurlBoot
;
name = " s t d e n v - ${ name } " ;
buildPlatform = localSystem ;
hostPlatform = localSystem ;
targetPlatform = localSystem ;
extraNativeBuildInputs = [
./unpack-source.sh
./always-patchelf.sh
] ;
cc = lib . makeOverridable ( import ../../build-support/cc-wrapper ) {
inherit lib stdenvNoCC ;
name = " ${ name } - c c " ;
inherit ( prevStage . freebsd ) libc ;
inherit ( prevStage ) gnugrep coreutils expand-response-params ;
libcxx = prevStage . llvmPackages . libcxx or null ;
runtimeShell = shell ;
propagateDoc = false ;
nativeTools = false ;
nativeLibc = false ;
cc = prevStage . llvmPackages . clang-unwrapped ;
isClang = true ;
extraPackages = lib . optionals hascxx [
prevStage . llvmPackages . compiler-rt
] ;
nixSupport = {
libcxx-cxxflags = lib . optionals ( ! hascxx ) [ " - i s y s t e m ${ prevStage . freebsd . libc } / i n c l u d e / c + + / v 1 " ] ;
} ;
extraBuildCommands = lib . optionalString hascxx (
mkExtraBuildCommands prevStage . llvmPackages . clang-unwrapped prevStage . llvmPackages . compiler-rt
) ;
bintools = lib . makeOverridable ( import ../../build-support/bintools-wrapper ) {
inherit lib stdenvNoCC ;
name = " ${ name } - b i n t o o l s " ;
inherit ( prevStage . freebsd ) libc ;
inherit ( prevStage ) gnugrep coreutils expand-response-params ;
runtimeShell = shell ;
bintools = prevStage . binutils-unwrapped ;
propagateDoc = false ;
nativeTools = false ;
nativeLibc = false ;
} ;
} ;
overrides = overrides prevStage ;
preHook = ''
export NIX_ENFORCE_PURITY = " ' ' ${ NIX_ENFORCE_PURITY-1 } "
export NIX_ENFORCE_NO_NATIVE = " ' ' ${ NIX_ENFORCE_NO_NATIVE-1 } "
export PATH_LOCALE = $ { prevStage . freebsd . localesReal or prevStage . freebsd . locales } /share/locale
'' ;
} ;
in
{
inherit config overlays stdenv ;
2016-12-16 13:22:02 +00:00
} ;
2024-05-27 19:08:14 +00:00
in
[
(
{ }:
mkStdenv {
name = " f r e e b s d - b o o t - 0 " ;
hascxx = false ;
overrides = prevStage : self : super : {
# this one's goal is to build foundational libs like libc and libcxx. we want to override literally every possible bin package we can with bootstrap tools
# we CAN'T import LLVM because the compiler built here is used to build the final compiler and the final compiler must not be built by the bootstrap compiler
inherit ( bootstrapTools )
patchelf
bash
curl
coreutils
diffutils
findutils
iconv
patch
gnutar
gawk
gnumake
gnugrep
gnused
gzip
bzip2
xz
;
binutils-unwrapped = builtins . removeAttrs bootstrapTools . binutils-unwrapped [ " s r c " ] ;
fetchurl = import ../../build-support/fetchurl {
inherit lib ;
inherit ( self ) stdenvNoCC ;
inherit ( prevStage ) curl ;
2020-03-01 19:22:16 +00:00
} ;
2024-05-27 19:08:14 +00:00
gettext = super . gettext . overrideAttrs {
NIX_CFLAGS_COMPILE = " - D H A V E _ I C O N V = 1 " ; # we clearly have iconv. what do you want?
2016-12-16 13:22:02 +00:00
} ;
2024-05-27 19:08:14 +00:00
curlReal = super . curl ;
tzdata = super . tzdata . overrideAttrs { NIX_CFLAGS_COMPILE = " - D H A V E _ G E T T E X T = 0 " ; } ;
# make it so libcxx/libunwind are built in this stdenv and not the next
freebsd = super . freebsd . overrideScope ( self' : super' : {
inherit ( prevStage . freebsd ) locales ;
stdenvNoLibcxx =
self . overrideCC ( self . stdenv // { name = " s t d e n v - f r e e b s d - b o o t - 0 . 4 " ; } )
(
self . stdenv . cc . override {
name = " f r e e b s d - b o o t - 0 . 4 - c c " ;
libc = self . freebsd . libc ;
bintools = self . stdenv . cc . bintools . override {
name = " f r e e b s d - b o o t - 0 . 4 - b i n t o o l s " ;
libc = self . freebsd . libc ;
} ;
}
) ;
} ) ;
llvmPackages = super . llvmPackages // {
libcxx =
( super . llvmPackages . libcxx . override {
stdenv = self . overrideCC ( self . stdenv // { name = " s t d e n v - f r e e b s d - b o o t - 0 . 5 " ; } ) (
self . stdenv . cc . override {
name = " f r e e b s d - b o o t - 0 . 5 - c c " ;
libc = self . freebsd . libc ;
bintools = self . stdenv . cc . bintools . override {
name = " f r e e b s d - b o o t - 0 . 5 - b i n t o o l s " ;
libc = self . freebsd . libc ;
} ;
extraPackages = [
self . llvmPackages . compiler-rt
] ;
extraBuildCommands = mkExtraBuildCommands self . llvmPackages . clang-unwrapped self . llvmPackages . compiler-rt ;
}
) ;
} ) . overrideAttrs
(
self' : super' : {
NIX_CFLAGS_COMPILE = " - n o s t d l i b + + " ;
NIX_LDFLAGS = " - - a l l o w - s h l i b - u n d e f i n e d " ;
cmakeFlags = builtins . filter ( x : x != " - D C M A K E _ S H A R E D _ L I N K E R _ F L A G S = - n o s t d l i b " ) super' . cmakeFlags ;
}
) ;
2020-03-01 19:22:16 +00:00
} ;
2015-11-28 15:06:15 +00:00
} ;
2024-05-27 19:08:14 +00:00
} bootstrapTools
)
( mkStdenv {
name = " f r e e b s d - b o o t - 1 " ;
overrides = prevStage : self : super : {
# this one's goal is to build all the tools that get imported into the final stdenv.
# we can import the foundational libs from boot-0
# we can import bins and libs that DON'T get imported OR LINKED into the final stdenv from boot-0
curl = prevStage . curlReal ;
inherit ( prevStage )
fetchurl
python3
bison
perl
cmake
ninja
;
2024-07-20 16:17:49 +00:00
fetchurlReal = super . fetchurl ;
2024-05-27 19:08:14 +00:00
freebsd = super . freebsd . overrideScope (
self' : super' : {
locales = prevStage . freebsd . locales ;
localesReal = super' . locales ;
libc = prevStage . freebsd . libc ;
}
) ;
llvmPackages = super . llvmPackages // {
libcxx = prevStage . llvmPackages . libcxx ;
} ;
} ;
} )
( mkStdenv {
name = " f r e e b s d " ;
overrides = prevStage : self : super : {
__bootstrapArchive = bootstrapArchive ;
2024-07-20 16:17:49 +00:00
fetchurl = prevStage . fetchurlReal ;
2024-05-27 19:08:14 +00:00
freebsd = super . freebsd . overrideScope (
self' : super' : { localesPrev = prevStage . freebsd . localesReal ; }
) ;
2015-11-26 02:35:12 +00:00
} ;
2016-12-16 13:22:02 +00:00
} )
]