docs: Add recommendations for lockfile (#3467)

I did some experiments on [this
example](https://github.com/bazelbuild/rules_rust/blob/e38fa8c2bc0990debceaf28daa4fcb2c57dcdc1c/examples/hello_world/MODULE.bazel#L25-L30)
to evaluate the `lockfile` attribute vs. using `MODULE.bazel.lock`:

I ran `bazel test //... --profile=...`. After every run, I did a `bazel
clean && bazel shutdown` to start clean.

1. Run (`MODULE.bazel.lock` file only): No `cargo-bazel` call found in
the profile generated
1. Run (add the `lockfile`, run `CARGO_BAZEL_REPIN=true bazel mod tidy`,
then `bazel test`): No `cargo-bazel` call found in the profile generated
1. Run (delete `MODULE.bazel.lock`): `cargo-bazel` was called, but cargo
splicing was very fast. The `MODULE.bazel.lock` was recreated
1. Run (delete`MODULE.bazel.lock` and run with `--lockfile_mode=off`):
`cargo-bazel` was called, similar to above

This suggests:

* If you have the `MODULE.bazel.lock` file up to date, no `cargo-bazel`
is called regardless of using the `lockfile` or not
* If the `MODULE.bazel.lock` is not tracked in VCS the `lockfile` seems
to be helpful and should be used
* Comparing the `MODULE.bazel.lock` file and the `lockfile` a bit more
in detail, shows they store similar information. The `lockfile` is a bit
more well structured json (for the rust specific content) while the
`MODULE.bazel.lock` file seems to store the entire content generated for
every crate in a single string.
1 file changed
tree: 20309b1a5cf30c4f12bec28c4f54bc13201f7c46
  1. .bazelci/
  2. .bcr/
  3. .github/
  4. cargo/
  5. crate_universe/
  6. docs/
  7. examples/
  8. extensions/
  9. ffi/
  10. nix/
  11. rust/
  12. test/
  13. tools/
  14. util/
  15. .bazelignore
  16. .bazelrc
  17. .clang-format
  18. .clippy.toml
  19. .envrc
  20. .gitattributes
  21. .gitignore
  22. .prettierrc.toml
  23. .rustfmt.toml
  24. ARCHITECTURE.md
  25. AUTHORS
  26. BUILD.bazel
  27. CODEOWNERS
  28. COMPATIBILITY.md
  29. CONTRIBUTING.md
  30. CONTRIBUTORS
  31. LICENSE.txt
  32. MODULE.bazel
  33. README.md
  34. version.bzl
  35. WORKSPACE.bazel
  36. WORKSPACE.bzlmod
README.md

Rust Rules

  • Postsubmit Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Community

General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust.

Documentation

Please refer to the full documentation.