Bug#1067714: llvm-toolchain-17: Build should use at least one CPU
Santiago Vila
sanvila at debian.org
Mon Mar 25 21:37:07 GMT 2024
Package: src:llvm-toolchain-17
Version: 17.0.6-5
Tags: patch
Dear maintainer:
I tried to build this package on a machine with 2 CPUs, 4GB of RAM,
and some swap, and the build stopped unexpectedly with this strange
error message:
LD_LIBRARY_PATH=/<<PKGBUILDDIR>>/build-llvm/lib:$LD_LIBRARY_PATH \
VERBOSE=1 cmake --build build-llvm -j 0 --target stage2 || cat build-llvm/tools/clang/stage2-bins/CMakeFiles/CMakeOut
put.log
The <jobs> value requires a positive integer argument.
Usage: cmake --build <dir> [options] [-- [native-options]]
cmake --build --preset <preset> [options] [-- [native-options]]
Options:
<dir> = Project binary directory to be built.
--preset <preset>, --preset=<preset>
= Specify a build preset.
--list-presets[=<type>]
= List available build presets.
--parallel [<jobs>], -j [<jobs>]
= Build in parallel using the given number of jobs.
If <jobs> is omitted the native build tool's
default number is used.
[...]
I would expect a message saying "not enough memory" instead,
not a "rant" about how I should use cmake.
However, I believe we could take for granted that the end user
knows what they are doing and simply ensure that NJOBS is
always >= 1 no matter what.
The attached patch tries to do that.
It changes "n==1 ? 1" to "n==1 || n2<=1 ? 1".
Also, it fixes a bug where in some cases the output is
greater than the number of available CPUs.
So, instead of "n2<n+1 ? n2 : n+1", which is buggy since n+1 > n,
I propose "n2<=n ? n2 : n" which IMO is a little bit more readable.
Thanks.
-------------- next part --------------
--- a/debian/rules
+++ b/debian/rules
@@ -59,7 +59,7 @@ else
endif
NJOBS := $(shell mt=`awk '/^(MemAvail|SwapFree)/ { mt += $$2 } END {print mt}' /proc/meminfo`; \
awk -vn=$(NCPUS) -vmt=$$mt -vm=$(MEM_PER_CPU) \
- 'END { mt/=1024; n2 = int(mt/m); print n==1 ? 1 : n2<n+1 ? n2 : n+1}' < /dev/null)
+ 'END { mt/=1024; n2 = int(mt/m); print n==1 || n2<=1 ? 1 : n2<=n ? n2 : n }' < /dev/null)
DH_VERSION := $(shell dpkg -s debhelper | grep '^Version' | awk '{print $$2}')
More information about the Pkg-llvm-team
mailing list