bazelbuild / bazelbuild/rules_rust

Correct use of CARGO_CRATE_NAME vs CARGO_PKG_NAME

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

Description

Currently the `CARGO_PKG_NAME` env var is passed in to the crate being built, but I am wondering if this is correct. The code https://github.com/bazelbuild/rules_rust/commit/3dffbabb3ab65a41056228b5c387d4b78331eaec#diff-4b0b39fe65c7318b74b94bd271d638a060ef06c2ac9363109b0ea4aa5ca085f2R36 implies that we are setting the crate name to `CARGO_PKG_NAME`, but there is also `CARGO_CRATE_NAME` which is used for the same thing.

From the [rust docs](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates):

> `CARGO_PKG_NAME` — The name of your package.
> `CARGO_CRATE_NAME` — The name of the crate that is currently being compiled.

It seems to me, at the very least, that both should be supported, but the distinction isn't quite clear. Is `CARGO_PKG_NAME` correct in this case?

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.