diff --git a/.travis.yml b/.travis.yml index a68a2bd..65d6ca0 100644 --- a/.travis.yml +++ b/.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 diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh new file mode 100644 index 0000000..64f4992 --- /dev/null +++ b/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 diff --git a/ci/install.sh b/ci/install.sh new file mode 100644 index 0000000..3b3f28d --- /dev/null +++ b/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 </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 +}