Skip to content
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

Issue Mounting and Using Workspaces in Git Bash/CMD on Windows #1156

Closed
5 of 11 tasks
Alexhuszagh opened this issue Nov 26, 2022 · 3 comments · Fixed by #1157
Closed
5 of 11 tasks

Issue Mounting and Using Workspaces in Git Bash/CMD on Windows #1156

Alexhuszagh opened this issue Nov 26, 2022 · 3 comments · Fixed by #1157
Assignees
Labels
A-windows-host Area: windows (not WSL2) hosts bug
Milestone

Comments

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Nov 26, 2022

Checklist

Describe your issue

When using docker or podman on a Windows machine (run from Git bash or CMD, likely also Powershell), the container engine fails to change directories to the mounted project directory. Although the mount directories for the same locations are properly mounted, the -w flag fails. This is an issue if using /mnt/c or C:\ for the provided path. The attempted workdir attempted to be found relative to Git bash.

On CMD, the workpath is properly found, so the CMD, and CMD is properly mounted, however other issues still seem to exist, since it produces the same error.

None of these issues manifest with cargo directly.

The simplest example is to do:

$ git clone https://github.com/cross-rs/test-workspace
$ cd test-workspace/workspace
$ crossbuild --target x

Oddly, this does not fail with the following invocation:

