Skip to content

Comments

[KeyManager]: (build) boringssl auto-build using cmake crate#646

Merged
atulpatildbz merged 3 commits intogoogle:mainfrom
atulpatildbz:boringssl-build-integration
Feb 10, 2026
Merged

[KeyManager]: (build) boringssl auto-build using cmake crate#646
atulpatildbz merged 3 commits intogoogle:mainfrom
atulpatildbz:boringssl-build-integration

Conversation

@atulpatildbz
Copy link
Collaborator

@atulpatildbz atulpatildbz commented Feb 6, 2026

Integrates BoringSSL into the keymanager build lifecycle by introducing build.rs for orchestration.

We've adopted sys-crate pattern for handling C/C++ dependencies.
Instead of relying on external shell scripts, we used the cmake build dependency to compile the native library (boringssl) as a static artifact during the cargo build step.

The RUST_BINDINGS CMake definition is injected to ensure BoringSSL generates the exact rust_wrapper symbols required by the bssl-crypto Rust crate

The resulting artifacts (libcrypto.a, libssl.a) are statically linked into the final binary, simplifying deployment.

Implementation Details

  • bssl-sys/build.rs: Implemented a custom build script that uses cmake::Config to drive the BoringSSL compilation.
    • Automatically orchestrates the cmake build process, handling platform detection and toolchain selection.
    • sets -DRUST_BINDINGS=ON to trigger the generation of Rust-compatible bindgen wrappers
    • detects and links the produced static archives (crypto, ssl, rust_wrapper) and propagates the search paths via cargo:rustc-link-search

Verification

  • Tested with changes in [KeyManager] Add HPKE and DHKEM crypto primitives #643
  • Tested on Linux/x86_64. Ran cargo test -p km_common and cargo test -p bssl-crypto. All 131 tests passed (including 93 bssl-crypto unit tests and 15 km_common tests), confirming that the underlying crypto symbols were correctly linked and callable
  • Validated that cargo build succeeds from a fresh clone without needing manual cmake invocation in the terminal

@atulpatildbz atulpatildbz changed the title [KeyManager]: (build) orchestrate boringssl build via cmake crate [KeyManager]: (build) boringssl auto-build using cmake crate Feb 6, 2026
Copy link
Collaborator

@NilanjanDaw NilanjanDaw left a comment

Choose a reason for hiding this comment

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

Thanks for working this. Some minor comments.

Integrates BoringSSL into the Cargo build process by adding a custom `build.rs`
to `third_party/bssl-sys`.

Implementation Details:
1. uses the `cmake` crate in `build.rs` to automatically configure and
build BoringSSL from git submodule.
2. Sets `RUST_BINDINGS` to ensure BoringSSL generates the necessary
Rust targets.
3. Preserves upstream bindgen logic to generate platform-specific
bindings during the build.
4. Enables standard `cargo build` workflows without requiring
external scripts or manual pre-build steps.
- Auto-init boringssl git submodule when source is missing (curl-sys
  / libgit2-sys pattern: attempt silently, discard errors)
- Add cargo:rerun-if-changed for the boringssl source directory so
  Cargo rebuilds when the submodule is updated
- Add assert on build_dir existence after cmake build for clarity
- Document why no cmake pre-check is needed (cmake crate handles it)
- Remove unused PathBuf import
@atulpatildbz
Copy link
Collaborator Author

/gcbrun

@atulpatildbz atulpatildbz merged commit b71451e into google:main Feb 10, 2026
11 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants