Skip to content

Commit 47d918d

Browse files
committed
Fix use with packaged crates and Bazel
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.
1 parent a12fb32 commit 47d918d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ pub fn crate_name(orig_name: &str) -> Result<FoundCrate, Error> {
241241
}
242242

243243
fn workspace_manifest_path(cargo_toml_manifest: &Path) -> Result<Option<PathBuf>, Error> {
244+
// Skip invoking Cargo if we're building a crate packaged with cargo.
245+
if !cargo_toml_manifest.with_extension(".toml.orig").exists() {
246+
return Ok(None);
247+
}
248+
244249
let stdout = Command::new(env::var("CARGO").map_err(|_| Error::CargoEnvVariableNotSet)?)
245250
.arg("locate-project")
246251
.args(&["--workspace", "--message-format=plain"])

0 commit comments

Comments
 (0)