Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions cmake/external_rules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,23 @@ function(build_external_dependencies)
message(FATAL_ERROR "BoringSSL configure failed: ${boringssl_configure_status}")
endif()

# Run builds in parallel if we know how
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(cmake_build_args -j)
# Cap parallel build jobs to avoid process exhaustion (e.g. when multiple
# architecture builds run concurrently).
if(DEFINED ENV{CMAKE_BUILD_PARALLEL_LEVEL} AND
"$ENV{CMAKE_BUILD_PARALLEL_LEVEL}" MATCHES "^[1-9][0-9]*$")
set(boringssl_build_jobs "$ENV{CMAKE_BUILD_PARALLEL_LEVEL}")
else()
cmake_host_system_information(
RESULT boringssl_build_jobs
QUERY NUMBER_OF_LOGICAL_CORES
)
if(NOT boringssl_build_jobs OR boringssl_build_jobs LESS 1)
set(boringssl_build_jobs 1)
endif()
Comment on lines +262 to +264

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using LESS on a potentially empty or non-numeric string (e.g., if cmake_host_system_information fails or returns an unexpected string) can cause CMake configure-time errors. A more robust approach is to use a regular expression match to verify that boringssl_build_jobs is a valid positive integer, falling back to 1 otherwise.

        if(NOT boringssl_build_jobs MATCHES "^[1-9][0-9]*$")
          set(boringssl_build_jobs 1)
        endif()

endif()

execute_process(
COMMAND ${ENV_COMMAND} ${CMAKE_COMMAND} --build . ${CMAKE_SUB_BUILD_OPTIONS} --target ssl crypto -- ${cmake_build_args}
COMMAND ${ENV_COMMAND} ${CMAKE_COMMAND} --build . ${CMAKE_SUB_BUILD_OPTIONS} --parallel ${boringssl_build_jobs} --target ssl crypto
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/external/src/boringssl-build
RESULT_VARIABLE boringssl_build_status
)
Expand Down
Loading