Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo-bazel: buildifier may fail for no such file or directory #2972

Open
ashi009 opened this issue Oct 30, 2024 · 1 comment
Open

cargo-bazel: buildifier may fail for no such file or directory #2972

ashi009 opened this issue Oct 30, 2024 · 1 comment

Comments

@ashi009
Copy link

ashi009 commented Oct 30, 2024

When generating many build files with cargo-bazel in crates_vendor() rule. We can constantly see errors when running crates_vendor as part of pre-commit hook:

buildifier: open /.../third_party/rust/crates/BUILD.percent-encoding-1.0.1.bazel: no such file or directory
Error: Failed to run buildifier on /.../third_party/rust/crates/BUILD.percent-encoding-1.0.1.bazel

However, when run crates_vendor directly won't trigger this.

After looking into the source code, and relevant rust issues, fs::write should be the culprit.

https://github.com/bazelbuild/rules_rust/blob/4e593b6cc3e1dab70eed5fdec239ffc0b4179b91/crate_universe/src/rendering.rs#L820C13-L820C22

As pointed out in rust-lang/rust#51775, fs::write doesn't force a sync in the end, so the newly created file may still sit in the os cache, which cannot be accessed by another process.

edit:

We are also seeing random errors from

fs::remove_dir_all(&vendor_dir)

Directory not empty (os error 66).

@illicitonion
Copy link
Collaborator

Good spot! Feel free to send a PR calling sync after the write!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants