diff options
author | Fabian Groffen <grobian@gentoo.org> | 2024-07-21 10:52:16 +0200 |
---|---|---|
committer | Fabian Groffen <grobian@gentoo.org> | 2024-07-21 10:52:16 +0200 |
commit | 636a653fcc42a974748a26cbf6c999592c762466 (patch) | |
tree | 12c84b996454feec3efe105e9dc7f4d0174cc3f6 | |
parent | scripts/bootstrap-prefix: improve emake error reporting (diff) | |
download | prefix-636a653fcc42a974748a26cbf6c999592c762466.tar.gz prefix-636a653fcc42a974748a26cbf6c999592c762466.tar.bz2 prefix-636a653fcc42a974748a26cbf6c999592c762466.zip |
scripts/bootstrap-prefix: use GCC-5 on all Darwin bootstraps
With recent macOS we need GCC-14 in order to make sense of system
headers. However, GCC-14 gets confused by (older) Clang installed on
the host system. So we need GCC-5 to get us a C11/C++11 compiler that
can compile GCC-14 to do the real work.
Unfortunately for GCC-5 to work properly on systems that do not have
/usr/{include,lib} we need wrappers such as we use in Gentoo Prefix
proper, thus part of that needs to be pulled and put in place too in
order to get correctly compiled and running binaries.
This change succeeds bootstrap on Darwin 17, 19 and 20, 21 and 22
pending.
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
-rwxr-xr-x | scripts/bootstrap-prefix.sh | 172 |
1 files changed, 122 insertions, 50 deletions
diff --git a/scripts/bootstrap-prefix.sh b/scripts/bootstrap-prefix.sh index f49a595ad0..33c9feff34 100755 --- a/scripts/bootstrap-prefix.sh +++ b/scripts/bootstrap-prefix.sh @@ -391,9 +391,10 @@ bootstrap_profile() { profile="prefix/darwin/macos/10.$((rev - 4))/x64" ;; *64-apple-darwin2[0123456789]) - # Big Sur is 11.0 + # Big Sur is 11.0 # Monterey is 12.0 - # Ventura is 13.0 + # Ventura is 13.0 + # Sanoma is 14.0 rev=${CHOST##*darwin} case ${CHOST%%-*} in x86_64) arch=x64 ;; @@ -453,44 +454,6 @@ bootstrap_profile() { ;; esac - if [[ ${CHOST} == *-darwin* ]] ; then - # setup MacOSX.sdk symlink for GCC, this should probably be - # managed using an eselect module in the future - # FWIW, just use system (/) if it seems OK, for some reason - # early versions of TAPI-based SDKs did not include some symbols - # like fclose, which ld64 is able to resolve from the dylibs - # although they are unvisible using e.g. nm. - rm -f "${ROOT}"/MacOSX.sdk - local SDKPATH - if [[ -e /usr/lib/libSystem.B.dylib && -d /usr/include ]] ; then - SDKPATH=/ - else - SDKPATH=$(xcrun --show-sdk-path --sdk macosx) - if [[ -L ${SDKPATH} ]] ; then - local fsdk - local osvers - # try and find a matching OS SDK - fsdk="$(readlink -f "${SDKPATH}")" - osvers="$(sw_vers -productVersion)" - if [[ ${osvers%%.*} -le 10 ]] ; then - osvers=$(echo "${osvers}" | cut -d'.' -f1-2) - else - osvers=${osvers%%.*} - fi - fsdk=${fsdk%/MacOSX*.sdk} - fsdk=${fsdk}/MacOSX${osvers}.sdk - [[ -e ${fsdk} ]] && SDKPATH=${fsdk} - fi - if [[ ! -e ${SDKPATH} ]] ; then - SDKPATH=$(xcodebuild -showsdks | sort -nr \ - | grep -o "macosx.*" | head -n1) - SDKPATH=$(xcode-select -print-path)/SDKs/MacOSX${SDKPATH#macosx}.sdk - fi - fi - ( cd "${ROOT}" && ln -s "${SDKPATH}" MacOSX.sdk ) - einfo "using system sources from ${SDKPATH}" - fi - if [[ ${DARWIN_USE_GCC} == 1 ]] ; then # amend profile, to use gcc one profile="${profile}/gcc" @@ -585,7 +548,7 @@ bootstrap_tree() { # retain this comment and the line below to # keep this snapshot around in the snapshots # MKSNAPSHOT-ANCHOR -- directory of rsync slaves - local PV="20240622" + local PV="20240718" # RAP uses the latest gentoo main repo snapshot to bootstrap. is-rap && LATEST_TREE_YES=1 @@ -919,8 +882,16 @@ bootstrap_gnu() { "--disable-bootstrap" "--disable-multilib" "--disable-nls" + "--disable-libsanitizer" ) + if [[ ${CHOST} == *-darwin* ]] ; then + myconf+=( + "--with-native-system-header-dir=${ROOT}/MacOSX.sdk/usr/include" + "--with-ld=${ROOT}/tmp/usr/bin/ldwrapper" + ) + fi + export CFLAGS="-O1 -pipe" export CXXFLAGS="-O1 -pipe" fi @@ -1320,6 +1291,33 @@ bootstrap_mpc() { bootstrap_gnu mpc 1.2.1 } +bootstrap_ldwrapper() { + A=ldwrapper.c + + einfo "Bootstrapping ${A%.c}" + + efetch "https://rsync.prefix.bitzolder.nl/sys-devel/binutils-config/files/${A}" || return 1 + + export S="${PORTAGE_TMPDIR}/ldwrapper" + rm -rf "${S}" + mkdir -p "${S}" || return 1 + cd "${S}" || return 1 + cp "${DISTDIR}/${A}" . || return 1 + + einfo "Compiling ${A%.c}" + ${CC:-gcc} \ + -o ldwrapper \ + -DCHOST="\"${CHOST}\"" \ + -DEPREFIX="\"${ROOT}\"" \ + ldwrapper.c || return 1 + + einfo "Installing ${A%.c}" + mkdir -p "${ROOT}"/tmp/usr/bin + cp -a ldwrapper "${ROOT}"/tmp/usr/bin/ || return 1 + + einfo "${A%.c} bootstrapped" +} + bootstrap_gcc5() { # bootstraps with gcc-4.0.1 (Darwin 8), provides C11 bootstrap_gnu gcc 5.5.0 @@ -1482,12 +1480,51 @@ bootstrap_stage1() { [[ -e ${ROOT}/tmp/${x} ]] || ( cd "${ROOT}"/tmp && ln -s usr/${x} ) done - # we could check compiler version here, but we just know - # it's Darwin 8 and 9 being affected here, so handle them to - # get a GCC-5 which is sufficient to compile the current tree - # packages + configure_toolchain + export CC CXX + + # GCC 14 cannot be compiled by versions of Clang at least on + # Darwin17, so go the safe route and get GCC-5 which is sufficient + # and the last one we can compile without C11. This also compiles + # on Darwin 8 and 9. # see also configure_toolchain - if [[ ${CHOST} == *-darwin[89] ]] ; then + if [[ ${CHOST} == *-darwin* ]] ; then + # setup MacOSX.sdk symlink for GCC, this should probably be + # managed using an eselect module in the future + # FWIW, just use system (/) if it seems OK, for some reason + # early versions of TAPI-based SDKs did not include some symbols + # like fclose, which ld64 is able to resolve from the dylibs + # although they are unvisible using e.g. nm. + rm -f "${ROOT}"/MacOSX.sdk + local SDKPATH + if [[ -e /usr/lib/libSystem.B.dylib && -d /usr/include ]] ; then + SDKPATH=/ + else + SDKPATH=$(xcrun --show-sdk-path --sdk macosx) + if [[ -L ${SDKPATH} ]] ; then + local fsdk + local osvers + # try and find a matching OS SDK + fsdk="$(readlink -f "${SDKPATH}")" + osvers="$(sw_vers -productVersion)" + if [[ ${osvers%%.*} -le 10 ]] ; then + osvers=$(echo "${osvers}" | cut -d'.' -f1-2) + else + osvers=${osvers%%.*} + fi + fsdk=${fsdk%/MacOSX*.sdk} + fsdk=${fsdk}/MacOSX${osvers}.sdk + [[ -e ${fsdk} ]] && SDKPATH=${fsdk} + fi + if [[ ! -e ${SDKPATH} ]] ; then + SDKPATH=$(xcodebuild -showsdks | sort -nr \ + | grep -o "macosx.*" | head -n1) + SDKPATH=$(xcode-select -print-path)/SDKs/MacOSX${SDKPATH#macosx}.sdk + fi + fi + ( cd "${ROOT}" && ln -s "${SDKPATH}" MacOSX.sdk ) + einfo "using system sources from ${SDKPATH}" + # benefit from 4.2 if it's present if [[ -e /usr/bin/gcc-4.2 ]] ; then export CC=gcc-4.2 @@ -1499,12 +1536,47 @@ bootstrap_stage1() { || (bootstrap_mpfr) || return 1 [[ -e ${ROOT}/tmp/usr/include/mpc.h ]] \ || (bootstrap_mpc) || return 1 + [[ -x ${ROOT}/tmp/usr/bin/ldwrapper ]] \ + || (bootstrap_ldwrapper) || return 1 + # get ldwrapper target in PATH + export BINUTILS_CONFIG_LD="$(type -P ld)" + # force deployment target in GCCs build, GCC-5 doesn't quite get + # the newer macOS versions (20+) and thus confuses ld when it + # passes on the deployment version. Use High Sierra as it has + # everything we need + [[ ${CHOST##*darwin} -gt 10 ]] && export MACOSX_DEPLOYMENT_TARGET=10.13 [[ -x ${ROOT}/tmp/usr/bin/gcc ]] \ || (bootstrap_gcc5) || return 1 - fi - configure_toolchain - export CC CXX + if [[ ${CHOST##*darwin} -gt 10 ]] ; then + # install wrappers in tmp/usr/local/bin which comes before + # /tmp/usr/bin in PATH + mkdir -p "${ROOT}"/tmp/usr/local/bin + rm -f "${ROOT}"/tmp/usr/local/bin/{gcc,${CHOST}-gcc} + cat > "${ROOT}/tmp/usr/local/bin/${CHOST}-gcc" <<-EOS + #!/usr/bin/env sh + export MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} + export BINUTILS_CONFIG_LD="$(type -P ld)" + exec "${ROOT}"/tmp/usr/bin/${CHOST}-gcc "\$@" + EOS + chmod 755 "${ROOT}/tmp/usr/local/bin/${CHOST}-gcc" + ln -s ${CHOST}-gcc "${ROOT}"/tmp/usr/local/bin/gcc + + rm -f "${ROOT}"/tmp/usr/local/bin/{g++,${CHOST}-g++} + cat > "${ROOT}"/tmp/usr/local/bin/${CHOST}-g++ <<-EOS + #!/usr/bin/env sh + export MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} + export BINUTILS_CONFIG_LD="$(type -P ld)" + exec "${ROOT}"/tmp/usr/bin/${CHOST}-g++ "\$@" + EOS + chmod 755 "${ROOT}"/tmp/usr/local/bin/${CHOST}-g++ + ln -s ${CHOST}-g++ "${ROOT}"/tmp/usr/local/bin/g++ + fi + + # reset after gcc-4.2 usage + export CC=gcc + export CXX=g++ + fi # Run all bootstrap_* commands in a subshell since the targets # frequently pollute the environment using exports which affect @@ -3018,7 +3090,7 @@ EOF # location seems ok break done - export PATH="$EPREFIX/usr/bin:$EPREFIX/bin:$EPREFIX/tmp/usr/bin:$EPREFIX/tmp/bin:$EPREFIX/tmp/usr/local/bin:${PATH}" + export PATH="$EPREFIX/usr/bin:$EPREFIX/bin:$EPREFIX/tmp/usr/local/bin:$EPREFIX/tmp/usr/bin:$EPREFIX/tmp/bin:${PATH}" cat << EOF |