Skip to content

Commit 833e03a

Browse files
authored
Merge pull request #97 from clog-tool/binary-releases
chore: adds travis config to make binary releases for multiple platfo…
2 parents 6c86f3e + 60b3502 commit 833e03a

File tree

5 files changed

+315
-11
lines changed

5 files changed

+315
-11
lines changed

.travis.yml

Lines changed: 120 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,122 @@
11
language: rust
2-
sudo: false
3-
rust:
4-
- nightly
5-
- beta
6-
- stable
7-
before_script:
8-
- git clone --depth 1 https://github.com/kbknapp/travis-cargo
9-
- ln -s ./travis-cargo/travis-cargo.py tc
2+
cache: cargo
3+
4+
env:
5+
global:
6+
- PROJECT_NAME=clog
7+
- MAKE_DEB=no
8+
9+
10+
matrix:
11+
include:
12+
# Stable channel
13+
- os: linux
14+
rust: stable
15+
env: TARGET=aarch64-unknown-linux-gnu
16+
# need Trusty because the glibc in Precise is too old and doesn't support 64-bit arm
17+
dist: trusty
18+
sudo: required
19+
# Extra packages only for this job
20+
addons:
21+
apt:
22+
packages: &aarch64_unknown_linux_gnu
23+
# Transparent emulation
24+
- qemu-user-static
25+
- binfmt-support
26+
- os: linux
27+
rust: stable
28+
env: TARGET=armv7-unknown-linux-gnueabihf
29+
# sudo is needed for binfmt_misc, which is needed for transparent user qemu emulation
30+
sudo: required
31+
addons:
32+
apt:
33+
packages: &armv7_unknown_linux_gnueabihf
34+
# Cross compiler and cross compiled C libraries
35+
- gcc-arm-linux-gnueabihf
36+
- libc6-armhf-cross
37+
- libc6-dev-armhf-cross
38+
# Transparent emulation
39+
- qemu-user-static
40+
- binfmt-support
41+
- os: osx
42+
rust: stable
43+
env: TARGET=i686-apple-darwin
44+
- os: linux
45+
rust: stable
46+
env: TARGET=i686-unknown-linux-gnu
47+
addons:
48+
apt:
49+
packages: &i686_unknown_linux_gnu
50+
# Cross compiler and cross compiled C libraries
51+
- gcc-multilib
52+
- os: linux
53+
rust: stable
54+
env: TARGET=i686-unknown-linux-musl
55+
dist: trusty
56+
sudo: required
57+
addons:
58+
apt:
59+
packages: &musl_packages
60+
- musl
61+
- musl-dev
62+
- musl-tools
63+
- os: osx
64+
rust: stable
65+
env: TARGET=x86_64-apple-darwin
66+
- os: linux
67+
rust: stable
68+
env: TARGET=x86_64-unknown-linux-gnu
69+
- os: linux
70+
rust: stable
71+
env: TARGET=x86_64-unknown-linux-musl
72+
dist: trusty
73+
sudo: required
74+
addons:
75+
apt:
76+
packages: *musl_packages
77+
78+
before_install:
79+
- export PATH="$PATH:$HOME/.cargo/bin"
80+
81+
install:
82+
- bash ci/install.sh
83+
1084
script:
11-
- |
12-
./tc cargo build &&
13-
./tc cargo test
85+
- bash ci/script.sh
86+
87+
before_deploy:
88+
- bash ci/before_deploy.sh
89+
90+
deploy:
91+
provider: releases
92+
# TODO Regenerate this api_key for your project, this one won't work for you. Here's how:
93+
# - Go to 'https://github.com/settings/tokens/new' and generate a Token with only the
94+
# `public_repo` scope enabled
95+
# - Call `travis encrypt $github_token` where $github_token is the token you got in the previous
96+
# step and `travis` is the official Travis CI gem (see https://rubygems.org/gems/travis/)
97+
# - Enter the "encrypted value" below
98+
api_key:
99+
secure: mcJ3TSKmf0doqku0CQMbUaBvLR1d5rwLlTlPPEf2DP5AZomBJqKxDzCFVZDRKeTEh4vqZj64TxVI4rjDxK7I+O4UqZXd3biEw7CTYWk/ZR9gxjbFe4/B1s6jggkF2T95skiKnw0www94jD3goyrX9rP7ylBnmu17RmSNgyRvL3U=
100+
file_glob: true
101+
file: ${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.*
102+
# don't delete the artifacts from previous phases
103+
skip_cleanup: true
104+
# deploy when a new tag is pushed
105+
on:
106+
# channel to use to produce the release artifacts
107+
# NOTE make sure you only release *once* per target
108+
# TODO you may want to pick a different channel
109+
condition: $TRAVIS_RUST_VERSION = stable
110+
tags: true
111+
112+
branches:
113+
only:
114+
# Pushes and PR to the master branch
115+
- master
116+
# IMPORTANT Ruby regex to match tags. Required, or travis won't trigger deploys when a new tag
117+
# is pushed. This regex matches semantic versions like v1.2.3-rc4+2016.02.22
118+
- /^v\d+\.\d+\.\d+.*$/
119+
120+
notifications:
121+
email:
122+
on_success: never

ci/before_deploy.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 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+
# TODO update this part to copy the artifacts that make sense for your project
18+
# NOTE All Cargo build artifacts will be under the 'target/$TARGET/{debug,release}'
19+
cp target/$TARGET/release/clog $td
20+
21+
pushd $td
22+
23+
# release tarball will look like 'rust-everywhere-v1.2.3-x86_64-unknown-linux-gnu.tar.gz'
24+
tar czf $out_dir/${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.tar.gz *
25+
26+
popd
27+
rm -r $td
28+
}
29+
30+
main() {
31+
mk_artifacts
32+
mk_tarball
33+
}
34+
35+
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
# TODO modify this function as you see fit
8+
# PROTIP Always pass `--target $TARGET` to cargo commands, this makes cargo output build artifacts
9+
# to target/$TARGET/{debug,release} which can reduce the number of needed conditionals in the
10+
# `before_deploy`/packaging phase
11+
run_test_suite() {
12+
case $TARGET in
13+
# configure emulation for transparent execution of foreign binaries
14+
aarch64-unknown-linux-gnu)
15+
export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu
16+
;;
17+
arm*-unknown-linux-gnueabihf)
18+
export QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf
19+
;;
20+
*)
21+
;;
22+
esac
23+
24+
if [ ! -z "$QEMU_LD_PREFIX" ]; then
25+
# Run tests on a single thread when using QEMU user emulation
26+
export RUST_TEST_THREADS=1
27+
fi
28+
29+
cargo build --target $TARGET --verbose
30+
cargo run --target $TARGET
31+
cargo test --target $TARGET
32+
33+
# sanity check the file type
34+
file target/$TARGET/debug/clog
35+
}
36+
37+
main() {
38+
run_test_suite
39+
}
40+
41+
main

