kornelski / cargo-deb

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

Cross-compiling debs for older glibc #139

Closed destenson closed 2 weeks ago

destenson commented 2 weeks ago

I am attempting to cross-compile debian packages that are compatible with versions of GLIBC older than the one installed.

I have successfully cross compiled the binary using cargo-cross with zig enabled and GLIBC version 2.27.0 using:

cross build --target aarch64-unknown-linux-gnu --release

with a Cross.toml containing:

[build.zig]
enable = true
version = "2.27.0"

After that, I verified that the version of the linked libc6 symbols are indeed <= 2.27 with objdump.

Finally, I used cargo-deb to create a .deb file:

cross deb --target aarch64-unknown-linux-gnu --no-build

or

cargo deb --target aarch64-unknown-linux-gnu --no-build

Those do create a .deb file with the cross-compiled binary. However, the control file in the created .deb contains:

Depends: libc6:arm64 (>= 2.31)

And that prevents the deb from being installed on the target system.

REDACTED:~/debs$ sudo dpkg -i REDACTED_arm64.deb
(Reading database ... 167635 files and directories currently installed.)
Preparing to unpack REDACTED_arm64.deb ...
Unpacking REDACTED (0.2.1-1) over (0.2.1-1) ...
dpkg: dependency problems prevent configuration of REDACTED:
 REDACTED depends on libc6:arm64 (>= 2.31); however:
  Version of libc6:arm64 on system is 2.27-3ubuntu1.6.

dpkg: error processing package REDACTED (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 REDACTED

Short of extracting the .deb, modifying the DEBIAN/control file manually and recreating the .deb file, how can I solve this issue? How can I get cargo-deb to depend on the intended version of libc6?

kornelski commented 2 weeks ago

You can write your own depends value in Cargo.toml metadata https://github.com/kornelski/cargo-deb?tab=readme-ov-file#packagemetadatadeb-options

When depends is computed automatically, it's done by asking dpkg, and it probably won't know better than to return Debian's current version.

destenson commented 2 weeks ago

Oh perfect, thank you @kornelski. I knew that was there, but I didn't think to use it, d'oh.