zombienet-sdk-tests: fall back gracefully when CARGO_WORKSPACE_ROOT_DIR is unset#12611
Open
Thiago316316 wants to merge 6 commits into
Open
zombienet-sdk-tests: fall back gracefully when CARGO_WORKSPACE_ROOT_DIR is unset#12611Thiago316316 wants to merge 6 commits into
Thiago316316 wants to merge 6 commits into
Conversation
…IR is unset
build.rs previously called env::var("CARGO_WORKSPACE_ROOT_DIR").unwrap(),
which only resolves because .cargo/config.toml defines it under [env].
Environments that don't apply that config (e.g. remote-build tooling)
panic instead. workspace_root() now falls back to walking up from
CARGO_MANIFEST_DIR, which cargo guarantees unconditionally, to find the
workspace root by locating the top-level [workspace] Cargo.toml.
Part of paritytech#6906.
Contributor
Author
|
@bkontur Would appreciate a look when you have a chance — and if you're able to, a T18-zombienet_tests label would help it clear CI's check-labels gate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the panic reported in #6906: build.rs unwraps CARGO_WORKSPACE_ROOT_DIR, an env var only supplied by this repo's .cargo/config.toml — absent in environments that don't apply it (e.g. remote-build tooling)
Root cause: build.rs had env::var("CARGO_WORKSPACE_ROOT_DIR").unwrap(). That variable isn't a cargo built-in — it only exists because this repo's .cargo/config.toml defines it under [env]:
CARGO_WORKSPACE_ROOT_DIR = { value = "", relative = true }
Cargo applies [env] entries automatically for a normal in-tree build, which is why it works for most of us locally. Your build path (/home/bkontur/cargo-remote-builds-aaa/...) looks like a remote-build tool that snapshots the source elsewhere and builds it there — in that kind of setup .cargo/config.toml's [env] section isn't necessarily applied, so the var is genuinely absent, and the old code just panicked instead of handling that.
What I confirmed before writing the fix:
The fix: workspace_root() (new function on build.rs) now tries CARGO_WORKSPACE_ROOT_DIR first (unchanged behavior when it's present), and if that's absent, derives the workspace root by walking up from CARGO_MANIFEST_DIR — which cargo guarantees unconditionally for every build script — looking for the top-level Cargo.toml that contains [workspace]. That mirrors what cargo itself does to find a workspace root, so it doesn't depend on this crate's fixed depth in the tree.
Closes #6906.