Handle files from external repos (fix breaking change in Bazel 3.7.0) (#2138)

Fixes https://github.com/bazelbuild/rules_rust/issues/1780

In Bazel 3.7.0, the path returned by `build_file_path` changed
(https://github.com/bazelbuild/bazel/issues/12344), it no longer
contains the `external/<repo>` prefix for external files. This breaks
the expectations of this rule in the [`paths.relativize`
function](https://github.com/bazelbuild/bazel-skylib/blob/main/docs/paths_doc.md#pathsrelativize)
call.

In this PR I prepend the `workspace_root` (`external/<repo>`) to
`build_file_path` (`<path/in/the/repo>`), and use `path`
(`external/<repo>/path/in/the/repo`) instead of `short_path`
(`../<repo>/path/in/the/repo`).

For files that are generated in different configurations I need to strip
the `root` which contains the
`bazel-out/darwin-fastbuild-ST-a1a0f4088294/bin/` that will never appear
in the `package_root` path.

~Note.- I will probably need some help to add tests for this change~
I've tried to add one test

---------

Co-authored-by: UebelAndre <github@uebelandre.com>
4 files changed
tree: a4517633c599a770938804a59c5e81a683a5bd78
  1. .bazelci/
  2. .github/
  3. bindgen/
  4. cargo/
  5. crate_universe/
  6. docs/
  7. examples/
  8. proto/
  9. rust/
  10. test/
  11. tools/
  12. util/
  13. wasm_bindgen/
  14. .bazelignore
  15. .bazelrc
  16. .clang-format
  17. .gitattributes
  18. .gitignore
  19. .rustfmt.toml
  20. ARCHITECTURE.md
  21. AUTHORS
  22. BUILD.bazel
  23. CODEOWNERS
  24. COMPATIBILITY.md
  25. CONTRIBUTING.md
  26. CONTRIBUTORS
  27. LICENSE.txt
  28. MODULE.bazel
  29. README.md
  30. version.bzl
  31. 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.