diff options
author | yuzhy8701 <18453608+yuzhy8701@users.noreply.github.com> | 2024-05-13 06:34:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-13 13:34:12 +0000 |
commit | c88ba10b51a7bc9a4c4f2a316ac8221d0612ee98 (patch) | |
tree | a94a068e293e1e2c97111ba7f9dbd43556064747 | |
parent | 6a06c81086bc81c6b6a7918c5e3fb2f517b80d4a (diff) | |
download | bazelbuild-rules_rust-upstream-main.tar.gz |
Fix cc_common_link when using sibling repository layout (#2643)upstream-main
Linking with cc_common is broken for external repositories if you also
specify `--experimental_sibling_repository_layout`.
The rule would complain `The package dir path should be a prefix of the
crate_info.output.path`. It happens because the package path derived
from `bin_dir`, `workspace_root` and `package` did not match how sibling
layout handles external repositories.
This change ignores the `workspace_root` component if the path signifies
the usage of sibling layout, as it is not needed.
-rw-r--r-- | rust/private/rustc.bzl | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 474d1a61..98806f1a 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -1391,13 +1391,18 @@ def rustc_compile_action( # The path to the package dir, including a trailing "/". package_dir = ctx.bin_dir.path + "/" - if ctx.label.workspace_root: + + # For external repositories, workspace root is not part of the output + # path when sibling repository layout is used (the repository name is + # part of the bin_dir). This scenario happens when the workspace root + # starts with "../" + if ctx.label.workspace_root and not ctx.label.workspace_root.startswith("../"): package_dir = package_dir + ctx.label.workspace_root + "/" if ctx.label.package: package_dir = package_dir + ctx.label.package + "/" if not crate_info.output.path.startswith(package_dir): - fail("The package dir path {} should be a prefix of the crate_info.output.path {}", package_dir, crate_info.output.path) + fail("The package dir path", package_dir, "should be a prefix of the crate_info.output.path", crate_info.output.path) output_relative_to_package = crate_info.output.path[len(package_dir):] |