Skip to content

Commit

Permalink
tinderbox: Only build clang/lld once if needed.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bdrewery committed Jun 27, 2018
1 parent 90eb413 commit 01f124b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 4 deletions.
81 changes: 79 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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 \
Expand Down
5 changes: 3 additions & 2 deletions Makefile.inc1
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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' \
Expand Down
7 changes: 7 additions & 0 deletions share/mk/src.sys.obj.mk
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,11 @@ OBJROOT= ${SRCTOP}/
.endif
.endif # defined(NO_OBJ)

.if !defined(HOST_TARGET)
# we need HOST_TARGET etc below.
.include <host-target.mk>
.export HOST_TARGET
.endif
HOST_OBJTOP?= ${OBJROOT}${HOST_TARGET}

.endif # ${MK_DIRDEPS_BUILD} == "no"

0 comments on commit 01f124b

Please sign in to comment.