cross icon indicating copy to clipboard operation
cross copied to clipboard

Darwin+Podman: Unable to cross-compile

Open skittishdev opened this issue 1 year ago • 4 comments

Checklist

Describe your issue

cross doesn't work when I try to use it with podman (even if I set the CROSS_CONTAINER_ENGINE=podman env variable) on my Mac/M2. But the same project cross compiles successfully with docker.

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

aarch64-unknown-linux-gnu

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

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

What architecture is the host?

  • [ ] x86_64 / AMD64
  • [ ] arm32
  • [X] arm64 (including Mac M1)

What container engine is cross using?

  • [ ] docker
  • [X] podman
  • [ ] other container engine (specify in description)

cross version

cross 0.2.5 (4090bec 2024-10-15)

Example

I have both docker and podman installed on my Mac. My Docker Desktop application is not running.

ps -ef | grep docker
  503 68715 69102   0  5:05PM ttys007    0:00.00 grep docker
podman machine init --cpus=8 --disk-size=64 --memory=24576 foo
podman machine start foo
CROSS_CONTAINER_ENGINE=podman cross build --target aarch64-unknown-linux-gnu --release

This results in an error like so:

Error: 
   0: /proc/self/mountinfo is unavailable when target_os != linux

Location:
   src/docker/shared.rs:1354

Additional information / notes

Cross works just fine with Docker. The command below results in a successful build when my Docker Desktop application is running in the background.

cross build --target aarch64-unknown-linux-gnu --release

I installed cross as specified in the docs: https://github.com/cross-rs/cross/blob/main/docs/getting-started.md#installing-cross-1

skittishdev avatar Nov 01 '24 00:11 skittishdev

Podman info (if needed)

$ podman version
Client:       Podman Engine
Version:      5.2.5
API Version:  5.2.5
Go Version:   go1.23.2
Git Commit:   10c5aa720d59480bc7edad347c1f5d5b75d4424f
Built:        Fri Oct 18 07:51:48 2024
OS/Arch:      darwin/arm64

Server:       Podman Engine
Version:      5.2.5
API Version:  5.2.5
Go Version:   go1.22.7
Built:        Thu Oct 17 17:00:00 2024
OS/Arch:      linux/arm64

skittishdev avatar Nov 01 '24 00:11 skittishdev

This was changed in #1485 and there some assumption done there that is incorrect for podman in the rest of the application logic. Should be an easy fix once located why it happens

Emilgardis avatar Nov 01 '24 06:11 Emilgardis

This was changed in #1485 and there some assumption done there that is incorrect for podman in the rest of the application logic. Should be an easy fix once located why it happens

I looked at the code in this linked commit, and realized that MacOS doesn't set a $HOSTNAME environment variable. In order to test a potential fix I did an export HOSTNAME=$(hostname), and then executed this command: CROSS_CONTAINER_ENGINE=podman cross build --target aarch64-unknown-linux-gnu --release. But now I see errors like so (a different error each time):

Error: statfs /Users/skittishdev/.xargo: no such file or directory
Error: statfs /Users/skittishdev/.cargo: no such file or directory
Error: statfs /Users/skittishdev/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu: no such file or directory

skittishdev avatar Nov 29 '24 20:11 skittishdev

rustup toolchain that is being complained about is present, though it is not native to my platform.

# rustup toolchain list
stable-aarch64-apple-darwin (default)
nightly-aarch64-apple-darwin (override)
nightly-x86_64-unknown-linux-gnu

When I run rustup update I see this:

      stable-aarch64-apple-darwin unchanged - rustc 1.83.0 (90b35a623 2024-11-26)
      nightly-aarch64-apple-darwin unchanged - rustc 1.85.0-nightly (a2545fd6f 2024-11-28)
      nightly-x86_64-unknown-linux-gnu unchanged - (error reading rustc version)

I don't understand why the x86_64 target is needed when the target is specify is aarch64, but I'll assume that's the platform that cross uses to cross-compile. I also ran rustup install nightly-aarch64-unknown-linux-gnu --force-non-host, but there is no change is the errors.

If I use docker though, the cross compilation continues to work just fine.

skittishdev avatar Nov 29 '24 21:11 skittishdev