Skip to content

Support exporting build vars from -sys crates to build depending C code - #1184

Closed
glebpom wants to merge 2 commits into
aws:mainfrom
nervix-io:export-build-vars
Closed

glebpom wants to merge 2 commits into
aws:mainfrom
nervix-io:export-build-vars

Conversation

@glebpom

@glebpom glebpom commented Jul 20, 2026 •

Copy link
Copy Markdown

Description of changes:

Currently, the sys crates export include directories and linker directives, but downstream Cargo build scripts cannot reliably determine the exact native library artifacts produced by AWS-LC. This is especially problematic when compiling additional C code against AWS-LC because source builds use version-prefixed library names.

This change exports additional build metadata from aws-lc-sys and aws-lc-fips-sys:

  • libdir
  • libcrypto_path
  • libssl_path when the ssl feature is enabled
  • link_kind

The metadata is emitted consistently for CC builds, CMake builds, and system-library builds. Platform-aware artifact naming is included for static and dynamic libraries on Unix, Apple platforms, MinGW, and MSVC.

This enables downstream build scripts to pass AWS-LC’s exact headers and libraries to native build systems such as CMake, without rebuilding AWS-LC or guessing version-prefixed artifact names.

Call-outs:

The new metadata becomes an interface consumed by direct Cargo dependents through versioned DEP_AWS_LC_* and DEP_AWS_LC_FIPS_* environment variables.

Exact absolute artifact paths are exported intentionally because the existing logical library names are insufficient for native build systems that require a concrete library file.

Special review attention would be helpful for:

  • Cross-platform library filename mapping.
  • Static versus dynamic link_kind reporting.
  • Consistency between CC, CMake, and system-library builders.
  • Conditional export of libssl_path when the ssl feature is enabled.

Existing Rust linker directives and linking behavior are unchanged.

Testing:

The links-testing crate now verifies that:

  • The exported library directory exists.
  • The exported libcrypto path exists.
  • The artifact belongs to the exported library directory.
  • The linkage kind is either static or dylib.

The metadata was tested with:

  • aws-lc-sys using the CC builder.
  • aws-lc-sys using the CMake builder.
  • aws-lc-fips-sys using its CMake build.
  • A downstream native librdkafka build consuming the exported AWS-LC headers and exact library paths.

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.

@glebpom
glebpom marked this pull request as ready for review July 20, 2026 19:28
@glebpom
glebpom requested a review from a team as a code owner July 20, 2026 19:28
@codecov-commenter

codecov-commenter commented Jul 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.76%. Comparing base (c358484) to head (92eb23d).
⚠️ Report is 423 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1184      +/-   ##
==========================================
- Coverage   95.80%   92.76%   -3.04%     
==========================================
  Files          61       71      +10     
  Lines        8143    10334    +2191     
  Branches        0    10334   +10334     
==========================================
+ Hits         7801     9586    +1785     
- Misses        342      453     +111     
- Partials        0      295     +295     

☔ View full report in Codecov by Harness.
📢 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.

@glebpom glebpom changed the title Support exporting build vars from -sys crates to build dependig C code Support exporting build vars from -sys crates to build depending C code Jul 22, 2026
The ("windows", _, Static) arm produced the same name as the catch-all
static arm, tripping clippy::match_same_arms under -W clippy::pedantic.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread builder/main.rs
Comment on lines +1436 to +1440
assert!(
ssl_path.is_file(),
"AWS-LC libssl artifact not found: {}",
ssl_path.display()
);

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.

Since asserts fail the build for all consumers (not just ones reading these vars), could these be downgraded to cargo:warning?

Comment thread links-testing/build.rs
@@ -31,19 +31,37 @@ fn main() {
}

fn build_and_link(links: &str, target_name: &str) {

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.

Our CI job for "links-testing" should be extended to cover a few more build configurations:

  • Windows dynamic -- both *-windows-gnu and *-windows-mscv
  • ssl consumer coverage -- an ssl-enabled feature in links-testing that asserts DEP_*_LIBSSL_PATH

Comment thread builder/main.rs
fn library_filename(self, name: &str) -> String {
match (target_os().as_str(), target_env().as_str(), self) {
("windows", "msvc", _) => format!("{name}.lib"),
("windows", _, Self::Dynamic) => format!("lib{name}.dll.a"),

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.

I'm not sure this is true for our prefixed source builds. The sys crates' CMakeLists.txt only sets IMPORT_PREFIX for MSVC; on MinGW the import library keeps CMake's default lib prefix, so we'd get libcrypto.dll.a while this predicts libaws_lc_X_Y_Z_crypto.dll.a.

  • With the assert! below, this might break AWS_LC_SYS_STATIC=0 builds on windows-gnu, which currently link fine because ld falls back to the DLL directly.

Comment thread builder/main.rs
println!("cargo:libcrypto_path={}", crypto_path.display());
println!("cargo:link_kind={}", output_lib_type.rust_lib_type());

if cfg!(feature = "ssl") {

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.

We need to add an ssl-enabled feature to links-testing that asserts DEP_*_LIBSSL_PATH the same way as libcrypto, plus a matrix entry to the links-crate-tests job.

@justsmth

Copy link
Copy Markdown
Contributor

I've stacked five follow-up commits addressing my review feedback on top of your branch here: https://github.com/justsmth/aws-lc-rs/tree/pr-1184-review-fixes

Since this PR comes from an organization-owned fork, I can't push to the branch directly (GitHub doesn't support maintainer edits for org forks).

My changes cover:

  • setting IMPORT_PREFIX for non-MSVC toolchains so MinGW shared builds produce the prefixed lib*.dll.a the metadata predicts;
  • downgrading the artifact asserts to warn-and-skip (links-testing now enforces presence in CI instead);
  • libssl_path validation + ssl feature coverage in links-testing;
  • the expanded links-crate-tests CI matrix (dynamic linkage, ssl, windows-gnu); and
  • a README note about link-time vs runtime artifacts on Windows.

You can bring them into this PR with:

git pull https://github.com/justsmth/aws-lc-rs pr-1184-review-fixes
git push

I'd also be fine with closing this PR and creating a separate one with these changes, if you'd prefer.

NOTE: my changes grow the CI matrix and exercise some combinations for the first time (ssl on macOS/Windows, windows-gnu dynamic), so we may see new failures that I can help triage.

@glebpom

glebpom commented Jul 23, 2026

Copy link
Copy Markdown
Author

@justsmth Thanks for the review! Since you've already fixed the remaining issues - please proceed with merging your PR, I'm totally fine with that

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