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

Rust Analyzer: Generate rust-project.json without explicit target list #1010

Merged
merged 18 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ tasks:
bazel: "rolling"
ubuntu1804:
name: "Min Bazel Version"
bazel: "3.5.0"
bazel: "4.0.0"
platform: ubuntu1804
build_targets: *default_linux_targets
test_targets: *default_linux_targets
ubuntu1804_with_aspects:
name: "Min Bazel Version With Aspects"
bazel: "3.5.0"
bazel: "4.0.0"
platform: ubuntu1804
build_targets: *default_linux_targets
test_targets: *default_linux_targets
Expand Down Expand Up @@ -181,6 +181,11 @@ tasks:
platform: ubuntu2004
run_targets:
- "//test/rustfmt:test_runner"
rust_analyzer_tests:
name: Rust-Analyzer Tests
platform: ubuntu2004
run_targets:
- "//test/rust_analyzer:rust_analyzer_test"
ubuntu2004_examples:
name: Examples
platform: ubuntu2004
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@

# BazelCI
bazelci.py

# rust-analyzer
rust-project.json
2 changes: 1 addition & 1 deletion docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ A rule defining an incompatible flag.
rust_analyzer(<a href="#rust_analyzer-name">name</a>, <a href="#rust_analyzer-targets">targets</a>)
</pre>

Produces a rust-project.json for the given targets. Configure rust-analyzer to load the generated file via the linked projects mechanism.
Deprecated: gen_rust_project can now create a rust-project.json without a rust_analyzer rule.


**ATTRIBUTES**
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rust_repositories()
```

The rules are under active development, as such the lastest commit on the
`main` branch should be used. `main` is only tested against `3.5.0` as the
`main` branch should be used. `main` is only tested against `4.0.0` as the
minimum supported version of Bazel. Though previous versions may still be
functional in certain environments.

Expand Down
35 changes: 7 additions & 28 deletions docs/rust_analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

For [non-Cargo projects](https://rust-analyzer.github.io/manual.html#non-cargo-based-projects),
[rust-analyzer](https://rust-analyzer.github.io/) depends on a `rust-project.json` file at the
root of the project that describes its structure. The `rust_analyzer` rule facilitates generating
root of the project that describes its structure. The `rust_analyzer` rule facilitates generating
such a file.

### Setup
Expand All @@ -32,32 +32,11 @@ can also set `include_rustc_srcs = True` on any `rust_repository` or
`rust_repositories` calls in the workspace but the environment variable
has higher priority and can override the attribute.

Finally, add a rule to the root `BUILD` file like the following.

```python
load("@rules_rust//rust:defs.bzl", "rust_analyzer")

rust_analyzer(
name = "rust_analyzer",
targets = [
# all the binary/library targets you want in the rust-project.json
],
)
```

A list of `rust_analyzer` compatible targets can be found by usign the following query:

```bash
bazel query 'kind("rust_*library|rust_binary", //...:all)'
```

Note: __All `rust_*` targets provided to the root rust_analyzer must have `//visibility:public`.__

Run `bazel run @rules_rust//tools/rust_analyzer:gen_rust_project` whenever
dependencies change to regenerate the `rust-project.json` file. It should be
added to `.gitignore` because it is effectively a build artifact. Once the
`rust-project.json` has been generated in the project root, rust-analyzer can
pick it up upon restart.
Finally, run `bazel run @rules_rust//tools/rust_analyzer:gen_rust_project`
whenever dependencies change to regenerate the `rust-project.json` file. It
should be added to `.gitignore` because it is effectively a build artifact.
Once the `rust-project.json` has been generated in the project root,
rust-analyzer can pick it up upon restart.

#### VSCode

Expand Down Expand Up @@ -100,7 +79,7 @@ to ensure a `rust-project.json` file is created and up to date when the editor i
rust_analyzer(<a href="#rust_analyzer-name">name</a>, <a href="#rust_analyzer-targets">targets</a>)
</pre>

Produces a rust-project.json for the given targets. Configure rust-analyzer to load the generated file via the linked projects mechanism.
Deprecated: gen_rust_project can now create a rust-project.json without a rust_analyzer rule.


**ATTRIBUTES**
Expand Down
33 changes: 6 additions & 27 deletions docs/rust_analyzer.vm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

For [non-Cargo projects](https://rust-analyzer.github.io/manual.html#non-cargo-based-projects),
[rust-analyzer](https://rust-analyzer.github.io/) depends on a `rust-project.json` file at the
root of the project that describes its structure. The `rust_analyzer` rule facilitates generating
root of the project that describes its structure. The `rust_analyzer` rule facilitates generating
such a file.

### Setup
Expand All @@ -26,32 +26,11 @@ can also set `include_rustc_srcs = True` on any `rust_repository` or
`rust_repositories` calls in the workspace but the environment variable
has higher priority and can override the attribute.

Finally, add a rule to the root `BUILD` file like the following.

```python
load("@rules_rust//rust:defs.bzl", "rust_analyzer")

rust_analyzer(
name = "rust_analyzer",
targets = [
# all the binary/library targets you want in the rust-project.json
],
)
```

A list of `rust_analyzer` compatible targets can be found by usign the following query:

```bash
bazel query 'kind("rust_*library|rust_binary", //...:all)'
```

Note: __All `rust_*` targets provided to the root rust_analyzer must have `//visibility:public`.__

Run `bazel run @rules_rust//tools/rust_analyzer:gen_rust_project` whenever
dependencies change to regenerate the `rust-project.json` file. It should be
added to `.gitignore` because it is effectively a build artifact. Once the
`rust-project.json` has been generated in the project root, rust-analyzer can
pick it up upon restart.
Finally, run `bazel run @rules_rust//tools/rust_analyzer:gen_rust_project`
whenever dependencies change to regenerate the `rust-project.json` file. It
should be added to `.gitignore` because it is effectively a build artifact.
Once the `rust-project.json` has been generated in the project root,
rust-analyzer can pick it up upon restart.

#### VSCode

Expand Down
6 changes: 6 additions & 0 deletions rust/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//rust/private:rust_analyzer.bzl", "rust_analyzer_detect_sysroot")
load("//rust/private:stamp.bzl", "stamp_build_setting")

bzl_library(
Expand All @@ -13,3 +14,8 @@ bzl_library(
)

stamp_build_setting(name = "stamp")

rust_analyzer_detect_sysroot(
name = "rust_analyzer_detect_sysroot",
visibility = ["//visibility:public"],
)
Loading