kornelski / cargo-deb

Make Debian packages directly from Rust/Cargo projects
https://lib.rs/cargo-deb
MIT License
432 stars 52 forks source link

Dependencies not found when corss compiling #5

Closed Niels-Be closed 2 years ago

Niels-Be commented 3 years ago

When cross compiling finding dependencies will fail.

For example on Ubuntu 20.04 amd64 host and compiling for arm64:

$ apt install gcc-aarch64-linux-gnu libc6-arm64-cross
$ rustup target add aarch64-unknown-linux-gnu
$ cargo deb --target aarch64-unknown-linux-gnu
[...]
warning: dpkg-shlibdeps (./project/target/aarch64-unknown-linux-gnu/release/server): dpkg-shlibdeps: error: cannot find library libgcc_s.so.1 needed by ./project/target/aarch64-unknown-linux-gnu/release/server (ELF format: 'elf64-little' abi: '020100b700000000'; RPATH: '')
dpkg-shlibdeps: error: cannot find library libpthread.so.0 needed by ./project/target/aarch64-unknown-linux-gnu/release/server (ELF format: 'elf64-little' abi: '020100b700000000'; RPATH: '')
dpkg-shlibdeps: warning: binaries to analyze should already be installed in their package's directory
dpkg-shlibdeps: error: cannot continue due to the errors listed above
Note: libraries are not searched in other binary packages that do not have any shlibs or symbols file.
To help dpkg-shlibdeps find private libraries, you might need to use -l.

The Debian archive is successfully created, but the Depends field in the control file is empty.

The libraries are available in /usr/aarch64-linux-gnu/lib/. When manually setting export LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib/ the errors disappear and the Depends field is set. However according to the man page and the error message you should use -l argument for dpkg-shlibdeps.

Edit: I just noticed event trough it works this way, it detects the wrong dependency:

Depends: libc6:arm64 (>= 2.28), libgcc1-arm64-cross  (>= 1:4.2)

libgcc1-arm64-cross should not be there.

Upon further investigation the following command will archive the desired result, however its not very generic:

$ dpkg-shlibdeps -O -l/usr/aarch64-linux-gnu/lib/ -xlibgcc1-arm64-cross target/aarch64-unknown-linux-gnu/release/server
shlibs:Depends=libc6:arm64 (>= 2.28)
kornelski commented 3 years ago

Paging @eggerk

eggerk commented 3 years ago

I unfortunately don't have experience with cross-compiling Rust.

@kornelski Do you know how well this was working with the ldd-based dependency searching?

kornelski commented 3 years ago

I'm not sure if it worked with ldd. It might have if you had cross-ldd and appropriate sysroot?

Maybe it would be enough to strip platform suffix? (:arm64, etc.)