fix(chroot): detect cargo binaries when CARGO_HOME unset#750
Conversation
When AWF_CARGO_HOME is not set, detect and add ~/.cargo/bin to PATH. This ensures Rust binaries (rustc, cargo) are accessible even when CARGO_HOME environment variable is not explicitly provided. Fixes the chroot package manager test failure where rustc was not found in PATH despite being installed at the default location. Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes Rust tool availability in chroot mode when CARGO_HOME isn’t set by adding a fallback PATH injection for the standard ~/.cargo/bin install location. This improves reliability of host Rust tool usage under sudo/chroot setups where only AWF_HOST_PATH is provided.
Changes:
- Add a fallback branch in
entrypoint.shto prepend"$HOME/.cargo/bin"toPATHwhenAWF_CARGO_HOMEis unset. - Emit a comment into the generated chroot command script documenting the fallback PATH behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| else | ||
| # Fallback: detect Cargo from default location if CARGO_HOME not provided | ||
| # This ensures Rust binaries work even when CARGO_HOME env var is not set | ||
| echo "# Add Cargo bin for Rust if it exists (fallback when CARGO_HOME not provided)" >> "/host${SCRIPT_FILE}" | ||
| echo "[ -d \"\$HOME/.cargo/bin\" ] && export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> "/host${SCRIPT_FILE}" |
There was a problem hiding this comment.
The new fallback branch for Rust/Cargo PATH resolution isn’t currently exercised by CI: test-chroot.yml explicitly sets CARGO_HOME and adds $CARGO_HOME/bin to PATH, so AWF_CARGO_HOME is always present and this else-path won’t be covered. Consider adding an integration test (or a CI job variant) that runs chroot with CARGO_HOME unset and PATH not containing ~/.cargo/bin, then asserts rustc --version succeeds to prevent regressions.
Problem
rustc --versionfails with exit code 127 in chroot mode whenCARGO_HOMEenvironment variable is not set, despite rustc/cargo being installed at~/.cargo/bin.Root Cause
In chroot mode with
AWF_HOST_PATHset (the common case with sudo), entrypoint.sh only adds Cargo binaries to PATH whenAWF_CARGO_HOMEis explicitly provided. Many environments install Rust at the standard location without settingCARGO_HOME.Changes
Added fallback detection in
containers/agent/entrypoint.shwhenAWF_CARGO_HOMEis unset:This matches the existing pattern for other tools in the fallback PATH construction block.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.