-
Notifications
You must be signed in to change notification settings - Fork 28
Fix use with Bazel #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/lib.rs
Outdated
|
|
||
| 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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if !cargo_toml_manifest.with_extension(".toml.orig").exists() { | |
| if cargo_toml_manifest.with_extension(".toml.orig").exists() { |
Isn't that the correct way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this file exists if the package was packaged by cargo, but also generally a little bit fragile because anything could create this file.
Maybe to fix your issue, just returning None when CARGO env variable wasn't found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops, patch tested and submitted differ :( my bad, sorry.
Yes, I’d be happy to change the PR to return None of cargo isn’t set. I guess the corresponding error type can also go away then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify: intended was this:
if cargo_toml_manifest.with_extension("toml.orig").exists() {(note the removed leading dot)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed the version that I intended and that I verified that it works as intended.
I think it's a win-win kind of, as it also speeds up the regular builds. But if you prefer the None on unset Cargo env, then I can also do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little bit afraid it breaks something else :D Also in a non obvious way. I think for now I would opt-in to check for CARGO being unchecked. But we could open an issue to speed up regular builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, sounds good. Force-push coming up to correct this :)
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. As a fallback, a lack of the CARGO environment variable now just means no workspace support.
| NotFound(PathBuf), | ||
| CargoManifestDirNotSet, | ||
| CargoEnvVariableNotSet, | ||
| FailedGettingWorkspaceManifestPath, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| FailedGettingWorkspaceManifestPath, | |
| #[deprecated] | |
| CargoEnvVariableNotSet, | |
| FailedGettingWorkspaceManifestPath, |
| path.display(), | ||
| ), | ||
| Error::CargoEnvVariableNotSet => f.write_str("`CARGO` env variable not set."), | ||
| Error::FailedGettingWorkspaceManifestPath => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Error::FailedGettingWorkspaceManifestPath => | |
| #[allow(deprecated)] | |
| Error::CargoEnvVariableNotSet => f.write_str("`CARGO` env variable not set."), | |
| Error::FailedGettingWorkspaceManifestPath => |
|
Ty! |
rstest currently fails to build under bazel with
```
error: custom attribute panicked
|
250 | #[rstest]
| ^^^^^^^^^
|
= help: message: rstest is present in `Cargo.toml` qed: Could not find `Cargo.toml` in manifest dir:
```
I've tracked this back to proc-macro-crate, which fixed it in bkchr/proc-macro-crate#55
rstest currently fails to build under bazel with
```
error: custom attribute panicked
|
250 | #[rstest]
| ^^^^^^^^^
|
= help: message: rstest is present in `Cargo.toml` qed: Could not find `Cargo.toml` in manifest dir:
```
I've tracked this back to proc-macro-crate, which fixed it in bkchr/proc-macro-crate#55
rstest currently fails to build under bazel with
```
error: custom attribute panicked
|
250 | #[rstest]
| ^^^^^^^^^
|
= help: message: rstest is present in `Cargo.toml` qed: Could not find `Cargo.toml` in manifest dir:
```
I've tracked this back to proc-macro-crate, which fixed it in bkchr/proc-macro-crate#55
rstest currently fails to build under bazel with
```
error: custom attribute panicked
|
250 | #[rstest]
| ^^^^^^^^^
|
= help: message: rstest is present in `Cargo.toml` qed: Could not find `Cargo.toml` in manifest dir:
```
I've tracked this back to proc-macro-crate, which fixed it in bkchr/proc-macro-crate#55
#329) * Upgrade proc-macro-crate to 3.4.0 in order fix compilation under bazel rstest currently fails to build under bazel with ``` error: custom attribute panicked | 250 | #[rstest] | ^^^^^^^^^ | = help: message: rstest is present in `Cargo.toml` qed: Could not find `Cargo.toml` in manifest dir: ``` I've tracked this back to proc-macro-crate, which fixed it in bkchr/proc-macro-crate#55 * fix typo in changelog
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.
As a fallback, a lack of the CARGO environment variable now just means
no workspace support.