@@ -220,18 +220,15 @@ configure_toolchain() {
220220 # this is Clang, recent enough to compile recent clang
221221 compiler_stage1+="
222222 ${llvm_deps}
223- sys-libs/libcxxabi
224- sys-libs/libcxx
223+ sys-libs/compiler-rt
225224 sys-devel/llvm
225+ sys-devel/lld
226+ sys-devel/clang-common
226227 sys-devel/clang
227228 "
228229 CC=clang
229230 CXX=clang++
230- # avoid going through hoops and deps for
231- # binutils-apple, rely on the host-installed ld to
232- # build a compiler, we'll pull in binutils-apple
233- # from system set
234- linker=sys-devel/native-cctools
231+ linker=sys-devel/lld
235232 ;;
236233 * )
237234 eerror " unknown/unsupported compiler"
@@ -242,10 +239,15 @@ configure_toolchain() {
242239 compiler="
243240 dev-libs/libffi
244241 ${llvm_deps}
242+ sys-libs/compiler-rt
245243 sys-libs/libcxxabi
246244 sys-libs/libcxx
247245 sys-devel/llvm
248- sys-devel/clang"
246+ sys-devel/lld
247+ sys-libs/llvm-libunwind
248+ sys-devel/clang-common
249+ sys-devel/clang
250+ "
249251 ;;
250252 * -linux* )
251253 is-rap && einfo " Triggering Linux RAP bootstrap"
@@ -454,9 +456,13 @@ bootstrap_profile() {
454456 ;;
455457 esac
456458
457- if [[ ${DARWIN_USE_GCC} == 1 ]] ; then
458- # amend profile, to use gcc one
459- profile=" ${profile} /gcc"
459+ if [[ ${CHOST} == * -darwin* ]] ; then
460+ if [[ ${DARWIN_USE_GCC} == 1 ]] ; then
461+ # amend profile, to use gcc one
462+ profile=" ${profile} /gcc"
463+ elif [[ " ${STAGE} " != stage2 ]]; then
464+ profile=" ${profile} /clang"
465+ fi
460466 fi
461467
462468 [[ -n ${PROFILE_BASE}${PROFILE_VARIANT} ]] &&
@@ -1176,18 +1182,17 @@ bootstrap_cmake_core() {
11761182
11771183 # we need sysroot crap to build cmake itself, but it makes trouble
11781184 # later on, so kill it in the installed version
1179- ver=${A% -* } ; ver=${ver% .* }
11801185 sed -i -e ' /cmake_gnu_set_sysroot_flag/d' \
1181- " ${ROOT} /tmp/usr/share/${ver} /Modules/Platform" /Apple-GNU-* .cmake || die
1186+ " ${ROOT} " /tmp/usr/share/cmake * /Modules/Platform/Apple-GNU-* .cmake || die
11821187 # disable isysroot usage with clang as well
11831188 sed -i -e ' /_SYSROOT_FLAG/d' \
1184- " ${ROOT} /tmp/usr/share/${ver} /Modules/Platform" /Apple-Clang.cmake || die
1189+ " ${ROOT} " /tmp/usr/share/cmake * /Modules/Platform/Apple-Clang.cmake || die
11851190
11861191 einfo " ${A% .tar.* } bootstrapped"
11871192}
11881193
11891194bootstrap_cmake () {
1190- bootstrap_cmake_core 3.16.5 || bootstrap_cmake_core 3.0.2
1195+ bootstrap_cmake_core 3.20.6 || bootstrap_cmake_core 3. 16.5 || bootstrap_cmake_core 3.0.2
11911196}
11921197
11931198bootstrap_zlib_core () {
@@ -1465,7 +1470,7 @@ bootstrap_stage1() {
14651470 [[ -e ${ROOT} /tmp/${x} ]] || ( cd " ${ROOT} " /tmp && ln -s usr/${x} )
14661471 done
14671472
1468- configure_toolchain
1473+ STAGE=stage1 configure_toolchain || return 1
14691474 export CC CXX
14701475
14711476 # default: empty = NO
@@ -1753,7 +1758,7 @@ bootstrap_stage1() {
17531758 [[ -e ${ROOT} /tmp/etc/portage/make.profile ]] || \
17541759 ( " ${CP} " -dpR " ${ROOT} " /etc/portage " ${ROOT} " /tmp/etc && \
17551760 rm -f " ${ROOT} " /tmp/etc/portage/make.profile && \
1756- (ROOT=" ${ROOT} " /tmp PREFIX_DISABLE_RAP=yes bootstrap_profile) ) || return 1
1761+ (ROOT=" ${ROOT} " /tmp PREFIX_DISABLE_RAP=yes STAGE=stage2 bootstrap_profile) ) || return 1
17571762
17581763 # setup portage
17591764 [[ -e ${ROOT} /tmp/usr/bin/emerge ]] || (bootstrap_portage) || return 1
@@ -1818,7 +1823,6 @@ do_emerge_pkgs() {
18181823 " -berkdb"
18191824 " -fortran" # gcc
18201825 " -gdbm"
1821- " -libcxx"
18221826 " -nls"
18231827 " -pcre"
18241828 " -python"
@@ -1830,6 +1834,22 @@ do_emerge_pkgs() {
18301834 " clang"
18311835 " internal-glib"
18321836 )
1837+ if [[ ${CHOST} :${DARWIN_USE_GCC} == * -darwin* :0 ]] ; then
1838+ # darwin+clang
1839+ myuse+=(
1840+ " -binutils-plugin"
1841+ " default-compiler-rt"
1842+ " default-libcxx"
1843+ " default-lld"
1844+ )
1845+ else
1846+ myuse+=( " -libcxx" )
1847+ fi
1848+ local skip_llvm_pkg_setup=" "
1849+ if [[ ${STAGE} == stage2 ]] ; then
1850+ myuse+=( " bootstrap-prefix" )
1851+ skip_llvm_pkg_setup=" yes"
1852+ fi
18331853 local override_make_conf_dir=" ${PORTAGE_OVERRIDE_EPREFIX}${MAKE_CONF_DIR# " ${ROOT} " } "
18341854
18351855 if [[ " ${USE} " == * " prefix-stack " * ]] &&
@@ -1891,6 +1911,7 @@ do_emerge_pkgs() {
18911911 PORTAGE_SYNC_STALE=0 \
18921912 FEATURES=" -news ${FEATURES} " \
18931913 USE=" ${myuse[*]} " \
1914+ LLVM_ECLASS_SKIP_PKG_SETUP=" ${skip_llvm_pkg_setup} " \
18941915 " ${ROOT} " /tmp/bin/python \
18951916 " ${ROOT} " /tmp/usr/bin/emerge " ${eopts[@]} " " ${pkg} "
18961917 ) || return 1
@@ -1907,11 +1928,29 @@ bootstrap_stage2() {
19071928
19081929 # Find out what toolchain packages we need, and configure LDFLAGS
19091930 # and friends.
1910- configure_toolchain || return 1
1931+ STAGE=stage2 configure_toolchain || return 1
19111932 configure_cflags || return 1
19121933 export CONFIG_SHELL=" ${ROOT} " /tmp/bin/bash
19131934 export CC CXX
19141935
1936+ # provide active SDK link on Darwin
1937+ if [[ ${CHOST} == * -darwin* ]] ; then
1938+ rm -f " ${ROOT} " /tmp/MacOSX.sdk
1939+ ( cd " ${ROOT} " /tmp && ln -s ../MacOSX.sdk MacOSX.sdk )
1940+ if [[ ${DARWIN_USE_GCC} == 0 ]] ; then
1941+ # Until proper clang is installed, just redirect calls to it to the
1942+ # system's one. Libtool is here because its path is passed to the
1943+ # compiler-rt and llvm's ebuilds.
1944+ for bin in libtool clang clang++ ; do
1945+ {
1946+ echo " #!${ROOT} /tmp/bin/sh"
1947+ echo " exec ${bin} " ' "$@"'
1948+ } > " ${ROOT} /tmp/usr/bin/${CHOST} -${bin} "
1949+ chmod +x " ${ROOT} /tmp/usr/bin/${CHOST} -${bin} "
1950+ done
1951+ fi
1952+ fi
1953+
19151954 emerge_pkgs () {
19161955 EPREFIX=" ${ROOT} " /tmp \
19171956 STAGE=stage2 \
@@ -2012,12 +2051,6 @@ bootstrap_stage2() {
20122051 sys-devel/binutils-config
20132052 )
20142053
2015- # provide active SDK link on Darwin
2016- if [[ ${CHOST} == * -darwin* ]] ; then
2017- rm -f " ${ROOT} " /tmp/MacOSX.sdk
2018- ( cd " ${ROOT} " /tmp && ln -s ../MacOSX.sdk MacOSX.sdk )
2019- fi
2020-
20212054 # cmake has some external dependencies which require autoconf, etc.
20222055 # unless we only build the buildtool, bug #603012
20232056 echo " dev-build/cmake -server" >> " ${ROOT} " /tmp/etc/portage/package.use
@@ -2036,11 +2069,13 @@ bootstrap_stage2() {
20362069
20372070 emerge_pkgs --nodeps " ${pkgs[@]} " || return 1
20382071
2039- # Debian multiarch supported by RAP needs ld to support sysroot.
2040- for pkg in ${linker} ; do
2041- EXTRA_ECONF=$( rapx --with-sysroot=/) \
2042- emerge_pkgs --nodeps " ${pkg} " || return 1
2043- done
2072+ if [[ ${CHOST} :${DARWIN_USE_GCC} != * -darwin* :0 ]] ; then
2073+ # Debian multiarch supported by RAP needs ld to support sysroot.
2074+ for pkg in ${linker} ; do
2075+ EXTRA_ECONF=$( rapx --with-sysroot=/) \
2076+ emerge_pkgs --nodeps " ${pkg} " || return 1
2077+ done
2078+ fi
20442079
20452080 # GCC doesn't respect CPPFLAGS because of its own meddling as well
20462081 # as toolchain.eclass, so provide a wrapper here to force just
@@ -2080,6 +2115,12 @@ bootstrap_stage2() {
20802115 [[ -x ${ROOT} /tmp/usr/bin/clang++ ]] && CXX=clang++
20812116 fi
20822117 done
2118+ if [[ ${CHOST} :${DARWIN_USE_GCC} == * -darwin* :0 ]] ; then
2119+ # Stop using host's compilers, but still need 'libtool' in PATH.
2120+ rm ${ROOT} /tmp/usr/bin/${CHOST} -{libtool,clang,clang++}
2121+ mkdir -p ${ROOT} /usr/bin
2122+ ln -s ${ROOT} /tmp/usr/lib/llvm/* /bin/llvm-libtool-darwin ${ROOT} /usr/bin/libtool
2123+ fi
20832124
20842125 if [[ ${compiler_type} == clang ]] ; then
20852126 # We use Clang as our toolchain compiler, so we need to make
@@ -2088,6 +2129,8 @@ bootstrap_stage2() {
20882129 {
20892130 echo
20902131 echo " # System compiler on $( uname) Prefix is Clang, do not remove this"
2132+ echo " AS=\" ${CHOST} -clang -c\" "
2133+ echo " CPP=${CHOST} -clang-cpp"
20912134 echo " CC=${CHOST} -clang"
20922135 echo " CXX=${CHOST} -clang++"
20932136 echo " OBJC=${CHOST} -clang"
@@ -2151,7 +2194,7 @@ bootstrap_stage3() {
21512194 # they stop mucking up builds.
21522195 rm -f " ${ROOT} " /tmp/usr/local/bin/{,my,${CHOST} -}{gcc,g++}
21532196
2154- configure_toolchain || return 1
2197+ STAGE=stage3 configure_toolchain || return 1
21552198
21562199 if [[ ${compiler_type} == clang ]] ; then
21572200 if ! type -P clang > /dev/null ; then
@@ -2204,7 +2247,6 @@ bootstrap_stage3() {
22042247 # (CBUILD, BDEPEND) and with the system being built
22052248 # (CHOST, RDEPEND). To correctly bootstrap stage3,
22062249 # PORTAGE_OVERRIDE_EPREFIX as BROOT is needed.
2207- PREROOTPATH=" ${ROOT} " $( echo /{,tmp/}{usr/,}{,lib/llvm/{12,11,10}/}{s,}bin | sed " s, ,:${ROOT} ,g" ) \
22082250 EPREFIX=" ${ROOT} " PORTAGE_TMPDIR=" ${PORTAGE_TMPDIR} " \
22092251 EMERGE_LOG_DIR=" ${ROOT} " /var/log \
22102252 STAGE=stage3 \
@@ -2356,8 +2398,10 @@ bootstrap_stage3() {
23562398 sys-devel/flex
23572399 sys-devel/binutils-config
23582400 sys-libs/zlib
2359- " ${linker_pkgs[@]} "
23602401 )
2402+ if [[ ${CHOST} :${DARWIN_USE_GCC} != * -darwin* :0 ]] ; then
2403+ pkgs+=( " ${linker_pkgs[@]} " )
2404+ fi
23612405
23622406 pre_emerge_pkgs --nodeps " ${pkgs[@]} " || return 1
23632407 fi
@@ -2387,6 +2431,30 @@ bootstrap_stage3() {
23872431 PYTHON_COMPAT_OVERRIDE=" python$( python_ver) " \
23882432 pre_emerge_pkgs --nodeps " ${compiler_pkgs[@]} " || return 1
23892433
2434+ if [[ ${CHOST} :${DARWIN_USE_GCC} == * -darwin* :0 ]] ; then
2435+ # At this point our libc++abi.dylib is dynamically linked to
2436+ # /usr/lib/libc++abi.dylib. That causes issues with perl later. Force
2437+ # rebuild of sys-libs/libcxxabi to break this link.
2438+ rm -Rf " ${ROOT} /var/db/pkg/sys-libs/libcxxabi" *
2439+ PYTHON_COMPAT_OVERRIDE=python$( python_ver) \
2440+ pre_emerge_pkgs --nodeps " sys-libs/libcxxabi" || return 1
2441+
2442+ # Make ${CHOST}-libtool (used by compiler-rt's and llvm's ebuild) to
2443+ # point at the correct libtool in stage3. Resolve it in runtime, to
2444+ # support llvm version upgrades.
2445+ rm -f ${ROOT} /usr/bin/${CHOST} -libtool
2446+ {
2447+ echo " #!${ROOT} /bin/sh"
2448+ echo ' exec llvm-libtool-darwin "$@"'
2449+ } > " ${ROOT} " /usr/bin/${CHOST} -${bin}
2450+
2451+ # Now clang is ready, can use it instead of /usr/bin/gcc
2452+ # TODO: perhaps symlink the whole etc/portage instead?
2453+ ln -s -f " ${ROOT} /etc/portage/make.profile" " ${ROOT} /tmp/etc/portage/make.profile"
2454+ cp " ${ROOT} /etc/portage/make.conf/0100_bootstrap_prefix_clang.conf" \
2455+ " ${ROOT} /tmp/etc/portage/make.conf/"
2456+ fi
2457+
23902458 # Undo libgcc_s.so path of stage2
23912459 # Now we have the compiler right there
23922460 unset CC CXX CPPFLAGS LDFLAGS
@@ -2403,8 +2471,33 @@ bootstrap_stage3() {
24032471 ln -s bash " ${ROOT} " /bin/sh
24042472 fi
24052473
2406- # Start using apps from the final destination Prefix
2407- export PREROOTPATH=" ${ROOT} /usr/bin:${ROOT} /bin"
2474+ # Start using apps from new target
2475+ cat > " ${ROOT} " /tmp/etc/env.d/10stage3 << -EOF
2476+ PATH="${ROOT} /usr/bin:${ROOT} /bin"
2477+ EOF
2478+ if [[ ${compiler_type} == clang ]] ; then
2479+ if [[ ! -e " ${ROOT} " /tmp/etc/env.d/11stage3-llvm ]]; then
2480+ ln -s " ${ROOT} " /etc/env.d/60llvm-* " ${ROOT} " /tmp/etc/env.d/11stage3-llvm
2481+ fi
2482+ # Prevent usage of AppleClang aka gcc for bad packages which ignore $CC
2483+ if [[ ! -e " ${ROOT} " /usr/bin/gcc ]]; then
2484+ echo " #!${ROOT} /bin/bash" > " ${ROOT} " /usr/bin/gcc
2485+ echo " false ${CHOST} -clang \"\$ @\" " >> " ${ROOT} " /usr/bin/gcc
2486+ fi
2487+ if [[ ! -e " ${ROOT} " /usr/bin/g++ ]]; then
2488+ echo " #!${ROOT} /bin/bash" > " ${ROOT} " /usr/bin/g++
2489+ echo " false ${CHOST} -clang++ \"\$ @\" " >> " ${ROOT} " /usr/bin/g++
2490+ fi
2491+ chmod +x " ${ROOT} " /usr/bin/{gcc,g++}
2492+ if [[ ${CHOST} == * -darwin* ]]; then
2493+ if [[ ! -e " ${ROOT} " /usr/bin/ld ]]; then
2494+ echo " #!${ROOT} /bin/bash" > " ${ROOT} " /usr/bin/ld
2495+ echo " false ld64.lld \"\$ @\" " >> " ${ROOT} " /usr/bin/ld
2496+ fi
2497+ chmod +x " ${ROOT} " /usr/bin/ld
2498+ fi
2499+ fi
2500+ " ${ROOT} " /tmp/usr/sbin/env-update
24082501
24092502 # Get a sane bash, overwriting tmp symlinks
24102503 pre_emerge_pkgs " " " app-shells/bash" || return 1
0 commit comments