Skip to content

Commit e5ac4d2

Browse files
committed
Migrate project to trust
We were using rust-everywhere to test, but trust is now the main supported project. This commit brings the goods from trust, but still allows docs deploy that I've setup before
1 parent 3a7b3e3 commit e5ac4d2

File tree

4 files changed

+133
-220
lines changed

4 files changed

+133
-220
lines changed

.travis.yml

+61-65
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,88 @@
1+
# Based on the "trust" template v0.1.1
2+
# https://github.com/japaric/trust/tree/v0.1.1
3+
4+
dist: trusty
15
language: rust
2-
cache: cargo
6+
services: docker
7+
sudo: required
38

49
env:
510
global:
6-
# This will be part of the release tarball
7-
# TODO change the project name
8-
- PROJECT_NAME=pickpocket
9-
# TODO comment out this variable if you don't want to build .deb packages on all the targets.
10-
- MAKE_DEB=yes
11-
# TODO update these two variables. They are part of the .deb package metadata
12-
- DEB_MAINTAINER="Bruno Tavares <@bltavares>"
13-
- DEB_DESCRIPTION="Pocket command line manager"
14-
15-
# AFAICT There are a few ways to set up the build jobs. This one is not the DRYest but I feel is the
16-
# easiest to reason about.
17-
# TODO Feel free to remove the channels/targets you don't need
18-
# NOTE Make *sure* you don't remove a reference (&foo) if you are going to dereference it (*foo)
11+
- CRATE_NAME=pickpocket
12+
1913
matrix:
14+
# TODO These are all the build jobs. Adjust as necessary. Comment out what you
15+
# don't need
2016
include:
21-
# Stable channel
22-
- os: osx
23-
rust: stable
24-
env: TARGET=i686-apple-darwin CFLAGS="-I/usr/local/opt/openssl/include $CFLAGS" LDFLAGS="-L/usr/local/opt/openssl/lib $LDFLAGS"
25-
- os: linux
26-
rust: stable
27-
env: TARGET=i686-unknown-linux-gnu
28-
addons:
29-
apt:
30-
packages: &i686_unknown_linux_gnu
31-
# Cross compiler and cross compiled C libraries
32-
- gcc-multilib
33-
# Added packages
34-
- libssl-dev:i386
35-
- libcrypto++-dev:i386
36-
- os: osx
37-
rust: stable
38-
env: TARGET=x86_64-apple-darwin CFLAGS="-I/usr/local/opt/openssl/include $CFLAGS" LDFLAGS="-L/usr/local/opt/openssl/lib $LDFLAGS"
39-
- os: linux
40-
rust: stable
41-
env: TARGET=x86_64-unknown-linux-gnu
42-
addons:
43-
apt:
44-
packages:
45-
# Added packages
46-
- libssl-dev
47-
- libcrypto++-dev
48-
49-
before_install:
50-
- export PATH="$PATH:$HOME/.cargo/bin"
17+
# Linux
18+
- env: TARGET=i686-unknown-linux-gnu
19+
- env: TARGET=i686-unknown-linux-musl
20+
- env: TARGET=x86_64-unknown-linux-gnu
21+
- env: TARGET=x86_64-unknown-linux-musl
22+
23+
# OSX
24+
- env: TARGET=i686-apple-darwin
25+
os: osx
26+
- env: TARGET=x86_64-apple-darwin
27+
os: osx
28+
29+
# *BSD
30+
- env: TARGET=i686-unknown-freebsd DISABLE_TESTS=1
31+
- env: TARGET=x86_64-unknown-freebsd DISABLE_TESTS=1
32+
- env: TARGET=x86_64-unknown-netbsd DISABLE_TESTS=1
33+
34+
# Other architectures
35+
- env: TARGET=aarch64-unknown-linux-gnu
36+
- env: TARGET=armv7-unknown-linux-gnueabihf
37+
- env: TARGET=mips-unknown-linux-gnu
38+
- env: TARGET=mips64-unknown-linux-gnuabi64
39+
- env: TARGET=mips64el-unknown-linux-gnuabi64
40+
- env: TARGET=mipsel-unknown-linux-gnu
41+
- env: TARGET=powerpc-unknown-linux-gnu
42+
- env: TARGET=powerpc64-unknown-linux-gnu
43+
- env: TARGET=powerpc64le-unknown-linux-gnu
44+
- env: TARGET=s390x-unknown-linux-gnu DISABLE_TESTS=1
45+
46+
# Testing other channels
47+
- env: TARGET=x86_64-unknown-linux-gnu
48+
rust: nightly
49+
- env: TARGET=x86_64-apple-darwin
50+
os: osx
51+
rust: nightly
52+
53+
before_install: set -e
5154