```bash
$ cross build --target x86_64-unknown-linux-gnu -v --manifest-path="./workspace/Cargo.toml" --workspace

What target(s) are you cross-compiling for?

No response

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.4 (b238b21 2022-10-12)

Example

Note that this also reproduces on Windows CMD as well as Git bash, so it's not exclusively a Git bash problem.

$ /c/Users/ahusz/git/cross/target/debug/cross.exe build --target x86_64-unknown-linux-gnu --workspace -v
+ cargo metadata --format-version 1 --filter-platform x86_64-unknown-linux-gnu
+ rustc --print sysroot
+ "C:\Program Files\Docker\Docker\resources\bin\docker.exe"
+ "C:\Program Files\Docker\Docker\resources\bin\docker.exe" version -f '{{ .Server.Os }},,,{{ .Server.Arch }}'
+ rustup toolchain list
+ rustup target list --toolchain stable-x86_64-unknown-linux-gnu
+ rustup component list --toolchain stable-x86_64-unknown-linux-gnu
+ "C:\Program Files\Docker\Docker\resources\bin\docker.exe" run --userns host -e 'PKG_CONFIG_ALLOW_CROSS=1' -e 'XARGO_HOME=/mnt/c/Users/ahusz/.xargo' -e 'CARGO_HOME=/mnt/c/Users/ahusz/.cargo' -e 'CROSS_RUST_SYSROOT=/mnt/c/Users/ahusz/.rustup/toolchains/stable-x86_64-unknown-linux-gnu' -e 'CARGO_TARGET_DIR=/target' -e 'CROSS_RUNNER=' -e TERM -e 'USER=ahusz' -e 'CROSS_RUSTC_MAJOR_VERSION=1' -e 'CROSS_RUSTC_MINOR_VERSION=64' -e 'CROSS_RUSTC_PATCH_VERSION=0' -v 'C:\Users\ahusz\git\cross\target\tmp\tmp.5z26cWTEes\external\external_lib:/mnt/c/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/external/external_lib:z' --name cross-stable-x86_64-unknown-linux-gnu-9de56-a55dd71d5-x86_64-unknown-linux-gnu-12695-1669472749478 --rm --user 1000:1000 -v 'C:\Users\ahusz\.xargo:/mnt/c/Users/ahusz/.xargo:z' -v 'C:\Users\ahusz\.cargo:/mnt/c/Users/ahusz/.cargo:z' -v /mnt/c/Users/ahusz/.cargo/bin -v 'C:\Users\ahusz\git\cross\target\tmp\tmp.5z26cWTEes\workspace:/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace:z' -v 'C:\Users\ahusz\.rustup\toolchains\stable-x86_64-unknown-linux-gnu:/mnt/c/Users/ahusz/.rustup/toolchains/stable-x86_64-unknown-linux-gnu:z,ro' -v 'C:\Users\ahusz\git\cross\target\tmp\tmp.5z26cWTEes\workspace\target:/target:z' -w /mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace -t ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main sh -c 'PATH="$PATH":"/mnt/c/Users/ahusz/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin" cargo build --target x86_64-unknown-linux-gnu --workspace -v'
error: failed to load manifest for workspace member `/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace/binary`

Caused by:
  failed to load manifest for dependency `test-workspace`

Caused by:
  failed to load manifest for dependency `external_lib`

Caused by:
  failed to read `/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/external/external_lib/Cargo.toml`

Caused by:
  No such file or directory (os error 2)
+ rustup component list --toolchain stable-x86_64-unknown-linux-gnu

Note that running the following works:

$ "C:\Program Files\Docker\Docker\resources\bin\docker.exe" run --userns host \
    -v 'C:\Users\ahusz\git\cross\target\tmp\tmp.5z26cWTEes\external\external_lib:/mnt/c/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/external/external_lib:z' \
    -it ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main bash
$  ls /mnt/c/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/external/external_lib
Cargo.toml  src

As does:

$ "C:\Program Files\Docker\Docker\resources\bin\docker.exe" run --userns host \
    -v 'C:\Users\ahusz\git\cross\target\tmp\tmp.5z26cWTEes\workspace:/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace:z' \
    -it ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main bash
$  ls /mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace/binary/
Cargo.toml  src

So clearly, the issue extends a bit past just the basic error messages reported. However, the failing step is:

$ "C:\Program Files\Docker\Docker\resources\bin\docker.exe" run --userns host \
    -v 'C:\Users\ahusz\git\cross\target\tmp\tmp.5z26cWTEes\workspace:/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace:z' \
    -w '/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace' \
    -it ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main bash
docker: Error response from daemon: the working directory 'C:/Program Files/Git/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace' is invalid, it needs to be an absolute path.
See 'docker run --help'.

Meanwhile, a similar issue occurs when using Podman:

$ podman run --userns host     -v 'C:\Users\ahusz\git\cross\target\tmp\tmp.5z26cWTEes\workspace:/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace:z'     -w '/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace'     -it ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main bash
Error: error preparing container f2ad9a0ac2a0aa6666f69ea52311f7cef253d8e489bcff6909cad98152d2bac7 for attach: workdir "C:/Program Files/Git/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace" does not exist on container f2ad9a0ac2a0aa6666f69ea52311f7cef253d8e489bcff6909cad98152d2bac7

However, when using CMD, the above command works perfectly fine:

> docker run --userns host -v "C:\Users\ahusz\git\cross\target\tmp\tmp.5z26cWTEes\workspace:/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace:z"  -w "/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/workspace"  -it ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main bash
$ exit

Additional information / notes

Presumably this also affects other engines, such as lima.

@Alexhuszagh Alexhuszagh added bug A-windows-host Area: windows (not WSL2) hosts labels Nov 26, 2022
@Alexhuszagh Alexhuszagh added this to the v0.3.0 milestone Nov 26, 2022
@Alexhuszagh Alexhuszagh self-assigned this Nov 26, 2022
@Alexhuszagh
Copy link
Contributor Author

Alexhuszagh commented Nov 26, 2022

EDIT: The relative paths seem to be invalid, it just seems to be an artifact of using Git bash. The major issue, however, remains. It also seems on CMD and Git bash that /mnt/c/mnt/c is duplicated, but this only occurs for external_lib: 'C:\Users\ahusz\git\cross\target\tmp\tmp.5z26cWTEes\external\external_lib:/mnt/c/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/external/external_lib:z'.

That is, it's an issue of dependencies being mounted outside the current workspace.

It might be worth adding ci/test.sh to our Windows and macOS CI.

It seems the issue is in /docker/shared.rs with the mount function, since everything up to there works perfectly fine.

Update: It seems the issue is in:

// absolute_path = "/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/external/external_lib"
let mount_path = absolute_path.as_posix_absolute()?;
// mount_path = "/mnt/c/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/external/external_lib"

as_posix_absolute probably needs a way to detect if the path starts with /c/ or /mnt/c. This was an issue with wsl -e wslpath before, since this isn't a new bug:

$  wsl -e wslpath "/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/external/external_lib"
/mnt/c/Program Files/Git/mnt/c/Users/ahusz/git/cross/target/tmp/tmp.5z26cWTEes/external/external_lib

@Emilgardis
Copy link
Member

Emilgardis commented Nov 26, 2022

we can't use the test suite on windows and macos due to missing functionality, related #610

@Alexhuszagh
Copy link
Contributor Author

we can't use the test suite on windows and macos due to missing functionality, related #610

Ah right. Ok, at least I can fix this locally.

bors bot added a commit that referenced this issue Nov 28, 2022
1157: Fix mount paths on Windows. r=Emilgardis a=Alexhuszagh

Fixes mount paths outside of the workspace mount directory on Windows and those provided as a WSL path. This also adds unittests for Windows outside of WSL2.

Closes #1145.
Closes #1156.

Co-authored-by: Alex Huszagh <[email protected]>
@bors bors bot closed this as completed in f253bd0 Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-windows-host Area: windows (not WSL2) hosts bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants