You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.7 KiB

ARMv7 Dynamic Rust Project from Cargo Package

Using this Dockerfile one can build a dynamically linked Rust project from a Cargo package (.crate file, a gzipped tarball) that depends on libpcap0.8 in a Debian Stretch container targetting ARMv7.

Note that the Dockerfile does a few special things needed to account for the target architecture's development headers:

  1. The armhf architecture is added before apt is updated using dpkg --add-architecture armhf
  2. Since libpcap-dev itself has no armhf installation candidate, the specific package libpcap0.8-dev:armhf is specified instead

Without these two steps, cross compliation dependent on libraries that differ across architectures is hopeless.

Container Build

$ podman build -t crossbuild-armhf -f armhf-stretch-crate

Build Example

This assumes PROJECT_DIR is set to the path to which this repo was cloned, and that you have the Rust toolchain installed with cargo on your PATH.

The project built in this example is here.

$ mkdir ~/build_dir
$ cd ${PROJECT_DIR}/examples/pcap-example/
$ cargo package --no-verify --allow-dirty
$ cp target/package/pcap-example-0.1.0.crate ~/build_dir/
$ podman run --rm -it e BIN_NAME="pcap-example" \
	-e BIN_VERSION="0.1.0" \
	-v "${HOME}/build_dir:/opt/build:z \
	crossbuild-armhf:latest \
	/opt/build/armhf-stretch-crate.sh

# Build output redacted

$ file build_dir/*_pcap-example
build_dir/armv7-unknown-linux-gnueabihf_pcap-example: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=40ed6d3beeed98797558d4024fbdb468f58abd49, stripped