nixpkgs/pkgs/development/tools/build-managers/bmake/setup-hook.sh
Sergei Trofimovich 69cf5181c3 stdenv/generic/setup.sh: enable parallel installs by default
The primary motivating example is openssl:

Before the change full package build took 1m54s minutes.
After the change full package build takes 59s.

About a 2x speedup.

The difference is visible because openssl builds hundreds of manpages
spawning a perl process per manual in `install` phase. Such a workload
is very easy to parallelize.

Another example would be `autotools`+`libtool` based build system where
install step requires relinking. The more binaries there are to relink
the more gain it will be to do it in parallel.

The change enables parallel installs by default only for buiilds that
already have parallel builds enabled. There is a high chance those build
systems already handle parallelism well but some packages will fail.

Consistently propagated the enableParallelBuilding to:
- cmake (enabled by default, similar to builds)
- ninja (set parallelism explicitly, don't rely on default)
- bmake (enable when requested)
- scons (enable when requested)
- meson (set parallelism explicitly, don't rely on default)
- waf (set parallelism explicitly, don't rely on default)
- qmake-4/5/6 (enable by default, similar to builds)
- xorg (always enable, similar to builds)
2023-02-26 22:02:09 +00:00

129 lines
3.2 KiB
Bash

addMakeFlags() {
export prefix="$out"
export MANDIR="${!outputMan}/share/man"
export MANTARGET=man
export BINOWN=
export STRIP_FLAG=
}
preConfigureHooks+=(addMakeFlags)
bmakeBuildPhase() {
runHook preBuild
local flagsArray=(
${enableParallelBuilding:+-j${NIX_BUILD_CORES}}
SHELL=$SHELL
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
$buildFlags ${buildFlagsArray+"${buildFlagsArray[@]}"}
)
echoCmd 'build flags' "${flagsArray[@]}"
bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray
runHook postBuild
}
if [ -z "${dontUseBmakeBuild-}" -a -z "${buildPhase-}" ]; then
buildPhase=bmakeBuildPhase
fi
bmakeCheckPhase() {
runHook preCheck
if [ -z "${checkTarget:-}" ]; then
#TODO(@oxij): should flagsArray influence make -n?
if bmake -n ${makefile:+-f $makefile} check >/dev/null 2>&1; then
checkTarget=check
elif bmake -n ${makefile:+-f $makefile} test >/dev/null 2>&1; then
checkTarget=test
fi
fi
if [ -z "${checkTarget:-}" ]; then
echo "no test target found in bmake, doing nothing"
else
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelChecking:+-j${NIX_BUILD_CORES}}
SHELL=$SHELL
# Old bash empty array hack
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
${checkFlags:-VERBOSE=y} ${checkFlagsArray+"${checkFlagsArray[@]}"}
${checkTarget}
)
echoCmd 'check flags' "${flagsArray[@]}"
bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray
fi
runHook postCheck
}
if [ -z "${dontUseBmakeCheck-}" -a -z "${checkPhase-}" ]; then
checkPhase=bmakeCheckPhase
fi
bmakeInstallPhase() {
runHook preInstall
if [ -n "$prefix" ]; then
mkdir -p "$prefix"
fi
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelInstalling:+-j${NIX_BUILD_CORES}}
SHELL=$SHELL
# Old bash empty array hack
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
$installFlags ${installFlagsArray+"${installFlagsArray[@]}"}
${installTargets:-install}
)
echoCmd 'install flags' "${flagsArray[@]}"
bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray
runHook postInstall
}
if [ -z "${dontUseBmakeInstall-}" -a -z "${installPhase-}" ]; then
installPhase=bmakeInstallPhase
fi
bmakeDistPhase() {
runHook preDist
if [ -n "$prefix" ]; then
mkdir -p "$prefix"
fi
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
$distFlags ${distFlagsArray+"${distFlagsArray[@]}"} ${distTarget:-dist}
)
echo 'dist flags: %q' "${flagsArray[@]}"
bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
if [ "${dontCopyDist:-0}" != 1 ]; then
mkdir -p "$out/tarballs"
# Note: don't quote $tarballs, since we explicitly permit
# wildcards in there.
# shellcheck disable=SC2086
cp -pvd ${tarballs:-*.tar.gz} "$out/tarballs"
fi
runHook postDist
}
if [ -z "${dontUseBmakeDist-}" -a -z "${distPhase-}" ]; then
distPhase=bmakeDistPhase
fi