crate_universe: use repository_ctx APIs instead of `cp`/`find` in `local_crate_mirror` (#4427) Fixes #4426. Replaces `cp -r` and the `find` + `read` loop with a Starlark copy (`readdir`, `read`, `file`) plus `repository_ctx.watch_tree`, so `local_crate_mirror` works on Windows. - Files are copied rather than symlinked, so the mirror stays self-contained. An earlier revision of this PR used symlinks and failed `local_path (external)`: that test vendors into `mktemp -d`, and the Linux sandbox hides `/tmp`. - `legacy_utf8 = False` keeps the copy byte-exact on Bazel 7. - The walk passes `watch = "no"` because `watch_tree` already covers the tree. With the default watches, deleting a subdirectory of the crate failed the refetch with "Inconsistent filesystem operations". - `watch_tree` is called before the copy, so an edit made during the copy still refetches. - `repository_ctx` cannot read file modes, so every copied file is executable. `cp -r` kept modes, but this keeps any script a build script runs working. - Symlinks inside the crate are followed. `cp -r` kept them as links. This does what the #3025 review asked for (no shell, `watch_tree`). That review left `watch` erroring on out-of-workspace paths as an open concern; it is retested below. Tested with stock rules_rust 0.75.0 plus this change, using the repro in #4426: - The repro builds on Bazel 8.7.0 and 7.4.1. The mirror has no symlinks, and every file matches its source byte for byte. - A file of all 256 byte values, a UTF-8 file and nested directories copy byte-exact on both versions. - An edit to the linked crate rebuilds it: appending `compile_error!` fails the build and reverting it builds again. This holds for in-workspace paths and for absolute out-of-workspace paths. - Adding a nested directory to the crate shows up in the mirror, and deleting it removes it (3 cycles, no errors). - Our monorepo's Windows build, which failed as in #4426, passes with the symlink revision of this change. The copy revision has not been run on Windows yet. `repository_ctx.copy` (Bazel 10) could replace the walk once that is the minimum version.
This repository provides rules for building Rust projects with Bazel.
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.
General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust.
Please refer to the full documentation.