From 8ba758885cbdcf1b1030f3224a73d3d077c56ac2 Mon Sep 17 00:00:00 2001 From: Nikita Pekin Date: Sun, 15 May 2016 16:02:53 -0400 Subject: [PATCH 1/2] chore: fix Travis CI config Build Travis CI builds with `sudo: false` and `travis-cargo`. Update the `$PATH` env var in `before_install` of `.travis.yml` to include the directory containing the rust tool chain binaries. Modify `.travis.yml` to install freetype via homebrew on OS X for Travis CI builds. Add `travis-cargo` to perform a build, test, and bench with the proper features on all of the build trains. Enable `travis-cargo` doc upload for stable builds on the master branch. Add code coverage checking via coveralls. Add the `RUST_BACKTRACE=1` env var for builds. Add the `TRAVIS_CARGO_NIGHTLY_FEATURE` env var to specify the default feature for nightly builds. Add secure `GH_TOKEN` for doc uploads. Restrict Travis CI builds to `master` and `auto` branches, as well as PRs. Allow build failures on rustc nightly. Enable `fast_finish` for the build matrix. Add japaric/rust-everywhere scripts to `ci` directory. Use rust-everywhere scripts in Travis CI. Use `cache: cargo` to cache cargo builds. Add `PROJECT_NAME` env var to define the project name for rust-everywhere releases. Configure the build matrix to build across stable, beta, and nightly. Configure the build matrix to build on OS X and linux. Configure the build matrix to build on i686 and x86_64 for linux. Add `before_deploy` and `deploy` sections to `.travis.yml` to configure deployment of build artifacts for all matrix targets when a new tag is pushed. Enable builds on tag branches using a Ruby regex. Configure notifications to be disabled for successful builds. --- .travis.yml | 137 ++++++++++++++++++++++++++++++++++++++++++-- ci/before_deploy.sh | 67 ++++++++++++++++++++++ ci/install.sh | 60 +++++++++++++++++++ ci/script.sh | 66 +++++++++++++++++++++ ci/utils.sh | 56 ++++++++++++++++++ 5 files changed, 380 insertions(+), 6 deletions(-) create mode 100755 ci/before_deploy.sh create mode 100755 ci/install.sh create mode 100755 ci/script.sh create mode 100755 ci/utils.sh diff --git a/.travis.yml b/.travis.yml index 34c6163..a982432 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,134 @@ +sudo: false language: rust -os: - - linux - - osx +cache: cargo + +env: + global: + # this will be part of the release tarball + - PROJECT_NAME=colonize + - RUST_BACKTRACE=1 + # override the default '--features unstable' used for the nightly branch + - TRAVIS_CARGO_NIGHTLY_FEATURE="nightly-testing" + # encrypted Github token for doc upload + - secure: "OtcCEFBniy4i89KaFKEOct+JsTQF3W3+6SYWlcB4FEvljRwwpAMWzpqoHQhfNLPQiX07Da+IlKrhM5wt2PPF80dEzyIxiK6Y/fJFgd0peAkbKYwqrgoS80WoqSHYBR8STb+X6JlhxxX+/pma+ILBBFQ6UH01KEHGISlHq4ARw58=" +# the following are necessary for `travis-cargo coveralls --no-sudo` +addons: + apt: + packages: + - libcurl4-openssl-dev + - libelf-dev + - libdw-dev + - binutils-dev # optional: only required for the --verify flag of coveralls + +matrix: + fast_finish: true + allow_failures: + - rust: nightly + include: + # stable channel + - 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 + # freetype library + - libfreetype6-dev:i386 + - os: linux + rust: stable + env: TARGET=x86_64-unknown-linux-gnu + # beta channel + - os: osx + rust: beta + env: TARGET=i686-apple-darwin + - os: linux + rust: beta + env: TARGET=i686-unknown-linux-gnu + addons: + apt: + packages: *i686_unknown_linux_gnu + - os: linux + rust: beta + env: TARGET=x86_64-unknown-linux-gnu + # nightly channel + - os: osx + rust: nightly + env: TARGET=i686-apple-darwin + - os: linux + rust: nightly + env: TARGET=i686-unknown-linux-gnu + addons: + apt: + packages: *i686_unknown_linux_gnu + - os: linux + rust: nightly + env: TARGET=x86_64-unknown-linux-gnu + +before_install: + - | + export PATH="$PATH:$HOME/.cargo/bin" + if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + brew update && + brew install freetype + fi + install: - - sudo apt-get update - - sudo apt-get install gcc g++ make upx electric-fence libsdl1.2-dev mercurial + - bash ci/install.sh + +before_script: + # load travis-cargo + - | + pip install 'travis-cargo<0.2' --user && + if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then + export PATH=$HOME/.local/bin/:$PATH + else + export PATH=$HOME/Library/Python/2.7/bin:$PATH + fi + +# the main build script: - - cargo build -v + - bash ci/script.sh + +after_success: + # upload the documentation from the build with stable (automatically only + # actually runs from the master branch, not individual PRs) + - travis-cargo --only stable doc-upload + # measure code coverage and upload to coveralls.io (the verify argument + # mitigates kcov crashes due to malformed debuginfo, at the cost of some + # speed. ) + - travis-cargo coveralls --no-sudo --verify + +before_deploy: + - bash ci/before_deploy.sh + +deploy: + provider: releases + api_key: + # secure Github token for release upload + secure: "OtcCEFBniy4i89KaFKEOct+JsTQF3W3+6SYWlcB4FEvljRwwpAMWzpqoHQhfNLPQiX07Da+IlKrhM5wt2PPF80dEzyIxiK6Y/fJFgd0peAkbKYwqrgoS80WoqSHYBR8STb+X6JlhxxX+/pma+ILBBFQ6UH01KEHGISlHq4ARw58=" + file_glob: true + file: ${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.* + # don't delete the artifacts from previous phases + skip_cleanup: true + on: + # channel to use to produce the release artifacts + condition: $TRAVIS_RUST_VERSION = stable + tags: true + +branches: + only: + - master + - auto + # Ruby regex to match tags. Required to 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 100755 index 0000000..5883d49 --- /dev/null +++ b/ci/before_deploy.sh @@ -0,0 +1,67 @@ +# `before_deploy` phase: here we package the build artifacts + +set -ex + +. $(dirname $0)/utils.sh + +# Generate artifacts for release +mk_artifacts() { + cargo rustc --target $TARGET --release -- -C link_args="-s" -C opt-level=3 +} + +mk_tarball() { + # create a "staging" directory + local td=$(mktempd) + local out_dir=$(pwd) + + # NOTE All Cargo build artifacts will be under the 'target/$TARGET/{debug,release}' + cp target/$TARGET/release/colonize $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 +} + +# Package your artifacts in a .deb file +# NOTE right now you can only package binaries using the `dobin` command. Simply call +# `dobin [file..]` to include one or more binaries in your .deb package. I'll add more commands to +# install other things like manpages (`doman`) as the needs arise. +# XXX This .deb packaging is minimal -- just to make your app installable via `dpkg` -- and doesn't +# fully conform to Debian packaging guideliens (`lintian` raises a few warnings/errors) +mk_deb() { + # TODO update this part to package the artifacts that make sense for your project + dobin target/$TARGET/release/colonize +} + +main() { + mk_artifacts + mk_tarball + + if [ $TRAVIS_OS_NAME = linux ]; then + if [ ! -z $MAKE_DEB ]; then + dtd=$(mktempd) + mkdir -p $dtd/debian/usr/bin + + mk_deb + + mkdir -p $dtd/debian/DEBIAN + cat >$dtd/debian/DEBIAN/control <>.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- + ;; + *) + 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) + echo i386 + ;; + arm*-unknown-linux-gnueabihf) + echo armhf + ;; + *) + die "architecture: unexpected target $TARGET" + ;; + esac +} From 07cd376b496ac9c3299426e238c4ba6117d26284 Mon Sep 17 00:00:00 2001 From: Nikita Pekin Date: Sun, 15 May 2016 16:51:30 -0400 Subject: [PATCH 2/2] docs(README): update `README.md` Update badge layout. Add "API Docs" badge to link the crate documentation. Add "Crates.io" badge to link to the latest crate version on crates.io. Add "Coverage Status" badge to display the current test coverage status via coveralls.io. Update the project summary. Add a table of contents. Add a section on precompiled binaries. Update the section on building and compiling from source. --- README.md | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ce390b1..d510da3 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,38 @@ -# colonize [![Build Status](https://travis-ci.org/indiv0/colonize.svg?branch=master)](https://travis-ci.org/indiv0/colonize) +# colonize -A Dwarf-Fortress/Rogue-like game written in Rust. + + + + + + + + +
Linux / OS Xtravis-badge
+ api-docs-badge + crates-io + coveralls-badge +
-## Prerequisites +A Dwarf-Fortress/Rimworld-like game written in Rust. + +# Table of Contents + +* [Running Precompiled Binaries](#running-precompiled-binaries) +* [Compiling & Running From Source](#compiling-and-running-from-source) +* [Configuration](#configuration) + +## Running Precompiled Binaries + +Pre-compiled binaries for each of the major targets can be found on the releases +page, [here][latest-release]. + +## Compiling & Running From Source +### Prerequisites * [rust](https://www.rust-lang.org) -* [libtcod](http://roguecentral.org/doryen/libtcod/) -## Compiling +### Compiling Compiling on Rustc stable: @@ -21,7 +46,7 @@ Compiling on Rustc nightly: cargo build --no-default-features --features nightly ``` -## Running +### Running Running on Rustc stable: @@ -47,4 +72,5 @@ the root of this repo as [`colonize.json.example`][colonize-json-example]. In the future, the capability to define the config directory might be added. -[colonize-json-example]: https://github.com/indiv0/colonize/blob/master/colonize.json.example +[colonize-json-example]: https://github.com/indiv0/colonize/blob/master/colonize.json.example "Example configuration" +[latest-release]: https://github.com/indiv0/colonize/releases/latest "Latest release"