Skip to content

fix(chroot): detect cargo binaries when CARGO_HOME unset#750

Merged
lpcox merged 2 commits intolpcox/port-one-shot-token-rustfrom
copilot/fix-github-actions-workflow-another-one
Feb 12, 2026
Merged

fix(chroot): detect cargo binaries when CARGO_HOME unset#750
lpcox merged 2 commits intolpcox/port-one-shot-token-rustfrom
copilot/fix-github-actions-workflow-another-one

Conversation

Copy link
Contributor

Copilot AI commented Feb 12, 2026

Problem

rustc --version fails with exit code 127 in chroot mode when CARGO_HOME environment variable is not set, despite rustc/cargo being installed at ~/.cargo/bin.

Root Cause

In chroot mode with AWF_HOST_PATH set (the common case with sudo), entrypoint.sh only adds Cargo binaries to PATH when AWF_CARGO_HOME is explicitly provided. Many environments install Rust at the standard location without setting CARGO_HOME.

Changes

Added fallback detection in containers/agent/entrypoint.sh when AWF_CARGO_HOME is unset:

if [ -n "${AWF_CARGO_HOME}" ]; then
  echo "export PATH=\"${AWF_CARGO_HOME}/bin:\$PATH\"" >> "/host${SCRIPT_FILE}"
  echo "export CARGO_HOME=\"${AWF_CARGO_HOME}\"" >> "/host${SCRIPT_FILE}"
else
  # Fallback: detect from default location
  echo "[ -d \"\$HOME/.cargo/bin\" ] && export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> "/host${SCRIPT_FILE}"
fi

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.

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>
Copilot AI changed the title [WIP] Fix the failing GitHub Actions workflow for Test Chroot Package Managers fix(chroot): detect cargo binaries when CARGO_HOME unset Feb 12, 2026
Copilot AI requested a review from lpcox February 12, 2026 15:58
@lpcox lpcox marked this pull request as ready for review February 12, 2026 15:58
Copilot AI review requested due to automatic review settings February 12, 2026 15:58
@lpcox lpcox merged commit dfd0a9c into lpcox/port-one-shot-token-rust Feb 12, 2026
@lpcox lpcox deleted the copilot/fix-github-actions-workflow-another-one branch February 12, 2026 15:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.sh to prepend "$HOME/.cargo/bin" to PATH when AWF_CARGO_HOME is 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.

Comment on lines +296 to +300
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}"
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants