Skip to content

Commit

Permalink
Fix cc_common_link when using sibling repository layout (#2643)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yuzhy8701 committed May 13, 2024
1 parent 6a06c81 commit c88ba10
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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):]

Expand Down

0 comments on commit c88ba10

Please sign in to comment.