Repository: rust
Issue: Building LLVM from source doesn't forward `-j x` to cmake
Labels: A-LLVM,E-mentor,T-bootstrap,E-medium,C-bug

<!--
Building Rust 1.54.0 with GCC-11.2.0 ignores the number of threads you want to use and results of using all available threads on the build node
-->

I am building Rust on a large HPC cluster using EasyBuild but Rust is not behaving as it should:

```bash
3450751 pts/1    S+     0:00  |                   \_ /bin/bash /rds/general/user/jsassman/home/.local/bin/eb --robot --download-timeout=100 --modules-tool=EnvironmentModules --module-syntax=Tcl --allow-modules-tool-mismatch -dr --parallel=64 Rust-1.54.0-GCCcore-11.2.0.eb
3450771 pts/1    Sl+    0:04  |                       \_ python3 -m easybuild.main --robot --download-timeout=100 --modules-tool=EnvironmentModules --module-syntax=Tcl --allow-modules-tool-mismatch -dr --parallel=64 Rust-1.54.0-GCCcore-11.2.0.eb

3450859 pts/1    S+     0:00  |                           \_ make -j 64
3450865 pts/1    S+     0:11  |                               \_ /rds/general/user/jsassman/home/apps/easybuild/amd/zen2/software/Python/3.9.6-GCCcore-11.2.0-bare/bin/python3 /dev/shm/jsassman/Rust/1.54.0/GCCcore-11.2.0/rustc-1.54.0-src/src/bootstrap/bootstrap.py build --stage 2
3452315 pts/1    S+     0:00  |                                   \_ /dev/shm/jsassman/Rust/1.54.0/GCCcore-11.2.0/rustc-1.54.0-src/build/bootstrap/debug/bootstrap build --stage 2
3487991 pts/1    S+     0:00  |                                       \_ cmake --build . --target install --config Release -- -j 256
3487994 pts/1    S+     0:00  |                                           \_ /usr/bin/gmake -f Makefile -j 256 install

3450751 pts/1    S+     0:00  |                   \_ /bin/bash /rds/general/user/jsassman/home/.local/bin/eb --robot --download-timeout=100 --modules-tool=EnvironmentModules --module-syntax=Tcl --allow-modules-tool-mismatch -dr --parallel=64 Rust-1.54.0-GCCcore-11.2.0.eb
3450771 pts/1    Sl+    0:04  |                       \_ python3 -m easybuild.main --robot --download-timeout=100 --modules-tool=EnvironmentModules --module-syntax=Tcl --allow-modules-tool-mismatch -dr --parallel=64 Rust-1.54.0-GCCcore-11.2.0.eb
--> 3450859 pts/1    S+     0:00  |                           \_ make -j 64
3450865 pts/1    S+     0:11  |                               \_ /rds/general/user/jsassman/home/apps/easybuild/amd/zen2/software/Python/3.9.6-GCCcore-11.2.0-bare/bin/python3 /dev/shm/jsassman/Rust/1.54.0/GCCcore-11.2.0/rustc-1.54.0-src/src/bootstrap/bootstrap.py build --stage 2
3452315 pts/1    S+     0:00  |                                   \_ /dev/shm/jsassman/Rust/1.54.0/GCCcore-11.2.0/rustc-1.54.0-src/build/bootstrap/debug/bootstrap build --stage 2
--> 3487991 pts/1    S+     0:00  |                                       \_ cmake --build . --target install --config Release -- -j 256
--> 3487994 pts/1    S+     0:00  |                                           \_ /usr/bin/gmake -f Makefile -j 256 install
3488033 pts/1    S+     0:00  |                                               \_ /usr/bin/gmake -s -f CMakeFiles/Makefile2 all
3488574 pts/1    S+     0:00  |                                                   \_ /usr/bin/gmake -s -f utils/TableGen/CMakeFiles/obj.llvm-tblgen.dir/build.make utils/TableGen/CMakeFiles/obj.llvm-tblgen.dir/build
3488695 pts/1    S+     0:00  |                                                   |   \_ /rds/general/user/jsassman/home/apps/easybuild/amd/zen2/software/GCCcore/11.2.0/bin/g++ -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/dev/shm/jsassman/Rust/1.54.0/GCCcore-11.2.0/rustc-1.54.0-src/build/x86_64-unknown-linux-gnu/llvm/build/utils/TableGen -I/dev/shm/jsassman/Rust/1.54.0/GCCcore-11.2.0/rustc-1.54.0-src/src/llvm-project/llvm/utils/TableGen -I/dev/shm/jsassman/Rust/1.54.0/GCCcore-11.2.0/rustc-1.54.0-src/build/x86_64-unknown-linux-gnu/llvm/build/include -I/dev/shm/jsassman/Rust/1.54.0/GCCcore-11.2.0/rustc-1.54.0-src/src/llvm-project/llvm/include -ffunction-sections -fdata-sections -fPIC -m64 -ftree-vectorize -march=native -fno-math-errno -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -ffunction-sections -fdata-sections -O3 -DNDEBUG -fno-exceptions -fno-rtti -std=c++14 -MD -MT utils/TableGen/CMakeFiles/obj.llvm-tblgen.dir/AsmWriterEmitter.cpp.o -MF CMakeFiles/obj.llvm-tblgen.dir/AsmWriterEmitter.cpp.o.d -o CMakeFiles/obj.llvm-tblgen.dir/AsmWriterEmitter.cpp.o -c /dev/shm/jsassman/Rust/1.54.0/GCCcore-11.2.0/rustc-1.54.0-src/src/llvm-project/llvm/utils/TableGen/AsmWriterEmitter.cpp
```

I expected to see only 64 threads being used but Rust is ignoring my request to use only 64 cores and uses the max-number of available treads. This leads to a very poor performance as each thread spends more time waiting than actually doing. specially when there are 128 threads available. This seems to be a bug in Rust and not in EasyBuild, as above. 


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

```
 Rust 1.54.0
```