Skip to content

Generate Rust Bindings#2999

Merged
justsmth merged 7 commits intoaws:mainfrom
justsmth:rust-bindings
Feb 20, 2026
Merged

Generate Rust Bindings#2999
justsmth merged 7 commits intoaws:mainfrom
justsmth:rust-bindings

Conversation

@justsmth
Copy link
Copy Markdown
Contributor

@justsmth justsmth commented Feb 16, 2026

Issues:

  • Addresses: V2090958423

Description of changes:

This adds CMake support for generating Rust FFI bindings from the AWS-LC public C headers using bindgen-cli. This is intended for use by downstream Rust consumers so that bindings can be generated directly from the CMake build system.

New CMake option: -DGENERATE_RUST_BINDINGS=ON (off by default)

When enabled, the build:

  1. Validates that bindgen-cli (≥0.69.5) and rustfmt are available
  2. Auto-discovers all public OpenSSL headers and generates a rust_wrapper.h aggregation header
  3. Invokes bindgen to produce aws_lc_bindings.rs in the build directory
  4. Supports the existing BORINGSSL_PREFIX mechanism — uses --prefix-link-name so Rust-side function names stay unprefixed while #[link_name] attributes carry the prefix for the linker
  5. During install, the bindings are placed at $INSTALL_DIR/share/rust/aws_lc_bindings.rs

Files added:

  • cmake/rust_bindings.cmake — Module containing the header discovery, prefix formatting, and bindgen invocation logic
  • cmake/rust_wrapper.h.in — Template header that aggregates all public headers for bindgen input

Call-outs:

  • The prefix symbols header (boringssl_prefix_symbols.h) is intentionally excluded from bindgen's input. The rationale is documented in the module-level comment in cmake/rust_bindings.cmake.
  • The rust_bindings target is not part of ALL. It is built on-demand when explicitly requested (--target rust_bindings) or automatically during cmake --install.
  • Platform-specific symbol prefix formatting (Apple/Win32 leading underscore) is handled by get_symbol_prefix_format().

Testing:

CI workflow added in .github/workflows/aws-lc-rs.yml (cmake-rust-bindings job) covering:

  • Linux (no prefix)
  • Linux with BORINGSSL_PREFIX=AWSLC
  • macOS (no prefix)
  • macOS with BORINGSSL_PREFIX=AWSLC
  • Windows (no prefix)

Each matrix entry verifies that bindings are generated, contain expected symbols, have correct prefix behavior, and compile as valid Rust.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.32%. Comparing base (ab1b674) to head (f33c27f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2999      +/-   ##
==========================================
+ Coverage   78.31%   78.32%   +0.01%     
==========================================
  Files         689      689              
  Lines      121007   121007              
  Branches    16996    16995       -1     
==========================================
+ Hits        94765    94782      +17     
+ Misses      25346    25329      -17     
  Partials      896      896              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Use bindgen's --raw-line to add #![allow(...)] directives directly
to the generated bindings file, so consumers don't need to suppress
warnings themselves. Covers the standard bindgen warnings (naming
conventions, dead_code, improper_ctypes, clippy) plus
unpredictable_function_pointer_comparisons which is triggered by
deriving PartialEq on structs with function pointer fields.

Remove the now-redundant #![allow(...)] lines from the CI
compile-check test.
Copy link
Copy Markdown
Contributor

@WillChilds-Klein WillChilds-Klein left a comment

Choose a reason for hiding this comment

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

very nice!

fail-fast: false
matrix:
include:
- os: ubuntu-latest
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.

Nit: Seeing that this is part of a work to flip everything internally, do we need to test on AL2023 or AL2?

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.

4 participants