From bee3f107e401fe29940bbd29ce85d7bbfa2344d9 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 6 Dec 2020 19:00:54 -0600 Subject: [PATCH 2/4] Darwin clang: Build libcxx before llvm & clang llvm and clang need to be built with the same libc++. If you don't build with the same libc++ then you get weird errors where comparing std::error_code's fails because llvm has one errc enum, and clang has a different one. Also, make sure to use our libc++, not the system provided libc++ in both stage 2 and stage3 when building llvm and clang. To make this work, we need to control CPLUS_INCLUDE_PATH carefully at several points. Bug: https://bugs.gentoo.org/758167 Signed-off-by: Jacob Floyd --- scripts/bootstrap-prefix.sh | 52 ++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/scripts/bootstrap-prefix.sh b/scripts/bootstrap-prefix.sh index e8471bde99..6378eed5a5 100755 --- a/scripts/bootstrap-prefix.sh +++ b/scripts/bootstrap-prefix.sh @@ -102,14 +102,22 @@ darwin_symlink_sdk() { } darwin_include_paths_for_clang() { - # only used on clang-based darwin installs + # C_INCLUDE_PATH and CPLUS_INCLUDE_PATH are the only way to override + # clang's builtin header search path. (vs adding new paths w/ -I or -isystem) + # we need to carefully adjust these paths throughout stage 1 & stage 2 in order + # to successfully bootstrap with clang on darwin. local XCODE_PATH=$(xcode-select -p) # Xcode.app path is deeper than CommandLineTools path [[ "${XCODE_PATH}" == */CommandLineTools ]] || XCODE_PATH+="/Toolchains/XcodeDefault.xctoolchain" export C_INCLUDE_PATH="${ROOT}/MacOSX.sdk/usr/include" + # stage1&2: CPLUS_INCLUDE_PATH needs to have system c++ headers before libcxx is built export CPLUS_INCLUDE_PATH="${XCODE_PATH}/usr/include/c++/v1:${C_INCLUDE_PATH}" + # stage2: CPLUS_INCLUDE_PATH must not have system c++ headers for building libcxx + export libcxx_CPLUS_INCLUDE_PATH="${C_INCLUDE_PATH}" + # stage2: CPLUS_INCLUDE_PATH should have EPREFIX/tmp c++ headers after libcxx is built + export post_libcxx_CPLUS_INCLUDE_PATH="${ROOT}/tmp/usr/include/c++/v1:${C_INCLUDE_PATH}" } configure_cflags() { @@ -254,12 +262,14 @@ configure_toolchain() { vers=${vers% (clang-*} # this is Clang, recent enough to compile recent clang mycc=clang + # llvm and clang must be built with the same libc++ + # So, make sure that llvm and clang are always after libcxx* compiler_stage1+=" ${llvm_deps} - sys-devel/llvm - sys-devel/clang sys-libs/libcxxabi - sys-libs/libcxx" + sys-libs/libcxx + sys-devel/llvm + sys-devel/clang" CC=clang CXX=clang++ linker=sys-devel/binutils-apple @@ -284,10 +294,10 @@ configure_toolchain() { mycc=clang compiler_stage1+=" ${llvm_deps} - sys-devel/llvm - sys-devel/clang sys-libs/libcxxabi - sys-libs/libcxx" + sys-libs/libcxx + sys-devel/llvm + sys-devel/clang" ;; esac CC=clang @@ -324,10 +334,10 @@ configure_toolchain() { local cdep="3.5.9999" compiler_stage1+=" dev-libs/libffi -