bazelbuild / bazelbuild/rules_rust
CARGO_BIN_FILE_* is not set and the binaries of dependencies are not added as dependencies
- Dominant language
- Starlark
- Stars
- 843
- Forks
- 651
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 15
Description
Surely an edge-case in the Rust world, but nonetheless, here we are. I am compiling an AWS project called `twoliter` using Bazel, because... well. I couldn't wait for death to experience hell.
They bundle a bunch of binaries, that in turn are built using various incantations of the cargo build system (one of them is even a Go binary!). A feature they rely on, that I frankly couldn't even find when I Googled it, is the fact that if you depend on a cargo bin, that in turn has this annotation:
```toml
pipesys = { version = "0.1", path = "tools/pipesys", lib = true, artifact = [ "bin:pipesys" ] }
pubsys = { version = "0.1", path = "tools/pubsys", artifact = [ "bin:pubsys" ] }
```
then you can, in RUSTC access them like this:
```rust
const PIPESYS: &[u8] = include_bytes!(env!("CARGO_BIN_FILE_PIPESYS"));
const PUBSYS: &[u8] = include_bytes!(env!("CARGO_BIN_FILE_PUBSYS"));
```
This, of course does not work when we use Bazel, because... Well, isn't this what you have Bazel for?
I had to solve it in two places (both add it as a dependency for the compilation, but also adding the env var for rustc itself) like so:
```python
rust_tool_deps.annotation(
compile_data = [
"@rust_tool_deps__buildsys-0.1.0//:buildsys__bin",
"@rust_tool_deps__pipesys-0.1.0//:pipesys__bin__musl",
"@rust_tool_deps__pubsys-0.1.0//:pubsys__bin",
"@rust_tool_deps__pubsys-setup-0.1.0//:pubsys-setup__bin",
"@rust_tool_deps__testsys-0.1.0//:testsys__bin",
"@rust_tool_deps__tuftool-0.14.0//:tuftool__bin",
"@rust_tool_deps__unplug-0.1.0//:unplug__bin__musl",
],
crate = "twoliter",
gen_all_binaries = True,
],
rustc_flags = [
"-Z",
"unstable-options",
"--env-set",
"CARGO_BIN_FILE_BUILDSYS=$(location @rust_tool_deps__buildsys-0.1.0//:buildsys__bin)",
"--env-set",
"CARGO_BIN_FILE_PIPESYS=$(location @rust_tool_deps__pipesys-0.1.0//:pipesys__bin__musl)",
"--env-set",
"CARGO_BIN_FILE_PUBSYS=$(location @rust_tool_deps__pubsys-0.1.0//:pubsys__bin)",
"--env-set",
"CARGO_BIN_FILE_PUBSYS_SETUP=$(location @rust_tool_deps__pubsys-setup-0.1.0//:pubsys-setup__bin)",
"--env-set",
"CARGO_BIN_FILE_TESTSYS=$(location @rust_tool_deps__testsys-0.1.0//:testsys__bin)",
"--env-set",
"CARGO_BIN_FILE_TUFTOOL=$(location @rust_tool_deps__tuftool-0.14.0//:tuftool__bin)",
"--env-set",
"CARGO_BIN_FILE_UNPLUG=$(location @rust_tool_deps__unplug-0.1.0//:unplug__bin__musl)",
],
)
```
@UebelAndre I know you've enjoyed some of these previously, perhaps you find this exciting too?
Contributor guide
Assessment
This issue has not been assessed yet.