Build script that sets lib name for Cargo.toml

Hello,

I want to know if there is a way in the build script to tell the Cargo.toml, "this is the name of your lib." I saw that for binaries, there is CARGO_BIN_NAME, but there doesn't seem to be an equivalent for libs.
Does anyone know a way to work around this?

Thanks!

  • CARGO_CRATE_NAME — The name of the crate that is currently being compiled. It is the name of the Cargo target with - converted to _, such as the name of the library, binary, example, integration test, or benchmark.

Note: CARGO_BIN_NAME and CARGO_CRATE_NAME are environment variables that Cargo sets for crates [1] rather than build script sets for Cargo.


  1. which means you can write env!("CARGO_CRATE_NAME"); in source code of your crate â†Šī¸Ž

that's not to change the binary name, that's set by cargo to inform the build script in case it need that information.

neither the library or binary names can be changed from a build script. they must be specified in the manifest.

1 Like