axodotdev / cargo-dist

📦 shippable application packaging
https://axodotdev.github.io/cargo-dist/
Apache License 2.0
1.46k stars 64 forks source link

cross-compiling to aarch64-unknown-linux-gnu uses wrong linker #1378

Open andrewdavidmackenzie opened 2 weeks ago

andrewdavidmackenzie commented 2 weeks ago

Hi, request for help.

In my release the build-local-artifacts step fails for two arm arch builds I have, when building ring, thus:

   Compiling ring v0.17.8
   Compiling parking v2.2.0
The following warnings were emitted during compilation:

warning: ring@0.17.8: Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is `arm-linux-gnueabihf-gcc` installed?
warning: ring@0.17.8: Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is `arm-linux-gnueabihf-gcc` installed?

Full job here: https://github.com/andrewdavidmackenzie/pigg/actions/runs/10597707922/job/29368504382

Here is my Cargo.toml Here is my release.yml

How do I fix that?

andrewdavidmackenzie commented 2 weeks ago

Maybe comments in this thread are part of my solution? https://github.com/axodotdev/cargo-dist/issues/74

"Add gcc-aarch64-linux-gnu to cargo-dist's dependencies.apt table. This installs a cross-compilation toolchain which can be invoked as aarch64-linux-gnu-gcc."

andrewdavidmackenzie commented 2 weeks ago

I tried that, and things progressed but still this failure I need to look at more:

https://github.com/andrewdavidmackenzie/pigg/actions/runs/10599058041/job/29373158574

mistydemeo commented 2 weeks ago

It looks like your armv7-unknown-linux-gnueabihf job is running into a bug/limitation in cargo-dist.

When we determine how to install dependencies, we look at the target triple. Since armv7-unknown-linux-gnueabihf isn't a target triple we recognize, we end up skipping package installation on that platform. We'll look at fixing this, and may have other fixes for your usecase in the future. In the meantime, our customizing build setup feature, which lets you run extra steps before your build begins, may be of use in making sure you can get the toolchain you need to target that platform.

Your aarch64-unknown-linux-gnu build looks like it's using the toolchain you installed, and is failing for reasons I'm not able to help with.

andrewdavidmackenzie commented 2 weeks ago

Thanks for your detailed reply. I'll look forward to new releases that increase the target coverage.

Is there a list of target triples you recognize, I could try and change my armv7 target to match one that works? I see both mention here in the source

I'll also look at the customizing docs.

The aarch64 build was failing the same originally when I opened this issue, but that changed when I added:

[workspace.metadata.dist.dependencies.apt]
gcc-aarch64-linux-gnu = { version = '*', targets = ["aarch64-unknown-linux-gnu", "aarch64-unknown-linux-musl"] }

to my Cargo.toml, and now it's a "normal" build issue I'll have to investigate.

Thanks again.

andrewdavidmackenzie commented 2 weeks ago

I tried to customize, but suspect it's not being used.

In the armv7 job here the "Install Dependencies" step is empty.

The aarch64 job here is doing the gcc install, but I suspect it's picking that up from my meta-data in Cargo.toml

Did I get the addition of the setup right?

andrewdavidmackenzie commented 2 weeks ago

Tried a bunch of things today... no luck.

It's trying to link using "cc" and failing. job log

I'm stuck, and will have to remove these arm targets from my cargo-dist list of targets I fear...

andrewdavidmackenzie commented 2 weeks ago

When searching for the error reported in my build log:

I see posts such as this that say my error is due to

"This is invoking the wrong linker (system linker), and most likely also invoking the wrong compiler ...."

andrewdavidmackenzie commented 1 week ago

I found this bug which mentioned the same error:

https://github.com/rust-lang/rust/issues/82519

The error message here is:

 = note: /usr/bin/ld: /home/runner/work/pigg/pigg/target/aarch64-unknown-linux-gnu/dist/deps/piggui-cb0337339124d967.4g3dfa9548xp8fq1f7dediq7i.rcgu.o: Relocations in generic ELF (EM: 183)

certainly is from using "ld" and not an aarch64 linker - so seems to be the same issue.

I am going to try and force the linker for these targets by adding a .cargo/cargo.toml config file with this content:

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

I already have this in Cargo.toml: targets = ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "armv7-unknown-linux-gnueabihf", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"]

and

[workspace.metadata.dist.dependencies.apt]
gcc-aarch64-linux-gnu = { version = '*', targets = ["aarch64-unknown-linux-gnu"] }
gcc-arm-linux-gnueabihf = { version = '*', targets = ["armv7-unknown-linux-gnueabihf"] }

And I have looked up those debian packages, and confirmed that is the name of the compiler/linker binary file in the package.

NOTE: I have modified the title of this issue to reflect this one of my two cargo-dist release build errors related to arm, I have filed an issue with ring for the other.

andrewdavidmackenzie commented 1 week ago

No change. I'm out of ideas now.

andrewdavidmackenzie commented 1 week ago

@mistydemeo is there anything else I can do to help troubleshoot this issue, that could help lead to solving it?

Gankra commented 1 week ago

Apologies, Misty is on vacation this week.

Starting next week I'll be picking up

again (this time based on maturin, which some of our users are very-manually using). I think that's the only really practical way for us to support these cross-compiles.

andrewdavidmackenzie commented 2 days ago

Was wondering if work started on #74 and if we can help in any way?