Skip to content

fix(cmake): cap BoringSSL parallel build jobs - #2000

Closed
AustinBenoit wants to merge 2 commits into
mainfrom
fix/boringssl-parallel-cap
Closed

AustinBenoit wants to merge 2 commits into
mainfrom
fix/boringssl-parallel-cap

Conversation

@AustinBenoit

@AustinBenoit AustinBenoit commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replace the unbounded make -j invocation when building BoringSSL in cmake/external_rules.cmake with a bounded cmake --build ... --parallel <N>.

Why

When firebase-unity-sdk builds macOS multi-arch (x86_64 and arm64 concurrently via build_zips.py), both CMake configures invoke build_external_dependencies() at the same time. With CMAKE_GENERATOR="Unix Makefiles", passing bare -j (unlimited jobs) to GNU make causes both BoringSSL crypto builds to spawn hundreds of concurrent cc/clang processes simultaneously, intermittently exhausting macOS RLIMIT_NPROC:

cc: error: unable to execute command: posix_spawn failed: Resource temporarily unavailable
CMake Error at firebase-cpp-sdk/cmake/external_rules.cmake:263 (message):
  BoringSSL build failed: 2

Example failure: https://github.com/firebase/firebase-unity-sdk/actions/runs/47056656196/job/144081787558

Changes

  • In cmake/external_rules.cmake (build_external_dependencies), determine boringssl_build_jobs from:
    1. ENV{CMAKE_BUILD_PARALLEL_LEVEL} if set to a positive integer (preserved before env -i strips the child environment), otherwise
    2. cmake_host_system_information(RESULT boringssl_build_jobs QUERY NUMBER_OF_LOGICAL_CORES) (falling back to 1 if unavailable).
  • Pass --parallel ${boringssl_build_jobs} directly to cmake --build (supported across Makefiles, Ninja, Xcode, and MSBuild in CMake 3.12+; project requires 3.22+) instead of forwarding bare -j to Unix Makefiles.

Verification

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request updates the BoringSSL build process in cmake/external_rules.cmake to cap parallel build jobs using the CMAKE_BUILD_PARALLEL_LEVEL environment variable or the number of logical cores, avoiding process exhaustion. The review feedback suggests a more robust validation of the core count using a regular expression match instead of the LESS operator to prevent potential CMake configure-time errors if the host system information query fails.

Comment on lines +262 to +264
if(NOT boringssl_build_jobs OR boringssl_build_jobs LESS 1)
set(boringssl_build_jobs 1)
endif()

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()

@AustinBenoit AustinBenoit added the skip-release-notes Skip release notes check label Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-release-notes Skip release notes check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant