From 6fb5004b850f3bf898605d65cc44e94fb08691f8 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Sun, 19 Aug 2018 15:30:59 +0200 Subject: [PATCH] Enable ARM cross-compilation closes #244 --- .travis.yml | 20 ++++++++++---------- ci/before_deploy.bash | 13 ++++++++++--- ci/before_install.bash | 26 ++++++++++++++++++++++++++ ci/script.bash | 11 +++++++++++ 4 files changed, 57 insertions(+), 13 deletions(-) create mode 100755 ci/before_install.bash create mode 100755 ci/script.bash diff --git a/.travis.yml b/.travis.yml index 975bd4e21..c365552d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,11 @@ matrix: - os: osx rust: stable env: TARGET=x86_64-apple-darwin + - os: linux + rust: stable + env: + - TARGET=arm-unknown-linux-gnueabihf + - CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc-4.8 # Beta channel. - os: linux @@ -82,13 +87,10 @@ matrix: - cargo install --debug --force rustfmt-nightly script: cargo fmt -- --check -addons: - apt: - packages: - # needed for i686-unknown-linux-gnu target - - gcc-multilib - # needed to build deb packages - - fakeroot +sudo: required + +before_install: + - ci/before_install.bash env: global: @@ -103,9 +105,7 @@ install: - if [[ $TRAVIS_OS_NAME = linux && $HOST != $TARGET ]]; then rustup target add $TARGET; fi script: - # Incorporate TARGET env var to the build and test process - - cargo build --target $TARGET --verbose - - cargo test --target $TARGET --verbose + - ci/script.bash before_deploy: - bash ci/before_deploy.bash diff --git a/ci/before_deploy.bash b/ci/before_deploy.bash index 49593d4d9..d21dce50e 100755 --- a/ci/before_deploy.bash +++ b/ci/before_deploy.bash @@ -11,18 +11,25 @@ pack() { local tempdir local out_dir local package_name + local gcc_prefix tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp) out_dir=$(pwd) package_name="$PROJECT_NAME-$TRAVIS_TAG-$TARGET" + if [[ $TARGET == "arm-unknown-linux-gnueabihf" ]]; then + gcc_prefix="arm-linux-gnueabihf-" + else + gcc_prefix="" + fi + # create a "staging" directory mkdir "$tempdir/$package_name" mkdir "$tempdir/$package_name/autocomplete" # copying the main binary cp "target/$TARGET/release/$PROJECT_NAME" "$tempdir/$package_name/" - strip "$tempdir/$package_name/$PROJECT_NAME" + "${gcc_prefix}"strip "$tempdir/$package_name/$PROJECT_NAME" # manpage, readme and license cp "doc/$PROJECT_NAME.1" "$tempdir/$package_name" @@ -57,8 +64,8 @@ make_deb() { architecture=i386 ;; *) - echo "ERROR: unknown target" >&2 - return 1 + echo "make_deb: skipping target '${TARGET}'" >&2 + return 0 ;; esac version=${TRAVIS_TAG#v} diff --git a/ci/before_install.bash b/ci/before_install.bash new file mode 100755 index 000000000..8e198765e --- /dev/null +++ b/ci/before_install.bash @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -ex + +if [ "$TRAVIS_OS_NAME" != linux ]; then + exit 0 +fi + +sudo apt-get update + +# needed to build deb packages +sudo apt-get install -y fakeroot + +# needed for i686 linux gnu target +if [[ $TARGET == i686-unknown-linux-gnu ]]; then + sudo apt-get install -y gcc-multilib +fi + +# needed for cross-compiling for arm +if [[ $TARGET == arm-unknown-linux-gnueabihf ]]; then + sudo apt-get install -y \ + gcc-4.8-arm-linux-gnueabihf \ + binutils-arm-linux-gnueabihf \ + libc6-armhf-cross \ + libc6-dev-armhf-cross +fi diff --git a/ci/script.bash b/ci/script.bash new file mode 100755 index 000000000..79f82324f --- /dev/null +++ b/ci/script.bash @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -ex + +# Incorporate TARGET env var to the build and test process +cargo build --target "$TARGET" --verbose + +# We cannot run arm executables on linux +if [[ $TARGET != arm-unknown-linux-gnueabihf ]]; then + cargo test --target "$TARGET" --verbose +fi