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

Add rust_analyzer rule to generate a rust-project.json #505

Merged
merged 57 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
19d0e8f
add rust-src to known shas
benbrittain Jul 27, 2020
432444e
rust-analyzer support
benbrittain Jul 24, 2020
82895e5
populate sysroot
benbrittain Jul 27, 2020
29bc845
use workspace_root instead of path hack
benbrittain Jul 29, 2020
8b12f2d
generate correct cfgs & workspace markers
benbrittain Aug 2, 2020
db78181
select proper source file
benbrittain Aug 2, 2020
f94e79c
add basic example generating rust-project.json
benbrittain Aug 2, 2020
4f8b492
fix example
benbrittain Aug 2, 2020
999f5df
implement suggested fixes
benbrittain Aug 10, 2020
3082f7a
Merge remote-tracking branch 'upstream/master'
djmarcin Nov 24, 2020
610f3ae
Allow specifying sha256 for non-blessed nightly versions
djmarcin Nov 24, 2020
18283bc
Hardcoded paths and excessive debugging
djmarcin Nov 24, 2020
b1d24bc
fix formatting
djmarcin Nov 24, 2020
8bbd77b
remove debug statements
djmarcin Nov 24, 2020
9eb96ed
Remove sysroot code, simplify file generation
djmarcin Nov 24, 2020
e1d451a
clippy stuff
djmarcin Nov 25, 2020
a6dcdd3
Move to rust/private
djmarcin Nov 25, 2020
536cf28
Refactor generation code
djmarcin Nov 25, 2020
cfedaa8
Merge remote-tracking branch 'upstream/master' into rust-analyzer
djmarcin Nov 25, 2020
7ebab90
Keep rustc-src in a subdirectory
djmarcin Nov 26, 2020
a5e2f9b
Proc macro support and more standard src location
djmarcin Nov 26, 2020
77f8c84
Fix include! macros
djmarcin Nov 26, 2020
1530692
revert extraneous clippy change
djmarcin Nov 26, 2020
8ab7fb3
Handle the rule at any depth in the workspace
djmarcin Nov 26, 2020
9703cbb
revert extraneous changes
djmarcin Nov 26, 2020
a522e5d
Remove CARGO_MANIFEST_DIR since it doesn't appear to work
djmarcin Nov 26, 2020
0f487c9
Fix example
djmarcin Nov 26, 2020
005d389
update shas
djmarcin Nov 26, 2020
d1d8bef
Update documentation
djmarcin Nov 27, 2020
dfcabb6
Regenerate documentation
djmarcin Nov 27, 2020
28fd0b0
Provide a utility binary to fill exec-root automatically
djmarcin Dec 2, 2020
cd0796f
Merge remote-tracking branch 'upstream/master' into rust-analyzer
djmarcin Dec 2, 2020
eca1cd9
Add type annotations and fix comment
djmarcin Dec 2, 2020
01d365a
Merge remote-tracking branch 'upstream/master' into rust-analyzer
djmarcin Dec 4, 2020
4926725
Regenerate documentation
djmarcin Dec 4, 2020
fa42c63
review comments
djmarcin Dec 7, 2020
49cf693
Merge remote-tracking branch 'upstream/master' into rust-analyzer
djmarcin Dec 7, 2020
b573ffb
Update shas
djmarcin Dec 7, 2020
049ee0c
Fix typo
djmarcin Dec 8, 2020
226cc95
Always add test and debug_assertions cfg values
djmarcin Dec 8, 2020
dd6e2fb
Handle missing attrs (e.g. rust_proto_library rules)
djmarcin Dec 8, 2020
d4668d0
Handle when sha256 is not passed for rustc-src
djmarcin Dec 11, 2020
a0df8c5
Merge remote-tracking branch 'upstream/master' into rust-analyzer
djmarcin Dec 11, 2020
b720d46
Merge remote-tracking branch 'upstream/main' into rust-analyzer
djmarcin Jan 31, 2021
73b0287
Update for review comments
djmarcin Jan 31, 2021
d408804
Fix args to find_proc_macro_dylib_path
djmarcin Feb 1, 2021
acd6c70
simplify with getattr
djmarcin Feb 1, 2021
a00d1a0
trim command output
djmarcin Feb 3, 2021
bb92b67
Merge branch 'main' into rust-analyzer
djmarcin Feb 14, 2021
8702431
fix merge
djmarcin Feb 14, 2021
a3a1ddb
Refactor to use command line flags and bazel info to determine workspace
djmarcin Feb 14, 2021
2b0d3e3
Use the new rust_common.crate_info, but now this OOMs...
djmarcin Feb 14, 2021
4a55fb8
Make buildifier happy
djmarcin Feb 14, 2021
5a1d449
Regenerate documentation
djmarcin Feb 14, 2021
d5d58a0
Regenerate known_shas
djmarcin Feb 14, 2021
227ece9
Remove extra /../ that isn't actually necessary
djmarcin Feb 14, 2021
1aa7f8e
Remove debugging statement
djmarcin Feb 14, 2021
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
11 changes: 11 additions & 0 deletions docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ PAGES = {
"rust_toolchain_repository",
"rust_toolchain_repository_proxy",
],
"rust_workspace": [
"rust_workspace",
],
"rust_clippy": [
"rust_clippy",
"rust_clippy_aspect",
],
"rust_analyzer": [
"rust_analyzer",
"rust_analyzer_aspect",
]
}

