Skip to content

Commit

Permalink
Fix use with packaged crates and Bazel
Browse files Browse the repository at this point in the history
When the application is built with Bazel as build system, environment
variables like CARGO_MANIFEST_DIR, etc. are set for compatibility, but
CARGO itself isn't, because Bazel is the tool of choice. Therefore any
attempt to invoke Cargo to locate the workspace manifest path fails.

Using proc-macro-crate with crates that are using Cargo workspaces makes
indeed only sense when Cargo is the build system. But when the crates
are packaged, then we don't even need to invoke cargo anyway to locate
a workspace, as there can't be any.

This speeds up the general build and makes it possible to use
proc-macro-crate with Bazel builds.
  • Loading branch information
tronical committed Jan 5, 2025
1 parent a12fb32 commit 37b5422
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ pub fn crate_name(orig_name: &str) -> Result<FoundCrate, Error> {
}

fn workspace_manifest_path(cargo_toml_manifest: &Path) -> Result<Option<PathBuf>, Error> {
// Skip invoking Cargo if we're building a crate packaged with cargo.
if cargo_toml_manifest.with_extension("toml.orig").exists() {
return Ok(None);
}

let stdout = Command::new(env::var("CARGO").map_err(|_| Error::CargoEnvVariableNotSet)?)
.arg("locate-project")
.args(&["--workspace", "--message-format=plain"])
Expand Down

0 comments on commit 37b5422

Please sign in to comment.