Skip to content

cargo_build_script_runner: parse cargo::metadata key/value pairs#3877

Merged
UebelAndre merged 1 commit intobazelbuild:mainfrom
sebas-zip:fix-cargo-metadata-dep-env
Mar 5, 2026
Merged

cargo_build_script_runner: parse cargo::metadata key/value pairs#3877
UebelAndre merged 1 commit intobazelbuild:mainfrom
sebas-zip:fix-cargo-metadata-dep-env

Conversation

@sebas-zip
Copy link
Contributor

@sebas-zip sebas-zip commented Mar 2, 2026

Summary

Fix cargo::metadata=KEY=VALUE handling in cargo_build_script_runner so metadata keys are propagated in Cargo-compatible form.

Before:

  • cargo::metadata=version_1_10_0=1
  • produced DEP_<links>_METADATA=version_1_10_0=1

After:

  • same input produces DEP_<links>_VERSION_1_10_0=1

Changes

  • Add a "metadata" parser branch in BuildScriptOutput::new.
  • Split metadata payload on first = and emit DepEnv("<KEY>=<VALUE>").
  • Preserve fallback behavior for malformed metadata payloads.
  • Add unit test: metadata_directive_maps_to_dep_env_key_value.

Motivation

Downstream links users (for example hdf5-metno) expect specific DEP_* metadata keys (DEP_HDF5_VERSION_*, DEP_HDF5_HAVE_*).

Testing

  • bazel --batch test //cargo/private/cargo_build_script_runner:test --remote_executor= --remote_cache= --bes_backend= --noshow_progress --color=no --curses=no

bazel test //test/cargo_build_script/metadata_dep_env:all are end to end integration tests

Closes #3876.

abrisco

This comment was marked as duplicate.

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

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

Thanks! Could you also implement an end-to-end test somewhere in //test/cargo_build_script that defines a cargo_build_script that emits this type of dep env and a consuming rust_test or other Rust rule that confirms the data is correct?

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

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

Looks great, thank you so much!

@UebelAndre UebelAndre enabled auto-merge March 5, 2026 00:05
auto-merge was automatically disabled March 5, 2026 00:11

Head branch was pushed to by a user without write access

@sebas-zip sebas-zip force-pushed the fix-cargo-metadata-dep-env branch from 40f9806 to 0645082 Compare March 5, 2026 00:36
@sebas-zip
Copy link
Contributor Author

thanks so much. I just tried to do some legacy testing of the old method too. I rebased to clean up the commits since I wasn't sure how commits are squashed to main. do you want to do another review? or okay to merge?

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thank you for the additional test case!

@UebelAndre UebelAndre enabled auto-merge March 5, 2026 00:42
@UebelAndre UebelAndre added this pull request to the merge queue Mar 5, 2026
Merged via the queue into bazelbuild:main with commit 43f0f76 Mar 5, 2026
3 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.

cargo::metadata forwarding doesn't produce Cargo-compatible DEP_<links>_<KEY> env vars

3 participants