[
Expand Down
5 changes: 5 additions & 0 deletions docs/all.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ load(
_rust_doc_test = "rust_doc_test",
_rust_library = "rust_library",
_rust_test = "rust_test",
_rust_clippy = "rust_clippy",
_rust_analyzer = "rust_analyzer",
)
load(
"@io_bazel_rules_rust//rust:toolchain.bzl",
Expand Down Expand Up @@ -80,3 +82,6 @@ rust_repositories = _rust_repositories
rust_repository_set = _rust_repository_set
rust_toolchain_repository = _rust_toolchain_repository
rust_toolchain_repository_proxy = _rust_toolchain_repository_proxy

rust_clippy = _rust_clippy
rust_analyzer = _rust_analyzer
81 changes: 80 additions & 1 deletion docs/flatten.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Rust rules

* [cargo_build_script](#cargo_build_script)
* [rust_analyzer](#rust_analyzer)
* [rust_analyzer_aspect](#rust_analyzer_aspect)
* [rust_benchmark](#rust_benchmark)
* [rust_binary](#rust_binary)
* [rust_bindgen](#rust_bindgen)
* [rust_bindgen_library](#rust_bindgen_library)
* [rust_bindgen_toolchain](#rust_bindgen_toolchain)
* [rust_clippy](#rust_clippy)
* [rust_clippy_aspect](#rust_clippy_aspect)
* [rust_doc](#rust_doc)
* [rust_doc_test](#rust_doc_test)
* [rust_grpc_library](#rust_grpc_library)
Expand All @@ -20,6 +24,26 @@
* [rust_toolchain_repository_proxy](#rust_toolchain_repository_proxy)
* [rust_wasm_bindgen](#rust_wasm_bindgen)
* [rust_wasm_bindgen_toolchain](#rust_wasm_bindgen_toolchain)
* [rust_workspace](#rust_workspace)


<a id="#rust_analyzer"></a>

## rust_analyzer

<pre>
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.

**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="rust_analyzer-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="rust_analyzer-targets"></a>targets | List of all targets to be included in the index | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |


<a id="#rust_benchmark"></a>
Expand Down Expand Up @@ -289,6 +313,60 @@ The tools required for the `rust_bindgen` rule.
| <a id="rust_bindgen_toolchain-rustfmt"></a>rustfmt | The label of a <code>rustfmt</code> executable. If this is provided, generated sources will be formatted. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |


<a id="#rust_clippy"></a>

## rust_clippy

<pre>
rust_clippy(<a href="#rust_clippy-name">name</a>, <a href="#rust_clippy-deps">deps</a>)
</pre>

Executes the clippy checker on a specific target.

Similar to `rust_clippy_aspect`, but allows specifying a list of dependencies within the build system.

For example, given the following example targets:

```python
package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library", "rust_test")

rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)

rust_test(
name = "greeting_test",
srcs = ["tests/greeting.rs"],
deps = [":hello_lib"],
)
```

Rust clippy can be set as a build target with the following:

```python
rust_clippy(
name = "hello_library_clippy",
testonly = True,
deps = [
":hello_lib",
":greeting_test",
],
)
```


**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="rust_clippy-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="rust_clippy-deps"></a>deps | - | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |


<a id="#rust_doc"></a>

## rust_doc
Expand Down Expand Up @@ -803,7 +881,7 @@ Run the test with `bazel build //hello_lib:hello_lib_test`.

<pre>
rust_toolchain(<a href="#rust_toolchain-name">name</a>, <a href="#rust_toolchain-binary_ext">binary_ext</a>, <a href="#rust_toolchain-cargo">cargo</a>, <a href="#rust_toolchain-clippy_driver">clippy_driver</a>, <a href="#rust_toolchain-debug_info">debug_info</a>, <a href="#rust_toolchain-default_edition">default_edition</a>, <a href="#rust_toolchain-dylib_ext">dylib_ext</a>,
<a href="#rust_toolchain-exec_triple">exec_triple</a>, <a href="#rust_toolchain-opt_level">opt_level</a>, <a href="#rust_toolchain-os">os</a>, <a href="#rust_toolchain-rust_doc">rust_doc</a>, <a href="#rust_toolchain-rust_lib">rust_lib</a>, <a href="#rust_toolchain-rustc">rustc</a>, <a href="#rust_toolchain-rustc_lib">rustc_lib</a>, <a href="#rust_toolchain-rustfmt">rustfmt</a>,
<a href="#rust_toolchain-exec_triple">exec_triple</a>, <a href="#rust_toolchain-opt_level">opt_level</a>, <a href="#rust_toolchain-os">os</a>, <a href="#rust_toolchain-rust_doc">rust_doc</a>, <a href="#rust_toolchain-rust_lib">rust_lib</a>, <a href="#rust_toolchain-rustc">rustc</a>, <a href="#rust_toolchain-rustc_lib">rustc_lib</a>, <a href="#rust_toolchain-rustc_src">rustc_src</a>, <a href="#rust_toolchain-rustfmt">rustfmt</a>,
<a href="#rust_toolchain-staticlib_ext">staticlib_ext</a>, <a href="#rust_toolchain-stdlib_linkflags">stdlib_linkflags</a>, <a href="#rust_toolchain-target_triple">target_triple</a>)
</pre>

Expand Down Expand Up @@ -867,6 +945,7 @@ See @io_bazel_rules_rust//rust:repositories.bzl for examples of defining the @ru
| <a id="rust_toolchain-rust_lib"></a>rust_lib | The rust standard library. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc"></a>rustc | The location of the <code>rustc</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc_lib"></a>rustc_lib | The libraries used by rustc during compilation. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc_src"></a>rustc_src | The source code of rustc. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustfmt"></a>rustfmt | The location of the <code>rustfmt</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-staticlib_ext"></a>staticlib_ext | The extension for static libraries created from rustc. | String | required | |
| <a id="rust_toolchain-stdlib_linkflags"></a>stdlib_linkflags | Additional linker libs used when std lib is linked, see https://github.com/rust-lang/rust/blob/master/src/libstd/build.rs | List of strings | required | |
Expand Down
23 changes: 23 additions & 0 deletions docs/rust_analyzer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Rust rules
* [rust_analyzer](#rust_analyzer)
* [rust_analyzer_aspect](#rust_analyzer_aspect)

<a id="#rust_analyzer"></a>

## rust_analyzer

<pre>
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.

**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="rust_analyzer-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="rust_analyzer-targets"></a>targets | List of all targets to be included in the index | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |


58 changes: 58 additions & 0 deletions docs/rust_clippy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Rust rules
* [rust_clippy](#rust_clippy)
* [rust_clippy_aspect](#rust_clippy_aspect)

<a id="#rust_clippy"></a>

## rust_clippy

<pre>
rust_clippy(<a href="#rust_clippy-name">name</a>, <a href="#rust_clippy-deps">deps</a>)
</pre>

Executes the clippy checker on a specific target.

Similar to `rust_clippy_aspect`, but allows specifying a list of dependencies within the build system.

For example, given the following example targets:

```python
package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library", "rust_test")

rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)

rust_test(
name = "greeting_test",
srcs = ["tests/greeting.rs"],
deps = [":hello_lib"],
)
```

Rust clippy can be set as a build target with the following:

```python
rust_clippy(
name = "hello_library_clippy",
testonly = True,
deps = [
":hello_lib",
":greeting_test",
],
)
```


**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="rust_clippy-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="rust_clippy-deps"></a>deps | - | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |


3 changes: 2 additions & 1 deletion docs/rust_repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<pre>
rust_toolchain(<a href="#rust_toolchain-name">name</a>, <a href="#rust_toolchain-binary_ext">binary_ext</a>, <a href="#rust_toolchain-cargo">cargo</a>, <a href="#rust_toolchain-clippy_driver">clippy_driver</a>, <a href="#rust_toolchain-debug_info">debug_info</a>, <a href="#rust_toolchain-default_edition">default_edition</a>, <a href="#rust_toolchain-dylib_ext">dylib_ext</a>,
<a href="#rust_toolchain-exec_triple">exec_triple</a>, <a href="#rust_toolchain-opt_level">opt_level</a>, <a href="#rust_toolchain-os">os</a>, <a href="#rust_toolchain-rust_doc">rust_doc</a>, <a href="#rust_toolchain-rust_lib">rust_lib</a>, <a href="#rust_toolchain-rustc">rustc</a>, <a href="#rust_toolchain-rustc_lib">rustc_lib</a>, <a href="#rust_toolchain-rustfmt">rustfmt</a>,
<a href="#rust_toolchain-exec_triple">exec_triple</a>, <a href="#rust_toolchain-opt_level">opt_level</a>, <a href="#rust_toolchain-os">os</a>, <a href="#rust_toolchain-rust_doc">rust_doc</a>, <a href="#rust_toolchain-rust_lib">rust_lib</a>, <a href="#rust_toolchain-rustc">rustc</a>, <a href="#rust_toolchain-rustc_lib">rustc_lib</a>, <a href="#rust_toolchain-rustc_src">rustc_src</a>, <a href="#rust_toolchain-rustfmt">rustfmt</a>,
<a href="#rust_toolchain-staticlib_ext">staticlib_ext</a>, <a href="#rust_toolchain-stdlib_linkflags">stdlib_linkflags</a>, <a href="#rust_toolchain-target_triple">target_triple</a>)
</pre>

Expand Down Expand Up @@ -75,6 +75,7 @@ See @io_bazel_rules_rust//rust:repositories.bzl for examples of defining the @ru
| <a id="rust_toolchain-rust_lib"></a>rust_lib | The rust standard library. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc"></a>rustc | The location of the <code>rustc</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc_lib"></a>rustc_lib | The libraries used by rustc during compilation. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustc_src"></a>rustc_src | The source code of rustc. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-rustfmt"></a>rustfmt | The location of the <code>rustfmt</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="rust_toolchain-staticlib_ext"></a>staticlib_ext | The extension for static libraries created from rustc. | String | required | |
| <a id="rust_toolchain-stdlib_linkflags"></a>stdlib_linkflags | Additional linker libs used when std lib is linked, see https://github.com/rust-lang/rust/blob/master/src/libstd/build.rs | List of strings | required | |
Expand Down
3 changes: 3 additions & 0 deletions docs/rust_workspace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Rust rules
* [rust_workspace](#rust_workspace)

6 changes: 6 additions & 0 deletions examples/hello_lib/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load(
"@io_bazel_rules_rust//rust:rust.bzl",
"rust_analyzer",
"rust_doc",
"rust_doc_test",
"rust_library",
Expand Down Expand Up @@ -85,3 +86,8 @@ rust_doc_test(
name = "hello_lib_doc_test",
dep = ":hello_lib",
)

rust_analyzer(
name = "hello_rust_analyzer",
targets = [":hello_lib"],
)
Loading