Skip to content

Commit bfa5b02

Browse files
committed
Auto merge of #58 - indiv0:chore-fix-travis-ci, r=indiv0
Update Travis CI Configuration # Status * [x] Enable Travis CI builds on rustc nightly, beta, and stable * [x] Add `travis-cargo` support * [ ] Ensure Travis CI performs the following operations: * [x] build * [x] test * [x] bench * [ ] doc-upload * [ ] coveralls code checking * [ ] automated build artifact deployment (#11) * [x] Update `README.md` * [x] Update building instructions * [x] Add information on pre-compiled binaries * [x] Update the badges * [x] API Docs * [x] Travis CI * [x] crates.io * [x] coveralls.io * [ ] ..? # Related Issues * #3 * #7 * #10 * #11 * #16 * #49
2 parents 3e88676 + 07cd376 commit bfa5b02

6 files changed

Lines changed: 413 additions & 13 deletions

File tree

.travis.yml

Lines changed: 131 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,134 @@
1+
sudo: false
12
language: rust
2-
os:
3-
- linux
4-
- osx
3+
cache: cargo
4+
5+
env:
6+
global:
7+
# this will be part of the release tarball
8+
- PROJECT_NAME=colonize
9+
- RUST_BACKTRACE=1
10+
# override the default '--features unstable' used for the nightly branch
11+
- TRAVIS_CARGO_NIGHTLY_FEATURE="nightly-testing"
12+
# encrypted Github token for doc upload
13+
- secure: "OtcCEFBniy4i89KaFKEOct+JsTQF3W3+6SYWlcB4FEvljRwwpAMWzpqoHQhfNLPQiX07Da+IlKrhM5wt2PPF80dEzyIxiK6Y/fJFgd0peAkbKYwqrgoS80WoqSHYBR8STb+X6JlhxxX+/pma+ILBBFQ6UH01KEHGISlHq4ARw58="
14+
# the following are necessary for `travis-cargo coveralls --no-sudo`
15+
addons:
16+
apt:
17+
packages:
18+
- libcurl4-openssl-dev
19+
- libelf-dev
20+
- libdw-dev
21+
- binutils-dev # optional: only required for the --verify flag of coveralls
22+
23+
matrix:
24+
fast_finish: true
25+
allow_failures:
26+
- rust: nightly
27+
include:
28+
# stable channel
29+
- os: osx
30+
rust: stable
31+
env: TARGET=i686-apple-darwin
32+
- os: linux
33+
rust: stable
34+
env: TARGET=i686-unknown-linux-gnu
35+
addons:
36+
apt:
37+
packages: &i686_unknown_linux_gnu
38+
# Cross compiler and cross compiled C libraries
39+
- gcc-multilib
40+
# freetype library
41+
- libfreetype6-dev:i386
42+
- os: linux
43+
rust: stable
44+
env: TARGET=x86_64-unknown-linux-gnu
45+
# beta channel
46+
- os: osx
47+
rust: beta
48+
env: TARGET=i686-apple-darwin
49+
- os: linux
50+
rust: beta
51+
env: TARGET=i686-unknown-linux-gnu
52+
addons:
53+
apt:
54+
packages: *i686_unknown_linux_gnu
55+
- os: linux
56+
rust: beta
57+
env: TARGET=x86_64-unknown-linux-gnu
58+
# nightly channel
59+
- os: osx
60+
rust: nightly
61+
env: TARGET=i686-apple-darwin
62+
- os: linux
63+
rust: nightly
64+
env: TARGET=i686-unknown-linux-gnu
65+
addons:
66+
apt:
67+
packages: *i686_unknown_linux_gnu
68+
- os: linux
69+
rust: nightly
70+
env: TARGET=x86_64-unknown-linux-gnu
71+
72+
before_install:
73+
- |
74+
export PATH="$PATH:$HOME/.cargo/bin"
75+
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
76+
brew update &&
77+
brew install freetype
78+
fi
79+
580
install:
6-
- sudo apt-get update
7-
- sudo apt-get install gcc g++ make upx electric-fence libsdl1.2-dev mercurial
81+
- bash ci/install.sh
82+
83+
before_script:
84+
# load travis-cargo
85+
- |
86+
pip install 'travis-cargo<0.2' --user &&
87+
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
88+
export PATH=$HOME/.local/bin/:$PATH
89+
else
90+
export PATH=$HOME/Library/Python/2.7/bin:$PATH
91+
fi
92+
93+
# the main build
894
script:
9-
- cargo build -v
95+
- bash ci/script.sh
96+
97+
after_success:
98+
# upload the documentation from the build with stable (automatically only
99+
# actually runs from the master branch, not individual PRs)
100+
- travis-cargo --only stable doc-upload
101+
# measure code coverage and upload to coveralls.io (the verify argument
102+
# mitigates kcov crashes due to malformed debuginfo, at the cost of some
103+
# speed. <https://github.com/huonw/travis-cargo/issues/12>)
104+
- travis-cargo coveralls --no-sudo --verify
105+
106+
before_deploy:
107+
- bash ci/before_deploy.sh
108+
109+
deploy:
110+
provider: releases
111+
api_key:
112+
# secure Github token for release upload
113+
secure: "OtcCEFBniy4i89KaFKEOct+JsTQF3W3+6SYWlcB4FEvljRwwpAMWzpqoHQhfNLPQiX07Da+IlKrhM5wt2PPF80dEzyIxiK6Y/fJFgd0peAkbKYwqrgoS80WoqSHYBR8STb+X6JlhxxX+/pma+ILBBFQ6UH01KEHGISlHq4ARw58="
114+
file_glob: true
115+
file: ${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.*
116+
# don't delete the artifacts from previous phases
117+
skip_cleanup: true
118+
on:
119+
# channel to use to produce the release artifacts
120+
condition: $TRAVIS_RUST_VERSION = stable
121+
tags: true
122+
123+
branches:
124+
only:
125+
- master
126+
- auto
127+
# Ruby regex to match tags. Required to Travis won't trigger deploys when a
128+
# new tag is pushed. This regex matches semantic versions like
129+
# v1.2.3-rc4+2016.02.22
130+
- /^v\d+\.\d+\.\d+.*$/
131+
132+
notifications:
133+
email:
134+
on_success: never

README.md

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
1-
# colonize [![Build Status](https://travis-ci.org/indiv0/colonize.svg?branch=master)](https://travis-ci.org/indiv0/colonize)
1+
# colonize
22

3-
A Dwarf-Fortress/Rogue-like game written in Rust.
3+
<table>
4+
<tr>
5+
<td><strong>Linux / OS X</strong></td>
6+
<td><a href="https://travis-ci.org/indiv0/colonize" title="Travis Build Status"><img src="https://travis-ci.org/indiv0/colonize.svg?branch=master" alt="travis-badge"></img></a></td>
7+
</tr>
8+
<tr>
9+
<td colspan="2">
10+
<a href="https://indiv0.github.io/colonize/colonize" title="API Docs"><img src="https://img.shields.io/badge/API-docs-blue.svg" alt="api-docs-badge"></img></a>
11+
<a href="https://crates.io/crates/colonize" title="Crates.io"><img src="https://img.shields.io/crates/v/colonize.svg" alt="crates-io"></img></a>
12+
<a href="https://coveralls.io/github/indiv0/colonize?branch=master" title="Coverage Status"><img src="https://coveralls.io/repos/github/indiv0/colonize/badge.svg?branch=master" alt="coveralls-badge"></img></a>
13+
</td>
14+
</tr>
15+
</table>
416

5-
## Prerequisites
17+
A Dwarf-Fortress/Rimworld-like game written in Rust.
18+
19+
# Table of Contents
20+
21+
* [Running Precompiled Binaries](#running-precompiled-binaries)
22+
* [Compiling & Running From Source](#compiling-and-running-from-source)
23+
* [Configuration](#configuration)
24+
25+
## Running Precompiled Binaries
26+
27+
Pre-compiled binaries for each of the major targets can be found on the releases
28+
page, [here][latest-release].
29+
30+
## Compiling & Running From Source
31+
### Prerequisites
632

733
* [rust](https://www.rust-lang.org)
8-
* [libtcod](http://roguecentral.org/doryen/libtcod/)
934

10-
## Compiling
35+
### Compiling
1136

1237
Compiling on Rustc stable:
1338

@@ -21,7 +46,7 @@ Compiling on Rustc nightly:
2146
cargo build --no-default-features --features nightly
2247
```
2348

24-
## Running
49+
### Running
2550

2651
Running on Rustc stable:
2752

@@ -47,4 +72,5 @@ the root of this repo as [`colonize.json.example`][colonize-json-example].
4772

4873
In the future, the capability to define the config directory might be added.
4974

50-
[colonize-json-example]: https://github.com/indiv0/colonize/blob/master/colonize.json.example
75+
[colonize-json-example]: https://github.com/indiv0/colonize/blob/master/colonize.json.example "Example configuration"
76+
[latest-release]: https://github.com/indiv0/colonize/releases/latest "Latest release"

ci/before_deploy.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# `before_deploy` phase: here we package the build artifacts
2+
3+
set -ex
4+
5+
. $(dirname $0)/utils.sh
6+
7+
# Generate artifacts for release
8+
mk_artifacts() {
9+
cargo rustc --target $TARGET --release -- -C link_args="-s" -C opt-level=3
10+
}
11+
12+
mk_tarball() {
13+
# create a "staging" directory
14+
local td=$(mktempd)
15+
local out_dir=$(pwd)
16+
17+
# NOTE All Cargo build artifacts will be under the 'target/$TARGET/{debug,release}'
18+
cp target/$TARGET/release/colonize $td
19+
20+
pushd $td
21+
22+
# release tarball will look like 'rust-everywhere-v1.2.3-x86_64-unknown-linux-gnu.tar.gz'
23+
tar czf $out_dir/${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.tar.gz *
24+
25+
popd
26+
rm -r $td
27+
}
28+
29+
# Package your artifacts in a .deb file
30+
# NOTE right now you can only package binaries using the `dobin` command. Simply call
31+
# `dobin [file..]` to include one or more binaries in your .deb package. I'll add more commands to
32+
# install other things like manpages (`doman`) as the needs arise.
33+
# XXX This .deb packaging is minimal -- just to make your app installable via `dpkg` -- and doesn't
34+
# fully conform to Debian packaging guideliens (`lintian` raises a few warnings/errors)
35+
mk_deb() {
36+
# TODO update this part to package the artifacts that make sense for your project
37+
dobin target/$TARGET/release/colonize
38+
}
39+
40+
main() {
41+
mk_artifacts
42+
mk_tarball
43+
44+
if [ $TRAVIS_OS_NAME = linux ]; then
45+
if [ ! -z $MAKE_DEB ]; then
46+
dtd=$(mktempd)
47+
mkdir -p $dtd/debian/usr/bin
48+
49+
mk_deb
50+
51+
mkdir -p $dtd/debian/DEBIAN
52+
cat >$dtd/debian/DEBIAN/control <<EOF
53+
Package: $PROJECT_NAME
54+
Version: ${TRAVIS_TAG#v}
55+
Architecture: $(architecture $TARGET)
56+
Maintainer: $DEB_MAINTAINER
57+
Description: $DEB_DESCRIPTION
58+
EOF
59+
60+
fakeroot dpkg-deb --build $dtd/debian
61+
mv $dtd/debian.deb $PROJECT_NAME-$TRAVIS_TAG-$TARGET.deb
62+
rm -r $dtd
63+
fi
64+
fi
65+
}
66+
67+
main

ci/install.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# `install` phase: install stuff needed for the `script` phase
2+
3+
set -ex
4+
5+
. $(dirname $0)/utils.sh
6+
7+
install_c_toolchain() {
8+
case $TARGET in
9+
aarch64-unknown-linux-gnu)
10+
sudo apt-get install -y --no-install-recommends \
11+
gcc-aarch64-linux-gnu libc6-arm64-cross libc6-dev-arm64-cross
12+
;;
13+
*)
14+
# For other targets, this is handled by addons.apt.packages in .travis.yml
15+
;;
16+
esac
17+
}
18+
19+
install_rustup() {
20+
# uninstall the rust toolchain installed by travis, we are going to use rustup
21+
sh ~/rust/lib/rustlib/uninstall.sh
22+
23+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$TRAVIS_RUST_VERSION
24+
25+
rustc -V
26+
cargo -V
27+
}
28+
29+
install_standard_crates() {
30+
if [ $(host) != "$TARGET" ]; then
31+
rustup target add $TARGET
32+
fi
33+
}
34+
35+
configure_cargo() {
36+
local prefix=$(gcc_prefix)
37+
38+
if [ ! -z $prefix ]; then
39+
# information about the cross compiler
40+
${prefix}gcc -v
41+
42+
# tell cargo which linker to use for cross compilation
43+
mkdir -p .cargo
44+
cat >>.cargo/config <<EOF
45+
[target.$TARGET]
46+
linker = "${prefix}gcc"
47+
EOF
48+
fi
49+
}
50+
51+
main() {
52+
install_c_toolchain
53+
install_rustup
54+
install_standard_crates
55+
configure_cargo
56+
57+
# TODO if you need to install extra stuff add it here
58+
}
59+
60+
main

ci/script.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# `script` phase: you usually build, test and generate docs in this phase
2+
3+
set -ex
4+
5+
. $(dirname $0)/utils.sh
6+
7+
# NOTE Workaround for rust-lang/rust#31907 - disable doc tests when cross compiling
8+
# This has been fixed in the nightly channel but it would take a while to reach the other channels
9+
disable_cross_doctests() {
10+
if [ $(host) != "$TARGET" ] && [ "$TRAVIS_RUST_VERSION" = "stable" ]; then
11+
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
12+
brew install gnu-sed --default-names
13+
fi
14+
15+
find src -name '*.rs' -type f | xargs sed -i -e 's:\(//.\s*```\):\1 ignore,:g'
16+
fi
17+
}
18+
19+
# PROTIP Always pass `--target $TARGET` to cargo commands, this makes cargo output build artifacts
20+
# to target/$TARGET/{debug,release} which can reduce the number of needed conditionals in the
21+
# `before_deploy`/packaging phase
22+
run_test_suite() {
23+
case $TARGET in
24+
# configure emulation for transparent execution of foreign binaries
25+
aarch64-unknown-linux-gnu)
26+
export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu
27+
;;
28+
arm*-unknown-linux-gnueabihf)
29+
export QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf
30+
;;
31+
*)
32+
;;
33+
esac
34+
35+
if [ ! -z "$QEMU_LD_PREFIX" ]; then
36+
# Run tests on a single thread when using QEMU user emulation
37+
export RUST_TEST_THREADS=1
38+
fi
39+
40+
if [[ "$TRAVIS_RUST_VERSION" == nightly* ]]; then
41+
travis-cargo build -- --target $TARGET --no-default-features
42+
else
43+
travis-cargo build -- --target $TARGET
44+
fi &&
45+
if [[ "$TRAVIS_RUST_VERSION" == nightly* ]]; then
46+
travis-cargo test -- --target $TARGET --no-default-features
47+
else
48+
travis-cargo test -- --target $TARGET
49+
fi &&
50+
if [[ "$TRAVIS_RUST_VERSION" == nightly* ]]; then
51+
travis-cargo bench -- --target $TARGET --no-default-features
52+
else
53+
travis-cargo bench -- --target $TARGET
54+
fi &&
55+
travis-cargo --only stable doc -- --target $TARGET
56+
57+
# sanity check the file type
58+
file target/$TARGET/debug/colonize
59+
}
60+
61+
main() {
62+
disable_cross_doctests
63+
run_test_suite
64+
}
65+
66+
main

0 commit comments

Comments
 (0)