bazelbuild / bazelbuild/rules_rust

No `version` attribute to `rust_doc`

Open
#573 2 comments 0 reactions 0 assignees View on GitHub
needs-triage rustdoc
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

The `rust_library` and `rust_binary` rules have a [`version`] attribute
to populate `CARGO_PKG_VERSION` (et al.) at compile time. But `rust_doc`
has no such `version` attribute, and so any code that actually depends
on the package version will break if given to `rust_doc`:

```
$ bazel build :rustboard_core
INFO: Build completed successfully, 2 total actions
$ bazel build :rustboard_core_doc
ERROR: /HOMEDIR/git/tensorboard/tensorboard/data/server/BUILD:98:9: Generating rustdoc for rustboard_core (18 files) failed (Exit 1): rustdoc failed: error executing command external/rust_linux_x86_64/bin/rustdoc tensorboard/data/server/lib.rs --crate-name rustboard_core --crate-type rlib --output bazel-out/k8-opt/bin/tensorboard/data/server/rustboard_core_doc ... (remaining 150 argument(s) skipped)
error: environment variable `CARGO_PKG_VERSION` not defined
--> tensorboard/data/server/cli.rs:39:38
|
39 | #[clap(name = "rustboard", version = clap::crate_version!())]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: Compilation failed, aborting rustdoc

error: aborting due to 2 previous errors

Target //tensorboard/data/server:rustboard_core_doc failed to build
FAILED: Build did NOT complete successfully
```

You can see from `bazel aquery` that the [Rustc action] passes an
appropriate env, but the [Rustdoc action] simply doesn’t. Perhaps it
should pass the same environment that its `dep` action does?

As far as I can tell, the only workaround is to just not write any code
that depends on `CARGO_PKG_VERSION`.

[Rustc action]: https://github.com/bazelbuild/rules_rust/blob/932a389dbfb227189062f343a738c0246494016a/rust/private/rustc.bzl#L623-L625
[Rustdoc action]: https://github.com/bazelbuild/rules_rust/blob/932a389dbfb227189062f343a738c0246494016a/rust/private/rustdoc.bzl#L101-L108
[`version`]: http://bazelbuild.github.io/rules_rust/rust.html#rust_library-version

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.