Skip to content

Commit

Permalink
Merge bitcoin#30935: ci: Approximate MAKEJOBS in image build phase
Browse files Browse the repository at this point in the history
fa71bed ci: Approximate MAKEJOBS in image build phase (MarcoFalke)

Pull request description:

  The `MAKEJOBS` env var is the default in image builds, which is fine, because it is only relevant when building msan (or iwyu) and only differs when setting MAKEJOBS to something other than `nproc` (currently used as an approximation).

  So the normal workflow of `MAKEJOBS="-j$(nproc)" FILE_ENV="./ci/test/00_setup_env_native_msan.sh" ./ci/test_run_all.sh` already works today.

  However, `MAKEJOBS="-j1" FILE_ENV="./ci/test/00_setup_env_native_msan.sh" ./ci/test_run_all.sh` does not.

  This is hard to fix, because making the env var a build arg means that changing it (and only it) requires a new (expensive and redundant) build.

  So add an option `HAVE_CGROUP_CPUSET`, which can be set to approximate `MAKEJOBS` a bit. Can be tested via:

  `HAVE_CGROUP_CPUSET=yo MAKEJOBS="-j_something"  FILE_ENV="./ci/test/00_setup_env_native_msan.sh" ./ci/test_run_all.sh`

ACKs for top commit:
  fanquake:
    ACK fa71bed

Tree-SHA512: 43ef194c71d726f4cfa3fe08a5894c7872150f37da7e4fa0c2d89e4572bc63acadb5dae3286a5e5cc14a8ce3e1ebcc14571f1a3541e8db2d18d2f7503764a2f3
  • Loading branch information
fanquake committed Oct 22, 2024
2 parents 28ce159 + fa71bed commit ffe4261
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ci/test/01_base_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ if [ "$(git config --global ${CFG_DONE})" == "true" ]; then
exit 0
fi

MAKEJOBS="-j$( nproc )" # Use nproc, because MAKEJOBS is the default in docker image builds.

if [ -n "$DPKG_ADD_ARCH" ]; then
dpkg --add-architecture "$DPKG_ADD_ARCH"
fi
Expand Down Expand Up @@ -45,7 +47,7 @@ if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
-S /msan/llvm-project/llvm

ninja -C /msan/clang_build/ "-j$( nproc )" # Use nproc, because MAKEJOBS is the default in docker image builds
ninja -C /msan/clang_build/ "$MAKEJOBS"
ninja -C /msan/clang_build/ install-runtimes

update-alternatives --install /usr/bin/clang++ clang++ /msan/clang_build/bin/clang++ 100
Expand All @@ -64,7 +66,7 @@ if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then
-DLIBCXX_HARDENING_MODE=debug \
-S /msan/llvm-project/runtimes

ninja -C /msan/cxx_build/ "-j$( nproc )" # Use nproc, because MAKEJOBS is the default in docker image builds
ninja -C /msan/cxx_build/ "$MAKEJOBS"

# Clear no longer needed source folder
du -sh /msan/llvm-project
Expand All @@ -74,7 +76,7 @@ fi
if [[ "${RUN_TIDY}" == "true" ]]; then
${CI_RETRY_EXE} git clone --depth=1 https://github.com/include-what-you-use/include-what-you-use -b clang_"${TIDY_LLVM_V}" /include-what-you-use
cmake -B /iwyu-build/ -G 'Unix Makefiles' -DCMAKE_PREFIX_PATH=/usr/lib/llvm-"${TIDY_LLVM_V}" -S /include-what-you-use
make -C /iwyu-build/ install "-j$( nproc )" # Use nproc, because MAKEJOBS is the default in docker image builds
make -C /iwyu-build/ install "$MAKEJOBS"
fi

mkdir -p "${DEPENDS_DIR}/SDKs" "${DEPENDS_DIR}/sdk-sources"
Expand Down
10 changes: 10 additions & 0 deletions ci/test/02_run_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
python3 -c 'import os; [print(f"{key}={value}") for key, value in os.environ.items() if "\n" not in value and "HOME" != key and "PATH" != key and "USER" != key]' | tee "/tmp/env-$USER-$CONTAINER_NAME"
# System-dependent env vars must be kept as is. So read them from the container.
docker run --rm "${CI_IMAGE_NAME_TAG}" bash -c "env | grep --extended-regexp '^(HOME|PATH|USER)='" | tee --append "/tmp/env-$USER-$CONTAINER_NAME"

# Env vars during the build can not be changed. For example, a modified
# $MAKEJOBS is ignored in the build process. Use --cpuset-cpus as an
# approximation to respect $MAKEJOBS somewhat, if cpuset is available.
MAYBE_CPUSET=""
if [ "$HAVE_CGROUP_CPUSET" ]; then
MAYBE_CPUSET="--cpuset-cpus=$( python3 -c "import random;P=$( nproc );M=min(P,int('$MAKEJOBS'.lstrip('-j')));print(','.join(map(str,sorted(random.sample(range(P),M)))))" )"
fi
echo "Creating $CI_IMAGE_NAME_TAG container to run in"

# shellcheck disable=SC2086
DOCKER_BUILDKIT=1 docker build \
--file "${BASE_READ_ONLY_DIR}/ci/test_imagefile" \
--build-arg "CI_IMAGE_NAME_TAG=${CI_IMAGE_NAME_TAG}" \
--build-arg "FILE_ENV=${FILE_ENV}" \
$MAYBE_CPUSET \
--label="${CI_IMAGE_LABEL}" \
--tag="${CONTAINER_NAME}" \
"${BASE_READ_ONLY_DIR}"
Expand Down

0 comments on commit ffe4261

Please sign in to comment.