Fix parse_cargo_tree_output misclassifying dev-dependencies as host deps (#3976)

Fix `parse_cargo_tree_output` incorrectly classifying
`[dev-dependencies]` as host dependencies when they follow
`[build-dependencies]` for the same crate.

This causes platform-conditional features to leak across platforms in
the generated BUILD files. For instance, the `tokio` feature `taskdump`
that can only be enabled on linux could leak to other platforms.

Example dependency tree that triggers the issue:
```
;my-crate v0.1.0 (/my-crate);;
`-- ;tokio v1.49.0;bytes,full,taskdump;
[build-dependencies]
`-- ;anyhow v1.0.100;default,std;
[dev-dependencies]
`-- ;tokio-test v0.4.4;;
    `-- ;tokio v1.49.0;bytes,full,taskdump; (*)
```

This PR also updates surrounding code in `parse_cargo_tree_output`. Let
me know if you'd prefer a minimal fix instead.
1 file changed
tree: 4a96bc2ac6b37bfd8e8e76c60f81101c0451640d
  1. .bazelci/
  2. .bcr/
  3. .github/
  4. cargo/
  5. crate_universe/
  6. docs/
  7. examples/
  8. extensions/
  9. ffi/
  10. nix/
  11. rust/
  12. test/
  13. tools/
  14. util/
  15. .bazelignore
  16. .bazelrc
  17. .clang-format
  18. .clippy.toml
  19. .envrc
  20. .gitattributes
  21. .gitignore
  22. .pre-commit-config.yaml
  23. .prettierrc.toml
  24. .rustfmt.toml
  25. .typos.toml
  26. ARCHITECTURE.md
  27. AUTHORS
  28. BUILD.bazel
  29. CODEOWNERS
  30. COMPATIBILITY.md
  31. CONTRIBUTING.md
  32. CONTRIBUTORS
  33. LICENSE.txt
  34. MODULE.bazel
  35. README.md
  36. version.bzl
  37. WORKSPACE.bazel
  38. WORKSPACE.bzlmod
README.md

Rust Rules

  • Postsubmit Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Starter repo

The fastest way to try this in an empty project is to click the green “Use this template” button on https://github.com/bazel-starters/rust.

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.