Skip to content

Commit

Permalink
Merge pull request #97 from clog-tool/binary-releases
Browse files Browse the repository at this point in the history
chore: adds travis config to make binary releases for multiple platfo…
  • Loading branch information
kbknapp committed Nov 12, 2016
2 parents 6c86f3e + 60b3502 commit 833e03a
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 11 deletions.
131 changes: 120 additions & 11 deletions .travis.yml
@@ -1,13 +1,122 @@
language: rust
sudo: false
rust:
- nightly
- beta
- stable
before_script:
- git clone --depth 1 https://github.com/kbknapp/travis-cargo
- ln -s ./travis-cargo/travis-cargo.py tc
cache: cargo

env:
global:
- PROJECT_NAME=clog
- MAKE_DEB=no


matrix:
include:
# Stable channel
- os: linux
rust: stable
env: TARGET=aarch64-unknown-linux-gnu
# need Trusty because the glibc in Precise is too old and doesn't support 64-bit arm
dist: trusty
sudo: required
# Extra packages only for this job
addons:
apt:
packages: &aarch64_unknown_linux_gnu
# Transparent emulation
- qemu-user-static
- binfmt-support
- os: linux
rust: stable
env: TARGET=armv7-unknown-linux-gnueabihf
# sudo is needed for binfmt_misc, which is needed for transparent user qemu emulation
sudo: required
addons:
apt:
packages: &armv7_unknown_linux_gnueabihf
# Cross compiler and cross compiled C libraries
- gcc-arm-linux-gnueabihf
- libc6-armhf-cross
- libc6-dev-armhf-cross
# Transparent emulation
- qemu-user-static
- binfmt-support
- os: osx
rust: stable
env: TARGET=i686-apple-darwin
- os: linux
rust: stable
env: TARGET=i686-unknown-linux-gnu
addons:
apt:
packages: &i686_unknown_linux_gnu
# Cross compiler and cross compiled C libraries
- gcc-multilib
- os: linux
rust: stable
env: TARGET=i686-unknown-linux-musl
dist: trusty
sudo: required
addons:
apt:
packages: &musl_packages
- musl
- musl-dev
- musl-tools
- os: osx
rust: stable
env: TARGET=x86_64-apple-darwin
- os: linux
rust: stable
env: TARGET=x86_64-unknown-linux-gnu
- os: linux
rust: stable
env: TARGET=x86_64-unknown-linux-musl
dist: trusty
sudo: required
addons:
apt:
packages: *musl_packages

before_install:
- export PATH="$PATH:$HOME/.cargo/bin"

install:
- bash ci/install.sh

script:
- |
./tc cargo build &&
./tc cargo test
- bash ci/script.sh

before_deploy:
- bash ci/before_deploy.sh

deploy:
provider: releases
# TODO Regenerate this api_key for your project, this one won't work for you. Here's how:
# - Go to 'https://github.com/settings/tokens/new' and generate a Token with only the
# `public_repo` scope enabled
# - Call `travis encrypt $github_token` where $github_token is the token you got in the previous
# step and `travis` is the official Travis CI gem (see https://rubygems.org/gems/travis/)
# - Enter the "encrypted value" below
api_key:
secure: mcJ3TSKmf0doqku0CQMbUaBvLR1d5rwLlTlPPEf2DP5AZomBJqKxDzCFVZDRKeTEh4vqZj64TxVI4rjDxK7I+O4UqZXd3biEw7CTYWk/ZR9gxjbFe4/B1s6jggkF2T95skiKnw0www94jD3goyrX9rP7ylBnmu17RmSNgyRvL3U=
file_glob: true
file: ${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.*
# don't delete the artifacts from previous phases
skip_cleanup: true
# deploy when a new tag is pushed
on:
# channel to use to produce the release artifacts
# NOTE make sure you only release *once* per target
# TODO you may want to pick a different channel
condition: $TRAVIS_RUST_VERSION = stable
tags: true

branches:
only:
# Pushes and PR to the master branch
- master
# IMPORTANT Ruby regex to match tags. Required, or travis won't trigger deploys when a new tag
# is pushed. This regex matches semantic versions like v1.2.3-rc4+2016.02.22
- /^v\d+\.\d+\.\d+.*$/

notifications:
email:
on_success: never
35 changes: 35 additions & 0 deletions ci/before_deploy.sh
@@ -0,0 +1,35 @@
# `before_deploy` phase: here we package the build artifacts

set -ex

. $(dirname $0)/utils.sh

# Generate artifacts for release
mk_artifacts() {
cargo build --target $TARGET --release
}

mk_tarball() {
# create a "staging" directory
local td=$(mktempd)
local out_dir=$(pwd)

# TODO update this part to copy the artifacts that make sense for your project
# NOTE All Cargo build artifacts will be under the 'target/$TARGET/{debug,release}'
cp target/$TARGET/release/clog $td

pushd $td

# release tarball will look like 'rust-everywhere-v1.2.3-x86_64-unknown-linux-gnu.tar.gz'
tar czf $out_dir/${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.tar.gz *

popd
rm -r $td
}

main() {
mk_artifacts
mk_tarball
}

main
60 changes: 60 additions & 0 deletions ci/install.sh
@@ -0,0 +1,60 @@
# `install` phase: install stuff needed for the `script` phase

set -ex

. $(dirname $0)/utils.sh

install_c_toolchain() {
case $TARGET in
aarch64-unknown-linux-gnu)
sudo apt-get install -y --no-install-recommends \
gcc-aarch64-linux-gnu libc6-arm64-cross libc6-dev-arm64-cross
;;
*)
# For other targets, this is handled by addons.apt.packages in .travis.yml
;;
esac
}

