cross icon indicating copy to clipboard operation
cross copied to clipboard

Arm x86_64 Musl build using alpine broken

Open SamTV12345 opened this issue 2 years ago • 3 comments

Checklist

Describe your issue

Cross does not compile an alpine image on x86.

[target."x86_64-unknown-linux-musl"]
image.name = "alpine:edge"
image.toolchain = ["x86_64-unknown-linux-musl", "linux/arm64=aarch64-unknown-linux-musl","armv7-unknown-linux-musleabi"]
pre-build = ["apk add --no-cache gcc musl-dev pkgconfig openssl-dev libc-dev git"]

[target."aarch64-unknown-linux-musl"]
image.name = "alpine:edge"
image.toolchain = ["x86_64-unknown-linux-musl", "linux/arm64=aarch64-unknown-linux-musl","armv7-unknown-linux-musleabi"]
pre-build = ["apk add --no-cache gcc musl-dev pkgconfig openssl-dev libc-dev git"]
env.passthrough = ["RUSTFLAGS","TARGET_CC=gcc"]

[target."armv7-unknown-linux-musleabi"]
image.name = "alpine:edge"
image.toolchain = ["x86_64-unknown-linux-musl", "linux/arm64=aarch64-unknown-linux-musl","armv7-unknown-linux-musleabi"]
pre-build = ["apk add --no-cache gcc musl-dev pkgconfig openssl-dev libc-dev git"]
env.passthrough = ["RUSTFLAGS","TARGET_CC=gcc", "CFLAGS=-mno-outline-atomics"]

I get a lot of this output when I compile my rust app

788ff71aac7e9ab5.podfetch.b6c798b2-cgu.0.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /target/aarch64-unknown-linux-musl/release/deps/podfetch-788ff71aac7e9ab5.podfetch.b6c798b2-cgu.0.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /target/aarch64-unknown-linux-musl/release/deps/podfetch-788ff71aac7e9ab5.podfetch.b6c798b2-cgu.0.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /target/aarch64-unknown-linux-musl/release/deps/podfetch-788ff71aac7e9ab5.podfetch.b6c798b2-cgu.0.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /target/aarch64-unknown-linux-musl/release/deps/podfetch-788ff71aac7e9ab5.podfetch.b6c798b2-cgu.0.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /target/aarch64-unknown-linux-musl/release/deps/podfetch-788ff71aac7e9ab5.podfetch.b6c798b2-cgu.0.rcgu.o: Relocations in generic ELF (EM: 183) 

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

aarch64-unknown-linux-musl, arm-unknown-linux-musleabihf, x86_64-unknown-linux-musl

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

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

What architecture is the host?

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

What container engine is cross using?

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

cross version

cross 0.2.5 (892fdfa 2023-05-02)

Example

git clone https://github.com/SamTV12345/PodFetch.git
git checkout armv7/sup
RUSTFLAGS='-C target-feature=-crt-static' cross build --release --target x86_64-unknown-linux-musl
RUSTFLAGS='-C target-feature=-crt-static' cross build --release --target aarch64-unknown-linux-musl
RUSTFLAGS='-C target-feature=-crt-static' cross build --release --target armv7-unknown-linux-musleabi

Additional information / notes

No response

SamTV12345 avatar May 11 '23 07:05 SamTV12345

cross compiling with alpine seems to be a bit tricky, we've had some conversations about this in the chat

I don't have much knowledge on how it works, but seems that you need to use different roots and possibly emulation.

I have found this SO post and this wiki page

To me, this suggests that there are no distributed cross-compilers and you need to setup the environment yourself or that you use the same host as the target.

The builds where you use alpine and target = host work fine, the problem is when they don't match, right @SamTV12345?. In the issue you're stating that all your configured targets are broken, but it's only aarch64-unknown-linux-musl and armv7-unknown-linux-musleabi? cross build --release --target x86_64-unknown-linux-musl works for me when using

[target."x86_64-unknown-linux-musl"]
image.name = "alpine:edge"
image.toolchain = ["x86_64-unknown-linux-musl"]
pre-build = ["apk add --no-cache gcc musl-dev pkgconfig openssl-dev libc-dev git"]
❯ cross build --target x86_64-unknown-linux-musl

[+] Building 2.3s (7/7) FINISHED                                                                           
 => [internal] load build definition from Dockerfile.x86_64-unknown-linux-musl-custom                 0.0s
 => => transferring dockerfile: 211B                                                                  0.0s
 => [internal] load .dockerignore                                                                     0.0s
 => => transferring context: 34B                                                                      0.0s
 => [internal] load metadata for docker.io/library/alpine:edge                                        2.2s
 => [auth] library/alpine:pull token for registry-1.docker.io                                         0.0s
 => [1/2] FROM docker.io/library/alpine:edge@sha256:2d01a16bab53a8405876cec4c27235d47455a7b72b75334c  0.0s
 => CACHED [2/2] RUN eval "apk add --no-cache gcc musl-dev pkgconfig openssl-dev libc-dev git"        0.0s
 => exporting to image                                                                                0.0s
 => => exporting layers                                                                               0.0s
 => => writing image sha256:85e77eb141a5e7b56b8435ad02301a726816e5a07545b30d9f3651f40c4653a5          0.0s
 => => naming to localhost/cross-rs/cross-custom-podfetch:x86_64-unknown-linux-musl-6e004-pre-build   0.0s
   Compiling podfetch v0.1.0 (/Users/emil/workspace/dev_space/PodFetch)
warning: unused import: `std::cmp::Ordering`
 --> src/controllers/watch_time_controller.rs:1:5
  |
1 | use std::cmp::Ordering;
  |     ^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: `podfetch` (bin "podfetch") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 5m 11s

(above is on a m1 mac, hence the long compile due to emulation, but it shouldn't matter)

related #1013

Emilgardis avatar May 11 '23 09:05 Emilgardis

Interestingly, using alpine:edge for armv8 doesn't work well, opened #1256 for that

Emilgardis avatar May 11 '23 09:05 Emilgardis

Yes you're right I should have been more specific.

SamTV12345 avatar May 12 '23 12:05 SamTV12345