M1 Users - How are you Cross Compiling?

43 points DemiKoss

As the title goes; I'm trying to cross compile a project from M1 to Armv7 (for a raspberry pi 4). On my x86 Macbook the cross toolkit worked without a hitch. I can't seem to find a working solution on my M1 machine though, and I'm fairly stuck -- hoping someone else has found a working solution they could share, or a push in the right direction from here.

Things I've tried:

  • Cross v0.2.1 (latest release) & master (--git) don't make a difference:
    • Cross + Podman can't work, as volume mounting is broken
    • Cross + Docker solves the mount issue, but the qemu emulation panics (qemu is being used to emulate x86 since cross has no linux/arm64/v8 images yet). I tried building the images with --platform arm64 & using a custom image, but both meet the same issue:

​

/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x400641441d]
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
error: could not compile 'unicode-bidi'
  • cargo build --release --target armv7-unknown-linux-gnueabihf on it's own fails to build ring due to missing arm-linux-gnueabihf-gcc on the machine
  • The messense/homebrew-macos-cross-toolchains gets me past ring but fails on another dependency I have, audiopus\_sys:

​

export TARGET_CC=armv7-unknown-linux-gnueabihf-gcc
export TARGET_AR=armv7-unknown-linux-gnueabihf-ar
export CC_x86_64_unknown_linux_gnu=armv7-unknown-linux-gnueabihf-gcc
export CXX_x86_64_unknown_linux_gnu=armv7-unknown-linux-gnueabihf-g++
export AR_x86_64_unknown_linux_gnu=armv7-unknown-linux-gnueabihf-ar
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=armv7-unknown-linux-gnueabihf-gcc
cargo build --release --target armv7-unknown-linux-gnueabihf
...
/opt/homebrew/bin/armv7-unknown-linux-gnueabihf-gcc   -ffunction-sections -fdata-sections -fPIC -march=armv7-a  -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.0.sdk -o CMakeFiles/cmTC_6e214.dir/testCCompiler.c.o -c /Users/myuser/code/disbot/target/armv7-unknown-linux-gnueabihf/release/build/audiopus_sys-0a12517698e9679e/out/build/CMakeFiles/CMakeTmp/testCCompiler.c
armv7-unknown-linux-gnueabihf-gcc: error: arm64: No such file or directory
armv7-unknown-linux-gnueabihf-gcc: error: unrecognized command-line option '-arch'; did you mean '-march='?