@@ -220,18 +220,17 @@ configure_toolchain() {
220
220
# this is Clang, recent enough to compile recent clang
221
221
compiler_stage1+="
222
222
${llvm_deps}
223
- sys-libs/libcxxabi
224
- sys-libs/libcxx
223
+ sys-libs/compiler-rt
225
224
sys-devel/llvm
225
+ sys-devel/lld
226
+ sys-devel/clang-common
226
227
sys-devel/clang
227
228
"
228
229
CC=clang
229
230
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=
232
+ [[ " ${BOOTSTRAP_STAGE} " == stage2 ]] && \
233
+ linker=sys-devel/lld
235
234
;;
236
235
* )
237
236
eerror " unknown/unsupported compiler"
@@ -240,12 +239,16 @@ configure_toolchain() {
240
239
esac
241
240
242
241
compiler="
243
- dev-libs/libffi
244
242
${llvm_deps}
243
+ sys-libs/compiler-rt
245
244
sys-libs/libcxxabi
246
245
sys-libs/libcxx
247
246
sys-devel/llvm
248
- sys-devel/clang"
247
+ sys-devel/lld
248
+ sys-libs/llvm-libunwind
249
+ sys-devel/clang-common
250
+ sys-devel/clang
251
+ "
249
252
;;
250
253
* -linux* )
251
254
is-rap && einfo " Triggering Linux RAP bootstrap"
@@ -457,6 +460,8 @@ bootstrap_profile() {
457
460
if [[ ${DARWIN_USE_GCC} == 1 ]] ; then
458
461
# amend profile, to use gcc one
459
462
profile=" ${profile} /gcc"
463
+ elif [[ ${CHOST} == * -darwin* ]] ; then
464
+ [[ " ${BOOTSTRAP_STAGE} " != stage2 ]] && profile+=" /clang"
460
465
fi
461
466
462
467
[[ -n ${PROFILE_BASE}${PROFILE_VARIANT} ]] &&
@@ -1466,7 +1471,7 @@ bootstrap_stage1() {
1466
1471
[[ -e ${ROOT} /tmp/${x} ]] || ( cd " ${ROOT} " /tmp && ln -s usr/${x} )
1467
1472
done
1468
1473
1469
- configure_toolchain
1474
+ BOOTSTRAP_STAGE= " stage1 " configure_toolchain || return 1
1470
1475
export CC CXX
1471
1476
1472
1477
# default: empty = NO
@@ -1752,9 +1757,16 @@ bootstrap_stage1() {
1752
1757
# setup a profile for stage2
1753
1758
mkdir -p " ${ROOT} " /tmp/etc/. || return 1
1754
1759
[[ -e ${ROOT} /tmp/etc/portage/make.profile ]] || \
1755
- ( " ${CP} " -dpR " ${ROOT} " /etc/portage " ${ROOT} " /tmp/etc && \
1760
+ (
1761
+ " ${CP} " -dpR " ${ROOT} " /etc/portage " ${ROOT} " /tmp/etc && \
1756
1762
rm -f " ${ROOT} " /tmp/etc/portage/make.profile && \
1757
- (ROOT=" ${ROOT} " /tmp PREFIX_DISABLE_RAP=yes bootstrap_profile) ) || return 1
1763
+ (
1764
+ ROOT=" ${ROOT} " /tmp \
1765
+ PREFIX_DISABLE_RAP=" yes" \
1766
+ BOOTSTRAP_STAGE=" stage2" \
1767
+ bootstrap_profile
1768
+ )
1769
+ ) || return 1
1758
1770
1759
1771
# setup portage
1760
1772
[[ -e ${ROOT} /tmp/usr/bin/emerge ]] || (bootstrap_portage) || return 1
@@ -1819,7 +1831,6 @@ do_emerge_pkgs() {
1819
1831
" -berkdb"
1820
1832
" -fortran" # gcc
1821
1833
" -gdbm"
1822
- " -libcxx"
1823
1834
" -nls"
1824
1835
" -pcre"
1825
1836
" -python"
@@ -1831,7 +1842,24 @@ do_emerge_pkgs() {
1831
1842
" clang"
1832
1843
" internal-glib"
1833
1844
)
1834
- local override_make_conf_dir=" ${PORTAGE_OVERRIDE_EPREFIX}${MAKE_CONF_DIR# " ${ROOT} " } "
1845
+
1846
+ local skip_llvm_pkg_setup=
1847
+ if [[ ${CHOST} :${DARWIN_USE_GCC} == * -darwin* :0 ]] ; then
1848
+ # Clang-based Darwin
1849
+ myuse+=(
1850
+ " -binutils-plugin"
1851
+ " default-compiler-rt"
1852
+ " default-libcxx"
1853
+ " default-lld"
1854
+ )
1855
+ if [[ " ${BOOTSTRAP_STAGE} " == stage2 ]] ; then
1856
+ myuse+=( " bootstrap-prefix" )
1857
+ skip_llvm_pkg_setup=" yes"
1858
+ fi
1859
+ fi
1860
+
1861
+ local override_make_conf_dir=" ${PORTAGE_OVERRIDE_EPREFIX} "
1862
+ override_make_conf_dir+=" ${MAKE_CONF_DIR# " ${ROOT} " } "
1835
1863
1836
1864
if [[ " ${USE} " == * " prefix-stack " * ]] &&
1837
1865
[[ ${PORTAGE_OVERRIDE_EPREFIX} == * /tmp ]] &&
@@ -1892,6 +1920,7 @@ do_emerge_pkgs() {
1892
1920
PORTAGE_SYNC_STALE=0 \
1893
1921
FEATURES=" -news ${FEATURES} " \
1894
1922
USE=" ${myuse[*]} " \
1923
+ LLVM_ECLASS_SKIP_PKG_SETUP=" ${skip_llvm_pkg_setup} " \
1895
1924
" ${ROOT} " /tmp/bin/python \
1896
1925
" ${ROOT} " /tmp/usr/bin/emerge " ${eopts[@]} " " ${pkg} "
1897
1926
) || return 1
@@ -1908,7 +1937,7 @@ bootstrap_stage2() {
1908
1937
1909
1938
# Find out what toolchain packages we need, and configure LDFLAGS
1910
1939
# and friends.
1911
- configure_toolchain || return 1
1940
+ BOOTSTRAP_STAGE= " stage2 " configure_toolchain || return 1
1912
1941
configure_cflags || return 1
1913
1942
export CONFIG_SHELL=" ${ROOT} " /tmp/bin/bash
1914
1943
export CC CXX
@@ -1995,6 +2024,24 @@ bootstrap_stage2() {
1995
2024
EOF
1996
2025
fi
1997
2026
2027
+ # provide active SDK link on Darwin
2028
+ if [[ ${CHOST} == * -darwin* ]] ; then
2029
+ rm -f " ${ROOT} " /tmp/MacOSX.sdk
2030
+ ( cd " ${ROOT} " /tmp && ln -s ../MacOSX.sdk MacOSX.sdk )
2031
+ if [[ ${DARWIN_USE_GCC} == 0 ]] ; then
2032
+ # Until proper clang is installed, just redirect calls to it
2033
+ # to the system's one. Libtool is here because its path is
2034
+ # passed to the compiler-rt and llvm's ebuilds.
2035
+ for bin in libtool clang clang++ ; do
2036
+ {
2037
+ echo " #!${ROOT} /tmp/bin/sh"
2038
+ echo " exec ${bin} " ' "$@"'
2039
+ } > " ${ROOT} /tmp/usr/bin/${CHOST} -${bin} "
2040
+ chmod +x " ${ROOT} /tmp/usr/bin/${CHOST} -${bin} "
2041
+ done
2042
+ fi
2043
+ fi
2044
+
1998
2045
# Build a basic compiler and portage dependencies in $ROOT/tmp.
1999
2046
pkgs=(
2000
2047
sys-devel/gnuconfig
@@ -2013,12 +2060,6 @@ bootstrap_stage2() {
2013
2060
sys-devel/binutils-config
2014
2061
)
2015
2062
2016
- # provide active SDK link on Darwin
2017
- if [[ ${CHOST} == * -darwin* ]] ; then
2018
- rm -f " ${ROOT} " /tmp/MacOSX.sdk
2019
- ( cd " ${ROOT} " /tmp && ln -s ../MacOSX.sdk MacOSX.sdk )
2020
- fi
2021
-
2022
2063
# cmake has some external dependencies which require autoconf, etc.
2023
2064
# unless we only build the buildtool, bug #603012
2024
2065
echo " dev-build/cmake -server" >> " ${ROOT} " /tmp/etc/portage/package.use
@@ -2037,8 +2078,8 @@ bootstrap_stage2() {
2037
2078
2038
2079
emerge_pkgs --nodeps " ${pkgs[@]} " || return 1
2039
2080
2040
- # Debian multiarch supported by RAP needs ld to support sysroot.
2041
2081
for pkg in ${linker} ; do
2082
+ # Debian multiarch supported by RAP needs ld to support sysroot.
2042
2083
EXTRA_ECONF=$( rapx --with-sysroot=/) \
2043
2084
emerge_pkgs --nodeps " ${pkg} " || return 1
2044
2085
done
@@ -2083,12 +2124,22 @@ bootstrap_stage2() {
2083
2124
done
2084
2125
2085
2126
if [[ ${compiler_type} == clang ]] ; then
2127
+ if [[ ${CHOST} == * -darwin* ]] ; then
2128
+ # Stop using host's compilers, but still need 'libtool' in PATH.
2129
+ rm " ${ROOT} /tmp/usr/bin/${CHOST} " -{libtool,clang,clang++}
2130
+ mkdir -p " ${ROOT} " /usr/bin
2131
+ ln -s " ${ROOT} " /tmp/usr/lib/llvm/* /bin/llvm-libtool-darwin \
2132
+ " ${ROOT} " /usr/bin/libtool
2133
+ fi
2134
+
2086
2135
# We use Clang as our toolchain compiler, so we need to make
2087
2136
# sure we actually use it
2088
2137
mkdir -p -- " ${MAKE_CONF_DIR} "
2089
2138
{
2090
2139
echo
2091
2140
echo " # System compiler on $( uname) Prefix is Clang, do not remove this"
2141
+ echo " AS=\" ${CHOST} -clang -c\" "
2142
+ echo " CPP=${CHOST} -clang-cpp"
2092
2143
echo " CC=${CHOST} -clang"
2093
2144
echo " CXX=${CHOST} -clang++"
2094
2145
echo " OBJC=${CHOST} -clang"
@@ -2152,7 +2203,7 @@ bootstrap_stage3() {
2152
2203
# they stop mucking up builds.
2153
2204
rm -f " ${ROOT} " /tmp/usr/local/bin/{,my,${CHOST} -}{gcc,g++}
2154
2205
2155
- configure_toolchain || return 1
2206
+ BOOTSTRAP_STAGE=stage3 configure_toolchain || return 1
2156
2207
2157
2208
if [[ ${compiler_type} == clang ]] ; then
2158
2209
if ! type -P clang > /dev/null ; then
@@ -2205,7 +2256,6 @@ bootstrap_stage3() {
2205
2256
# (CBUILD, BDEPEND) and with the system being built
2206
2257
# (CHOST, RDEPEND). To correctly bootstrap stage3,
2207
2258
# PORTAGE_OVERRIDE_EPREFIX as BROOT is needed.
2208
- PREROOTPATH=" ${ROOT} " $( echo /{,tmp/}{usr/,}{,lib/llvm/{12,11,10}/}{s,}bin | sed " s, ,:${ROOT} ,g" ) \
2209
2259
EPREFIX=" ${ROOT} " PORTAGE_TMPDIR=" ${PORTAGE_TMPDIR} " \
2210
2260
EMERGE_LOG_DIR=" ${ROOT} " /var/log \
2211
2261
STAGE=stage3 \
@@ -2388,6 +2438,31 @@ bootstrap_stage3() {
2388
2438
PYTHON_COMPAT_OVERRIDE=" python$( python_ver) " \
2389
2439
pre_emerge_pkgs --nodeps " ${compiler_pkgs[@]} " || return 1
2390
2440
2441
+ if [[ ${CHOST} :${DARWIN_USE_GCC} == * -darwin* :0 ]] ; then
2442
+ # At this point our libc++abi.dylib is dynamically linked to
2443
+ # /usr/lib/libc++abi.dylib. That causes issues with perl later. Force
2444
+ # rebuild of sys-libs/libcxxabi to break this link.
2445
+ rm -Rf " ${ROOT} /var/db/pkg/sys-libs/libcxxabi" *
2446
+ PYTHON_COMPAT_OVERRIDE=python$( python_ver) \
2447
+ pre_emerge_pkgs --nodeps " sys-libs/libcxxabi" || return 1
2448
+
2449
+ # Make ${CHOST}-libtool (used by compiler-rt's and llvm's ebuild) to
2450
+ # point at the correct libtool in stage3. Resolve it in runtime, to
2451
+ # support llvm version upgrades.
2452
+ rm -f ${ROOT} /usr/bin/${CHOST} -libtool
2453
+ {
2454
+ echo " #!${ROOT} /bin/sh"
2455
+ echo ' exec llvm-libtool-darwin "$@"'
2456
+ } > " ${ROOT} " /usr/bin/${CHOST} -${bin}
2457
+
2458
+ # Now clang is ready, can use it instead of /usr/bin/gcc
2459
+ # TODO: perhaps symlink the whole etc/portage instead?
2460
+ ln -s -f " ${ROOT} /etc/portage/make.profile" \
2461
+ " ${ROOT} /tmp/etc/portage/make.profile"
2462
+ cp " ${ROOT} /etc/portage/make.conf/0100_bootstrap_prefix_clang.conf" \
2463
+ " ${ROOT} /tmp/etc/portage/make.conf/"
2464
+ fi
2465
+
2391
2466
# Undo libgcc_s.so path of stage2
2392
2467
# Now we have the compiler right there
2393
2468
unset CC CXX CPPFLAGS LDFLAGS
@@ -2404,8 +2479,35 @@ bootstrap_stage3() {
2404
2479
ln -s bash " ${ROOT} " /bin/sh
2405
2480
fi
2406
2481
2482
+ if [[ " ${compiler_type} " == clang ]] ; then
2483
+ if [[ ! -e " ${ROOT} " /tmp/etc/env.d/11stage3-llvm ]]; then
2484
+ ln -s " ${ROOT} " /etc/env.d/60llvm-* \
2485
+ " ${ROOT} " /tmp/etc/env.d/11stage3-llvm
2486
+ fi
2487
+ # Prevent usage of AppleClang aka gcc for bad packages which ignore $CC
2488
+ if [[ ! -e " ${ROOT} " /usr/bin/gcc ]]; then
2489
+ echo " #!${ROOT} /bin/bash" > " ${ROOT} " /usr/bin/gcc
2490
+ echo " false ${CHOST} -clang \"\$ @\" " >> " ${ROOT} " /usr/bin/gcc
2491
+ fi
2492
+ if [[ ! -e " ${ROOT} " /usr/bin/g++ ]]; then
2493
+ echo " #!${ROOT} /bin/bash" > " ${ROOT} " /usr/bin/g++
2494
+ echo " false ${CHOST} -clang++ \"\$ @\" " >> " ${ROOT} " /usr/bin/g++
2495
+ fi
2496
+ chmod +x " ${ROOT} " /usr/bin/{gcc,g++}
2497
+ if [[ ${CHOST} == * -darwin* ]]; then
2498
+ if [[ ! -e " ${ROOT} " /usr/bin/ld ]]; then
2499
+ echo " #!${ROOT} /bin/bash" > " ${ROOT} " /usr/bin/ld
2500
+ echo " false ld64.lld \"\$ @\" " >> " ${ROOT} " /usr/bin/ld
2501
+ fi
2502
+ chmod +x " ${ROOT} " /usr/bin/ld
2503
+ fi
2504
+ fi
2505
+
2407
2506
# Start using apps from the final destination Prefix
2408
- export PREROOTPATH=" ${ROOT} /usr/bin:${ROOT} /bin"
2507
+ cat > " ${ROOT} " /tmp/etc/env.d/10stage3 << -EOF
2508
+ PATH="${ROOT} /usr/bin:${ROOT} /bin"
2509
+ EOF
2510
+ " ${ROOT} " /tmp/usr/sbin/env-update
2409
2511
2410
2512
# Get a sane bash, overwriting tmp symlinks
2411
2513
pre_emerge_pkgs " " " app-shells/bash" || return 1
0 commit comments