summaryrefslogtreecommitdiffstats
path: root/ci
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2016-09-05 20:08:46 -0400
committerAndrew Gallant <jamslam@gmail.com>2016-09-05 20:08:46 -0400
commit1a3e7c0bb2b7f4269856f3e1f0377a6a64f4339c (patch)
treef8bd31de2e47df9ae4d4f2deda09a824e0a6fff5 /ci
parent02ac331529e2570b48ffcd4a735ad8bccb0cb72c (diff)
Trying CI.
Diffstat (limited to 'ci')
-rw-r--r--ci/before_deploy.sh35
-rw-r--r--ci/install.sh60
-rw-r--r--ci/script.sh53
-rw-r--r--ci/utils.sh56
4 files changed, 204 insertions, 0 deletions
diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh
new file mode 100644
index 00000000..b18c9b61
--- /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() {
+ RUSTFLAGS="-C target-feature=+ssse3" cargo build --target $TARGET --release --features simd-accel
+}
+
+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/xrep $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 00000000..3b3f28d4
--- /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 <<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
diff --git a/ci/script.sh b/ci/script.sh
new file mode 100644
index 00000000..b93c686d
--- /dev/null
+++ b/ci/script.sh
@@ -0,0 +1,53 @@
+# `script` phase: you usually build, test and generate docs in this phase
+
+set -ex
+
+. $(dirname $0)/utils.sh
+
+# NOTE Workaround for rust-lang/rust#31907 - disable doc tests when cross compiling
+# This has been fixed in the nightly channel but it would take a while to reach the other channels
+disable_cross_doctests() {
+ if [ $(host) != "$TARGET" ] && [ "$TRAVIS_RUST_VERSION" = "stable" ]; then
+ if [ "$TRAVIS_OS_NAME" = "osx" ]; then
+ brew install gnu-sed --default-names
+ fi
+
+ find src -name '*.rs' -type f | xargs sed -i -e 's:\(//.\s*```\):\1 ignore,:g'
+ fi
+}
+
+# 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 test --target $TARGET
+
+ # sanity check the file type
+ file target/$TARGET/debug/xrep
+}
+
+main() {
+ disable_cross_doctests
+ run_test_suite
+}
+
+main
diff --git a/ci/utils.sh b/ci/utils.sh
new file mode 100644
index 00000000..32c7de37
--- /dev/null
+++ b/ci/utils.sh
@@ -0,0 +1,56 @@
+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-
+ ;;
+ *)
+ 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
+}