Skip to content

Commit 724ee62

Browse files
committed
Minor cleanup
1 parent 1fc2993 commit 724ee62

File tree

3 files changed

+76
-75
lines changed

3 files changed

+76
-75
lines changed

rust/private/rustc.bzl

+2-3
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,8 @@ def construct_arguments(
495495
This is to be passed to the `arguments` parameter of actions
496496
- (dict): Common rustc environment variables
497497
"""
498-
output_dir = getattr(crate_info.output, "dirname") if hasattr(crate_info.output, "dirname") else None
499-
500-
linker_script = getattr(file, "linker_script") if hasattr(file, "linker_script") else None
498+
output_dir = getattr(crate_info.output, "dirname", None)
499+
linker_script = getattr(file, "linker_script", None)
501500

502501
env = _get_rustc_env(attr, toolchain, crate_info.name)
503502

rust/private/rustdoc.bzl

+42-42
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# buildifier: disable=module-docstring
15+
"""Rules for generating documentation with `rustdoc` for Bazel built crates"""
16+
1617
load("//rust/private:common.bzl", "rust_common")
1718
load("//rust/private:rustc.bzl", "add_crate_link_flags", "add_edition_flags")
18-
load("//rust/private:utils.bzl", "find_toolchain")
19-
20-
_rust_doc_doc = """Generates code documentation.
21-
22-
Example:
23-
Suppose you have the following directory structure for a Rust library crate:
24-
25-
```
26-
[workspace]/
27-
WORKSPACE
28-
hello_lib/
29-
BUILD
30-
src/
31-
lib.rs
32-
```
33-
34-
To build [`rustdoc`][rustdoc] documentation for the `hello_lib` crate, define \
35-
a `rust_doc` rule that depends on the the `hello_lib` `rust_library` target:
36-
37-
[rustdoc]: https://doc.rust-lang.org/book/documentation.html
38-
39-
```python
40-
package(default_visibility = ["//visibility:public"])
41-
42-
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc")
43-
44-
rust_library(
45-
name = "hello_lib",
46-
srcs = ["src/lib.rs"],
47-
)
48-
49-
rust_doc(
50-
name = "hello_lib_doc",
51-
crate = ":hello_lib",
52-
)
53-
```
54-
55-
Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing \
56-
the documentation for the `hello_lib` library crate generated by `rustdoc`.
57-
"""
19+
load("//rust/private:utils.bzl", "dedent", "find_toolchain")
5820

5921
def _rust_doc_impl(ctx):
6022
"""The implementation of the `rust_doc` rule
@@ -146,7 +108,45 @@ def _zip_action(ctx, input_dir, output_zip):
146108
)
147109

148110
rust_doc = rule(
149-
doc = _rust_doc_doc,
111+
doc = dedent("""\
112+
Generates code documentation.
113+
114+
Example:
115+
Suppose you have the following directory structure for a Rust library crate:
116+
117+
```
118+
[workspace]/
119+
WORKSPACE
120+
hello_lib/
121+
BUILD
122+
src/
123+
lib.rs
124+
```
125+
126+
To build [`rustdoc`][rustdoc] documentation for the `hello_lib` crate, define \
127+
a `rust_doc` rule that depends on the the `hello_lib` `rust_library` target:
128+
129+
[rustdoc]: https://doc.rust-lang.org/book/documentation.html
130+
131+
```python
132+
package(default_visibility = ["//visibility:public"])
133+
134+
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc")
135+
136+
rust_library(
137+
name = "hello_lib",
138+
srcs = ["src/lib.rs"],
139+
)
140+
141+
rust_doc(
142+
name = "hello_lib_doc",
143+
crate = ":hello_lib",
144+
)
145+
```
146+
147+
Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing \
148+
the documentation for the `hello_lib` library crate generated by `rustdoc`.
149+
"""),
150150
implementation = _rust_doc_impl,
151151
attrs = {
152152
"crate": attr.label(

rust/private/rustdoc_test.bzl

+32-30
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# buildifier: disable=module-docstring
15+
"""Rules for performing `rustdoc --test` on Bazel built crates"""
16+
1617
load("//rust/private:common.bzl", "rust_common")
17-
load("//rust/private:utils.bzl", "find_toolchain", "get_lib_name", "get_preferred_artifact")
18+
load("//rust/private:utils.bzl", "dedent", "find_toolchain", "get_lib_name", "get_preferred_artifact")
1819

1920
def _rust_doc_test_impl(ctx):
2021
"""The implementation for the `rust_doc_test` rule
@@ -217,42 +218,43 @@ rust_doc_test = rule(
217218
test = True,
218219
toolchains = [str(Label("//rust:toolchain"))],
219220
incompatible_use_toolchain_transition = True,
220-
doc = """Runs Rust documentation tests.
221+
doc = dedent("""\
222+
Runs Rust documentation tests.
221223
222-
Example:
224+
Example:
223225
224-
Suppose you have the following directory structure for a Rust library crate:
226+
Suppose you have the following directory structure for a Rust library crate:
225227
226-
```output
227-
[workspace]/
228-
WORKSPACE
229-
hello_lib/
230-
BUILD
231-
src/
232-
lib.rs
233-
```
228+
```output
229+
[workspace]/
230+
WORKSPACE
231+
hello_lib/
232+
BUILD
233+
src/
234+
lib.rs
235+
```
234236
235-
To run [documentation tests][doc-test] for the `hello_lib` crate, define a `rust_doc_test` \
236-
target that depends on the `hello_lib` `rust_library` target:
237+
To run [documentation tests][doc-test] for the `hello_lib` crate, define a `rust_doc_test` \
238+
target that depends on the `hello_lib` `rust_library` target:
237239
238-
[doc-test]: https://doc.rust-lang.org/book/documentation.html#documentation-as-tests
240+
[doc-test]: https://doc.rust-lang.org/book/documentation.html#documentation-as-tests
239241
240-
```python
241-
package(default_visibility = ["//visibility:public"])
242+
```python
243+
package(default_visibility = ["//visibility:public"])
242244
243-
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc_test")
245+
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc_test")
244246
245-
rust_library(
246-
name = "hello_lib",
247-
srcs = ["src/lib.rs"],
248-
)
247+
rust_library(
248+
name = "hello_lib",
249+
srcs = ["src/lib.rs"],
250+
)
249251
250-
rust_doc_test(
251-
name = "hello_lib_doc_test",
252-
crate = ":hello_lib",
253-
)
254-
```
252+
rust_doc_test(
253+
name = "hello_lib_doc_test",
254+
crate = ":hello_lib",
255+
)
256+
```
255257
256-
Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation tests for the `hello_lib` library crate.
257-
""",
258+
Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation tests for the `hello_lib` library crate.
259+
"""),
258260
)

0 commit comments

Comments
 (0)