5255
install:
53-
- bash scripts/install.sh
56+
- sh ci/install.sh
57+
- source ~/.cargo/env || true
5458

5559
script:
56-
- bash scripts/script.sh
60+
- bash ci/script.sh
61+
62+
after_script: set +e
5763

5864
before_deploy:
59-
- bash scripts/before_deploy.sh
65+
- sh ci/before_deploy.sh
6066

6167
deploy:
62-
provider: releases
63-
# TODO Regenerate this api_key for your project, this one won't work for you. Here's how:
64-
# - Go to 'https://github.com/settings/tokens/new' and generate a Token with only the
65-
# `public_repo` scope enabled
66-
# - Call `travis encrypt $github_token` where $github_token is the token you got in the previous
67-
# step and `travis` is the official Travis CI gem (see https://rubygems.org/gems/travis/)
68-
# - Enter the "encrypted value" below
6968
api_key:
7069
secure: "ICxMkUIseLvzdnE1JCqipkYQFa43pC2Sv44HA3CcI/8bgOHNbRD81d69CnHnbXZeOAdPbX6TiMKGI3UhDYpHS65sH8Z7npr51zwcC7VMHsCzOFvBcA0fWoXyEZ0CZErD6gYrzHZnfm2TDQs0p9z8x69ULY6OaQS3UUhTl6lFHtOdWXT14lirppar80HIq8+d3k8jbsxp71mTqHqcWyGV9T7Aq6wJU0c+0nNM2W6S+nVP1FUOjF4gNrtXrtBKyY6e1vTd7nz7ZGntdQeFFjAqDLOZz+0F3k3+RW2F8WJZA/nPvREFMaBiM1+ULD7JAafrh+c+CBbugPSOYpQfM7Oqn+TCdm3UFpMu4kicJFYuDj8GTw5vDi8tS9T93OfCeAYbGJsAAFv4VJYiRUxrhtm0JksEZpfT5fNo+oqi4SCmQhtz/DIcZ9FYrKEtb9A1XmcoYkmHHHIffXRtiBTQjgwoQoEA5qZPalsS/RBiSkXvlzezu1Hy08Fw+B9avxcmMWtKxzEJq9RPC6ucbBXjA09IxJjkDB3hdSx8ciQsC4QYI/U3Yhp90xzPnpOf1HU6/9xOg9zHIknPu5bB9/tk3CqThSrA8emc5oJJAsk05F/0X/ERZ3I5f3i2werevq+fp7RElzA0yPG1oFrklEPZOD2x/VAYXrrHyWNuX5kKDfjtOGE="
7170
file_glob: true
72-
file: ${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.*
73-
# don't delete the artifacts from previous phases
74-
skip_cleanup: true
75-
# deploy when a new tag is pushed
71+
file: $CRATE_NAME-$TRAVIS_TAG-$TARGET.*
7672
on:
77-
# channel to use to produce the release artifacts
78-
# NOTE make sure you only release *once* per target
79-
# TODO you may want to pick a different channel
8073
condition: $TRAVIS_RUST_VERSION = stable
8174
tags: true
75+
provider: releases
76+
skip_cleanup: true
77+
78+
cache: cargo
79+
before_cache:
80+
- chmod -R a+r $HOME/.cargo
8281

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

9187
notifications:
9288
email:

scripts/before_deploy.sh

+40-49
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,57 @@
1-
# `before_deploy` phase: here we package the build artifacts
1+
# This script takes care of building your crate and packaging it for release
22

33
set -ex
44

5-
. $(dirname $0)/utils.sh
6-
7-
# Generate artifacts for release
8-
mk_artifacts() {
9-
cargo build --target $TARGET --release
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/pickpocket-* $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)
355
mk_deb() {
36-
dobin target/$TARGET/release/pickpocket-*
37-
}
6+
if [ ! -z $MAKE_DEB ]; then
7+
dtd=$(mktempd)
8+
mkdir -p $dtd/debian/usr/bin
389

39-
main() {
40-
mk_artifacts
41-
mk_tarball
42-
43-
if [ $TRAVIS_OS_NAME = linux ]; then
44-
if [ ! -z $MAKE_DEB ]; then
45-
dtd=$(mktempd)
46-
mkdir -p $dtd/debian/usr/bin
10+
dobin target/$TARGET/release/pickpocket-*
4711

48-
mk_deb
49-
50-
mkdir -p $dtd/debian/DEBIAN
51-
cat >$dtd/debian/DEBIAN/control <<EOF
12+
mkdir -p $dtd/debian/DEBIAN
13+
cat >$dtd/debian/DEBIAN/control <<EOF
5214
Package: $PROJECT_NAME
5315
Version: ${TRAVIS_TAG#v}
5416
Architecture: $(architecture $TARGET)
5517
Maintainer: $DEB_MAINTAINER
5618
Description: $DEB_DESCRIPTION
5719
EOF
5820

59-
fakeroot dpkg-deb --build $dtd/debian
60-
mv $dtd/debian.deb $PROJECT_NAME-$TRAVIS_TAG-$TARGET.deb
61-
rm -r $dtd
62-
fi
21+
fakeroot dpkg-deb --build $dtd/debian
22+
mv $dtd/debian.deb $PROJECT_NAME-$TRAVIS_TAG-$TARGET.deb
23+
rm -r $dtd
6324
fi
6425
}
6526

27+
main() {
28+
local src=$(pwd) \
29+
stage=
30+
31+
case $TRAVIS_OS_NAME in
32+
linux)
33+
stage=$(mktemp -d)
34+
;;
35+
osx)
36+
stage=$(mktemp -d -t tmp)
37+
;;
38+
esac
39+
40+
test -f Cargo.lock || cargo generate-lockfile
41+
42+
cross rustc --target $TARGET --release -- -C lto
43+
44+
cp target/$TARGET/release/pickpocket $stage/
45+
46+
cd $stage
47+
tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz *
48+
cd $src
49+
50+
if [ $TRAVIS_OS_NAME = linux ]; then
51+
mk_deb
52+
fi
53+
54+
rm -rf $stage
55+
}
6656

