Skip to content

Fix CARGO_MANIFEST_DIR when transform_sources moves crate root to bazel-out#3953

Open
0xbeefd1ed wants to merge 1 commit intobazelbuild:mainfrom
0xbeefd1ed:fix-bevy
Open

Fix CARGO_MANIFEST_DIR when transform_sources moves crate root to bazel-out#3953
0xbeefd1ed wants to merge 1 commit intobazelbuild:mainfrom
0xbeefd1ed:fix-bevy

Conversation

@0xbeefd1ed
Copy link
Copy Markdown

@0xbeefd1ed 0xbeefd1ed commented Apr 7, 2026

Summary

When a rust_library (or similar rule) has a mix of generated and non-generated files in compile_data, transform_sources symlinks all source files into bazel-out/. However, CARGO_MANIFEST_DIR was still computed from ctx.label.workspace_root and ctx.label.package, pointing to the original source directory. This caused proc-macros that read Cargo.toml (e.g., Bevy's #[derive(Component)]) to fail with "Cargo manifest does not exist" errors in sandboxed builds on Linux / macOS.

This change derives CARGO_MANIFEST_DIR from the actual crate root location when the crate root has been transformed, using crate_info.root.root.path combined with the package path.

Reproduction

  1. Create a rust_library with a generated file in compile_data and Cargo.toml also in compile_data
  2. Use a proc-macro that reads Cargo.toml via CARGO_MANIFEST_DIR (e.g., Bevy's derive macros)
  3. Build with sandboxing enabled (default on Linux)
  4. Observe: proc-macro panics because Cargo.toml is not found at the CARGO_MANIFEST_DIR path

Fix

  • If crate_info.root.is_source, use the existing label-based path (no behavior change)
  • Otherwise, compute the manifest directory from crate_info.root.root.path + the workspace/package path, which reflects the actual bazel-out/ layout

Disclosure

This PR was created with assistance from Claude Code.

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 7, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@scentini scentini added the awaiting-response Maintainers have responded to the pull-request or thread and now await contributor responses. label Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-response Maintainers have responded to the pull-request or thread and now await contributor responses.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants