[Bugfix] Convert metadata keys to screaming snake case instead of screaming kebab case in `cargo_build_script_runner` (#2682)

The `cargo_build_script_runner` currently converts the keys from
`cargo:KEY=VALUE` metadata build script output lines into uppercase.
This is not completely correct, however, because Cargo converts those
keys to uppercase AND replaces dashes with underscores (effectively
doing a conversion to SCREAMING_SNAKE_CASE).

To verify that Cargo is indeed doing the dash-to-underscore conversion,
have a look at
https://github.com/rust-lang/cargo/blob/10b7d384352f6d9a39f609de44476f815fc792a2/src/cargo/core/compiler/custom_build.rs#L46,
which is the code responsible for building the
`DEP_{crate-name}_{metadata-key}` env variables in Cargo. The code is
```rust
cmd.env(
    &format!("DEP_{}_{}", super::envify(&name), super::envify(key)),
    value,
);
```
where `super::envify()` is defined as
```rust
fn envify(s: &str) -> String {
    s.chars()
        .flat_map(|c| c.to_uppercase())
        .map(|c| if c == '-' { '_' } else { c })
        .collect()
}
```

This PR adds the dash-to-underscore conversion to
`cargo_build_script_runner`.
1 file changed
tree: b91f517049ab922b78430dbe60a551cd795777c6
  1. .bazelci/
  2. .bcr/
  3. .github/
  4. bindgen/
  5. cargo/
  6. crate_universe/
  7. docs/
  8. examples/
  9. ffi/
  10. nix/
  11. proto/
  12. rust/
  13. test/
  14. tools/
  15. util/
  16. wasm_bindgen/
  17. .bazelignore
  18. .bazelrc
  19. .clang-format
  20. .envrc
  21. .gitattributes
  22. .gitignore
  23. .prettierrc.toml
  24. .rustfmt.toml
  25. ARCHITECTURE.md
  26. AUTHORS
  27. BUILD.bazel
  28. CODEOWNERS
  29. COMPATIBILITY.md
  30. CONTRIBUTING.md
  31. CONTRIBUTORS
  32. LICENSE.txt
  33. MODULE.bazel
  34. README.md
  35. version.bzl
  36. WORKSPACE.bazel
README.md

Rust Rules

  • Postsubmit Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Community

General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust.

Documentation

Please refer to the full documentation.