install_rustup() {
# uninstall the rust toolchain installed by travis, we are going to use rustup
sh ~/rust/lib/rustlib/uninstall.sh

curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$TRAVIS_RUST_VERSION

rustc -V
cargo -V
}

install_standard_crates() {
if [ $(host) != "$TARGET" ]; then
rustup target add $TARGET
fi
}

configure_cargo() {
local prefix=$(gcc_prefix)

if [ ! -z $prefix ]; then
# information about the cross compiler
${prefix}gcc -v

# tell cargo which linker to use for cross compilation
mkdir -p .cargo
cat >>.cargo/config <<EOF
[target.$TARGET]
linker = "${prefix}gcc"
EOF
fi
}

main() {
install_c_toolchain
install_rustup
install_standard_crates
configure_cargo

# TODO if you need to install extra stuff add it here
}

main
41 changes: 41 additions & 0 deletions ci/script.sh
@@ -0,0 +1,41 @@
# `script` phase: you usually build, test and generate docs in this phase

set -ex

. $(dirname $0)/utils.sh

# TODO modify this function as you see fit
# PROTIP Always pass `--target $TARGET` to cargo commands, this makes cargo output build artifacts
# to target/$TARGET/{debug,release} which can reduce the number of needed conditionals in the
# `before_deploy`/packaging phase
run_test_suite() {
case $TARGET in
# configure emulation for transparent execution of foreign binaries
aarch64-unknown-linux-gnu)
export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu
;;
arm*-unknown-linux-gnueabihf)
export QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf
;;
*)
;;
esac

if [ ! -z "$QEMU_LD_PREFIX" ]; then
# Run tests on a single thread when using QEMU user emulation
export RUST_TEST_THREADS=1
fi

cargo build --target $TARGET --verbose
cargo run --target $TARGET
cargo test --target $TARGET

# sanity check the file type
file target/$TARGET/debug/clog
}

main() {
run_test_suite
}

main
59 changes: 59 additions & 0 deletions ci/utils.sh
@@ -0,0 +1,59 @@
mktempd() {
echo $(mktemp -d 2>/dev/null || mktemp -d -t tmp)
}

host() {
case "$TRAVIS_OS_NAME" in
linux)
echo x86_64-unknown-linux-gnu
;;
osx)
echo x86_64-apple-darwin
;;
esac
}

gcc_prefix() {
case "$TARGET" in
aarch64-unknown-linux-gnu)
echo aarch64-linux-gnu-
;;
arm*-gnueabihf)
echo arm-linux-gnueabihf-
;;
*-musl)
echo musl-
;;
*)
return
;;
esac
}

dobin() {
[ -z $MAKE_DEB ] && die 'dobin: $MAKE_DEB not set'
[ $# -lt 1 ] && die "dobin: at least one argument needed"

local f prefix=$(gcc_prefix)
for f in "$@"; do
install -m0755 $f $dtd/debian/usr/bin/
${prefix}strip -s $dtd/debian/usr/bin/$(basename $f)
done
}

architecture() {
case $1 in
x86_64-unknown-linux-gnu|x86_64-unknown-linux-musl)
echo amd64
;;
i686-unknown-linux-gnu|i686-unknown-linux-musl)
echo i386
;;
arm*-unknown-linux-gnueabihf)
echo armhf
;;
*)
die "architecture: unexpected target $TARGET"
;;
esac
}

0 comments on commit 833e03a

Please sign in to comment.