kornelski/cargo-deb

strip failed when cross compiling

Ludea opened this issue · 5 comments

Ludea commented

Hi,

I trying to create a .deb with my app for aarch64 from x86_64 hosts.

I install g++-aarch64-linux-gnu libc6-dev-arm64-cross, run cargo build --release --target aarch64-unknown-linux-gnu all is fine

When running cargo deb -p myapp --target aarch64-unknown-linux-gnu, I get

strip: Unable to recognise the format of the input file `/home/runner/work/myapp/myapp/target/aarch64-unknown-linux-gnu/release/myapp'
cargo-deb: unable to strip binary '/home/runner/work/myapp/myapp/target/aarch64-unknown-linux-gnu/release/myapp': strip: exit status: 1.
hint: Target-specific strip commands are configured in [target.aarch64-unknown-linux-gnu] strip = { path = "strip" } in .cargo/config

I do something wrong ?

Hi @Ludea

I have the very same issue but on a different platform.
I've fixed it by adding required information to the config.

In my case (for Raspberry Pi / ARMv7).
Content of ~/.cargo/config

[target.armv7-unknown-linux-gnueabihf]
strip = "/usr/bin/arm-linux-gnueabihf-strip"
objcopy = "/usr/bin/arm-linux-gnueabihf-objcopy"
linker = "/usr/bin/arm-linux-gnueabihf-gcc"

You can't use strip command when cross compiling, because it is platform specific, like your compiler and linker are. You need a special version for the target, configured like the error says.

Ludea commented

[target.armv7-unknown-linux-gnueabihf]
strip = "/usr/bin/arm-linux-gnueabihf-strip"
objcopy = "/usr/bin/arm-linux-gnueabihf-objcopy"
linker = "/usr/bin/arm-linux-gnueabihf-gcc"

Can we use env var to setup strip ?
I already do this when building app and creating deb

env:
        CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
        CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
        CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++

@Ludea
It seems there is no such option.

Ludea commented

closing, I use cargo config to specify strip and objcopy path