From 668a848600e171ad2f300884f7e2eac6127b8282 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Tue, 14 Sep 2021 15:26:08 +0800 Subject: [PATCH] fix(cmake/windows): fix low probability build failed on Windows GitOrigin-RevId: 21fe964bbb03e5eedaf07ed51d136e436fc73748 --- scripts/cmake-build/utils/utils.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/cmake-build/utils/utils.sh b/scripts/cmake-build/utils/utils.sh index 987d56c62..fbb18a45c 100755 --- a/scripts/cmake-build/utils/utils.sh +++ b/scripts/cmake-build/utils/utils.sh @@ -119,6 +119,18 @@ function show_cmakelist_options() { } function config_ninja_default_max_jobs() { - ((NINJA_MAX_JOBS = ${cpu_number} + 2)) - echo "config default NINJA_MAX_JOBS to ${NINJA_MAX_JOBS}" + # plus 2 is ninja default behavior, you can run ninja -h to verify + # but at Windows env, default max jobs will take 100% cpu, which may lead + # to some Windows OS issue sometimes, eg, OpenSSH server lost respond or vcvarsall.bat + # setenv failed etc(especially enable CUDA). I have no idea about this Windows OS issue. + # as a workaround: config default NINJA_MAX_JOBS to cpu_number - 1 + if [[ $OS =~ "NT" ]]; then + ((NINJA_MAX_JOBS = ${cpu_number} - 1)) + if [[ ${NINJA_MAX_JOBS} -le 0 ]]; then + NINJA_MAX_JOBS=1 + fi + else + ((NINJA_MAX_JOBS = ${cpu_number} + 2)) + fi + echo "config default NINJA_MAX_JOBS to ${NINJA_MAX_JOBS} [cpu number is:${cpu_number}]" } -- GitLab