From 01f124b46fb9b0f02d8cc9600f81d9a6d13a74fc Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Wed, 27 Jun 2018 16:58:10 +0000 Subject: [PATCH] tinderbox: Only build clang/lld once if needed. Need to handle LLD_BOOTSTRAP separately (for archs like i386). This would be much better off with an off-by-default option like SHARED_TOOLCHAIN that universe force-enabled. Then a normal buildworld would store the toolchain there if enabled and otherwise in WORLDTMP with only the 1 arch selected. MFC after: 3 weeks Sponsored by: Dell EMC --- Makefile | 81 ++++++++++++++++++++++++++++++++++++++++- Makefile.inc1 | 5 ++- share/mk/src.sys.obj.mk | 7 ++++ 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f54eae4411d7..23a6113dddca 100644 --- a/Makefile +++ b/Makefile @@ -169,7 +169,7 @@ META_TGT_WHITELIST+= \ buildworld everything kernel-toolchain kernel-toolchains kernel \ kernels libraries native-xtools showconfig test-system-compiler \ test-system-linker tinderbox toolchain \ - toolchains universe world worlds xdev xdev-build + toolchains universe universe-toolchain world worlds xdev xdev-build .ORDER: buildworld installworld .ORDER: buildworld distrib-dirs @@ -480,7 +480,8 @@ worlds: .PHONY # with a reasonable chance of success, regardless of how old your # existing system is. # -.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets) +.if make(universe) || make(universe_kernels) || make(tinderbox) || \ + make(targets) || make(universe-toolchain) TARGETS?=amd64 arm arm64 i386 mips powerpc riscv sparc64 _UNIVERSE_TARGETS= ${TARGETS} TARGET_ARCHES_arm?= arm armeb armv6 armv7 @@ -542,6 +543,36 @@ universe_prologue: .PHONY .if defined(DOING_TINDERBOX) @rm -f ${FAILFILE} .endif + +universe-toolchain: .PHONY universe_prologue + @echo "--------------------------------------------------------------" + @echo "> Toolchain bootstrap started on `LC_ALL=C date`" + @echo "--------------------------------------------------------------" + ${_+_}@cd ${.CURDIR}; \ + env PATH=${PATH} ${SUB_MAKE} ${JFLAG} kernel-toolchain \ + TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH} \ + OBJTOP="${HOST_OBJTOP}" \ + WITHOUT_SYSTEM_COMPILER=yes \ + WITHOUT_SYSTEM_LINKER=yes \ + TOOLS_PREFIX_UNDEF= \ + kernel-toolchain \ + MK_LLVM_TARGET_ALL=yes \ + > _.${.TARGET} 2>&1 || \ + (echo "${.TARGET} failed," \ + "check _.${.TARGET} for details" | \ + ${MAKEFAIL}; false) + @if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/cc" ]; then \ + echo "Missing host compiler at ${HOST_OBJTOP}/tmp/usr/bin/cc?" >&2; \ + false; \ + fi + @if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/ld" ]; then \ + echo "Missing host linker at ${HOST_OBJTOP}/tmp/usr/bin/cc?" >&2; \ + false; \ + fi + @echo "--------------------------------------------------------------" + @echo "> Toolchain bootstrap completed on `LC_ALL=C date`" + @echo "--------------------------------------------------------------" + .for target in ${_UNIVERSE_TARGETS} universe: universe_${target} universe_epilogue: universe_${target} @@ -550,10 +581,56 @@ universe_${target}_prologue: universe_prologue .PHONY @echo ">> ${target} started on `LC_ALL=C date`" universe_${target}_worlds: .PHONY +.if !make(targets) && !make(universe-toolchain) +.for target_arch in ${TARGET_ARCHES_${target}} +.if !defined(_need_clang_${target}_${target_arch}) +_need_clang_${target}_${target_arch} != \ + env TARGET=${target} TARGET_ARCH=${target_arch} \ + ${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-compiler \ + -V MK_CLANG_BOOTSTRAP +.export _need_clang_${target}_${target_arch} +.endif +.if !defined(_need_lld_${target}_${target_arch}) +_need_lld_${target}_${target_arch} != \ + env TARGET=${target} TARGET_ARCH=${target_arch} \ + ${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-linker \ + -V MK_LLD_BOOTSTRAP +.export _need_lld_${target}_${target_arch} +.endif +# Setup env for each arch to use the one clang. +.if defined(_need_clang_${target}_${target_arch}) && \ + ${_need_clang_${target}_${target_arch}} != "no" +# No check on existing XCC or CROSS_BINUTILS_PREFIX, etc, is needed since +# we use the test-system-compiler logic to determine if clang needs to be +# built. It will be no from that logic if already using an external +# toolchain or /usr/bin/cc. +# XXX: Passing HOST_OBJTOP into the PATH would allow skipping legacy, +# bootstrap-tools, and cross-tools. Need to ensure each tool actually +# supports all TARGETS though. +MAKE_PARAMS_${target}+= \ + XCC="${HOST_OBJTOP}/tmp/usr/bin/cc" \ + XCXX="${HOST_OBJTOP}/tmp/usr/bin/c++" \ + XCPP="${HOST_OBJTOP}/tmp/usr/bin/cpp" +.endif +.if defined(_need_lld_${target}_${target_arch}) && \ + ${_need_lld_${target}_${target_arch}} != "no" +MAKE_PARAMS_${target}+= \ + XLD="${HOST_OBJTOP}/tmp/usr/bin/ld" +.endif +.endfor +.endif # !make(targets) + .if !defined(MAKE_JUST_KERNELS) universe_${target}_done: universe_${target}_worlds .PHONY .for target_arch in ${TARGET_ARCHES_${target}} universe_${target}_worlds: universe_${target}_${target_arch} .PHONY +.if (defined(_need_clang_${target}_${target_arch}) && \ + ${_need_clang_${target}_${target_arch}} != "no") || \ + (defined(_need_lld_${target}_${target_arch}) && \ + ${_need_lld_${target}_${target_arch}} != "no") +universe_${target}_${target_arch}: universe-toolchain +universe_${target}_prologue: universe-toolchain +.endif universe_${target}_${target_arch}: universe_${target}_prologue .MAKE .PHONY @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`" @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \ diff --git a/Makefile.inc1 b/Makefile.inc1 index 0c693ae0d5b7..613e2d969c25 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -645,7 +645,7 @@ CROSSENV+= ${TARGET_CFLAGS} # bootstrap-tools stage BMAKEENV= INSTALL="sh ${.CURDIR}/tools/install.sh" \ - TOOLS_PREFIX=${WORLDTMP} \ + TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \ PATH=${BPATH}:${PATH} \ WORLDTMP=${WORLDTMP} \ MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" @@ -694,7 +694,8 @@ XMAKE+= MK_LLVM_TARGET_ALL=no KTMAKEENV= INSTALL="sh ${.CURDIR}/tools/install.sh" \ PATH=${BPATH}:${PATH} \ WORLDTMP=${WORLDTMP} -KTMAKE= TOOLS_PREFIX=${WORLDTMP} \ +KTMAKE= \ + TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \ ${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \ DESTDIR= \ OBJTOP='${WORLDTMP}/obj-kernel-tools' \ diff --git a/share/mk/src.sys.obj.mk b/share/mk/src.sys.obj.mk index 038e45e2b4ee..3b48fc3c5514 100644 --- a/share/mk/src.sys.obj.mk +++ b/share/mk/src.sys.obj.mk @@ -220,4 +220,11 @@ OBJROOT= ${SRCTOP}/ .endif .endif # defined(NO_OBJ) +.if !defined(HOST_TARGET) +# we need HOST_TARGET etc below. +.include +.export HOST_TARGET +.endif +HOST_OBJTOP?= ${OBJROOT}${HOST_TARGET} + .endif # ${MK_DIRDEPS_BUILD} == "no"