commit | 2e460de57b94f0cbe0aaf34043f4a42094ce4804 | [log] [tgz] |
---|---|---|
author | William Smith <87392567+william-smith-skydio@users.noreply.github.com> | Wed Apr 03 02:02:06 2024 -0700 |
committer | GitHub <noreply@github.com> | Wed Apr 03 09:02:06 2024 +0000 |
tree | d4b667dd87d27112bebfb039b3db9b95ec7a1056 | |
parent | 127b9b869f8fcb901bbfc01b0b41d7f86d854624 [diff] |
Add support for `--compile_one_dependency` (#2598) The `--compile_one_dependency` flag ([docs](https://bazel.build/docs/user-manual#compile-one-dependency)) changes `bazel build` etc. to accept a file path and build the target corresponding to that file. This is useful for check-on-save with rust-analyzer in combination with the newly-added `$saved_file` command substitution (https://github.com/rust-lang/rust-analyzer/pull/15476). Officially `--compile_one_dependency` only supports the builtin C++ and Java rules, but an [undocumented flag](https://github.com/bazelbuild/bazel/blob/7.1.1/src/main/java/com/google/devtools/build/lib/packages/Attribute.java#L102) can be added to attributes to turn them into sources supporting `--compile_one_dependency`. I'm not sure what the status of this support is, but it appears to work for all bazel versions up to at least 7.1.1, and if support is removed the flag is pretty harmless. Before this change: ``` > bazel build --compile_one_dependency tools/rust_analyzer/main.rs WARNING: Target pattern parsing failed. ERROR: Couldn't find dependency on target '//tools/rust_analyzer:main.rs' ERROR: Couldn't find dependency on target '//tools/rust_analyzer:main.rs' INFO: Elapsed time: 0.956s INFO: 0 processes. ERROR: Build did NOT complete successfully ``` After: ``` > bazel build --compile_one_dependency tools/rust_analyzer/main.rs INFO: Analyzed target //tools/rust_analyzer:gen_rust_project (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //tools/rust_analyzer:gen_rust_project up-to-date: bazel-bin/tools/rust_analyzer/gen_rust_project INFO: Elapsed time: 0.341s, Critical Path: 0.00s INFO: 1 process: 1 internal. INFO: Build completed successfully, 1 total action ``` --------- Co-authored-by: Daniel Wagner-Hall <dwagnerhall@apple.com>
This repository provides rules for building Rust projects with Bazel.
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.