57+
main

scripts/install.sh

+20-55
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,27 @@
1-
# `install` phase: install stuff needed for the `script` phase
2-
31
set -ex
42

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-
x86_64-unknown-linux-musl)
14-
sudo apt-get install -y --no-install-recommends \
15-
musl-dev musl-tools
16-
;;
17-
*)
18-
# For other targets, this is handled by addons.apt.packages in .travis.yml
19-
;;
20-
esac
21-
}
22-
23-
install_rustup() {
24-
# uninstall the rust toolchain installed by travis, we are going to use rustup
25-
sh ~/rust/lib/rustlib/uninstall.sh
26-
27-
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$TRAVIS_RUST_VERSION
28-
29-
rustc -V
30-
cargo -V
31-
}
32-
33-
install_standard_crates() {
34-
if [ $(host) != "$TARGET" ]; then
35-
rustup target add $TARGET
36-
fi
37-
}
38-
39-
configure_cargo() {
40-
local prefix=$(gcc_prefix)
41-
42-
if [ ! -z $prefix ]; then
43-
# information about the cross compiler
44-
${prefix}gcc -v
45-
46-
# tell cargo which linker to use for cross compilation
47-
mkdir -p .cargo
48-
cat >>.cargo/config <<EOF
49-
[target.$TARGET]
50-
linker = "${prefix}gcc"
51-
EOF
3+
main() {
4+
local target=
5+
if [ $TRAVIS_OS_NAME = linux ]; then
6+
target=x86_64-unknown-linux-musl
7+
sort=sort
8+
else
9+
target=x86_64-apple-darwin
10+
sort=gsort # for `sort --sort-version`, from brew's coreutils.
5211
fi
53-
}
5412

55-
main() {
56-
install_c_toolchain
57-
install_rustup
58-
install_standard_crates
59-
configure_cargo
13+
# This fetches latest stable release
14+
local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \
15+
| cut -d/ -f3 \
16+
| grep -E '^v[0.1.0-9.]+$' \
17+
| $sort --version-sort \
18+
| tail -n1)
19+
curl -LSfs https://japaric.github.io/trust/install.sh | \
20+
sh -s -- \
21+
--force \
22+
--git japaric/cross \
23+
--tag $tag \
24+
--target $target
6025
}
6126

6227
main

0 commit comments

Comments
 (0)