ci/utils.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
mktempd() {
2+
echo $(mktemp -d 2>/dev/null || mktemp -d -t tmp)
3+
}
4+
5+
host() {
6+
case "$TRAVIS_OS_NAME" in
7+
linux)
8+
echo x86_64-unknown-linux-gnu
9+
;;
10+
osx)
11+
echo x86_64-apple-darwin
12+
;;
13+
esac
14+
}
15+
16+
gcc_prefix() {
17+
case "$TARGET" in
18+
aarch64-unknown-linux-gnu)
19+
echo aarch64-linux-gnu-
20+
;;
21+
arm*-gnueabihf)
22+
echo arm-linux-gnueabihf-
23+
;;
24+
*-musl)
25+
echo musl-
26+
;;
27+
*)
28+
return
29+
;;
30+
esac
31+
}
32+
33+
dobin() {
34+
[ -z $MAKE_DEB ] && die 'dobin: $MAKE_DEB not set'
35+
[ $# -lt 1 ] && die "dobin: at least one argument needed"
36+
37+
local f prefix=$(gcc_prefix)
38+
for f in "$@"; do
39+
install -m0755 $f $dtd/debian/usr/bin/
40+
${prefix}strip -s $dtd/debian/usr/bin/$(basename $f)
41+
done
42+
}
43+
44+
architecture() {
45+
case $1 in
46+
x86_64-unknown-linux-gnu|x86_64-unknown-linux-musl)
47+
echo amd64
48+
;;
49+
i686-unknown-linux-gnu|i686-unknown-linux-musl)
50+
echo i386
51+
;;
52+
arm*-unknown-linux-gnueabihf)
53+
echo armhf
54+
;;
55+
*)
56+
die "architecture: unexpected target $TARGET"
57+
;;
58+
esac
59+
}

0 commit comments

Comments
 (0)