Travis: add rust cargo offline mode
[tor.git] / .travis.yml
blob8d300004aa620be8133fef8991ae7c37cfae4025
1 language: c
3 cache:
4   ccache: true
6 compiler:
7   - gcc
8   - clang
10 os:
11   - linux
12   - osx
14 ## The build matrix in the following stanza expands into builds for each
15 ## OS and compiler.
16 env:
17   global:
18     ## The Travis CI environment allows us two cores, so let's use both.
19     - MAKEFLAGS="-j 2"
20     ## We turn on hardening by default
21     ## Also known as --enable-fragile-hardening in 0.3.0.3-alpha and later
22     - HARDENING_OPTIONS="--enable-expensive-hardening"
23     ## We turn off asciidoc by default, because it's slow
24     - ASCIIDOC_OPTIONS="--disable-asciidoc"
25   matrix:
26     ## We want to use each build option at least once
27     ##
28     ## We don't list default variable values, because we set the defaults
29     ## in global (or the default is unset)
30     -
31     ## We turn off hardening for Rust builds, because they are incompatible,
32     ## and it's going to take a while for them to be fixed. See:
33     ##   https:/trac.torproject.org/projects/tor/ticket/25386
34     ##   https:/trac.torproject.org/projects/tor/ticket/26398
35     - RUST_OPTIONS="--enable-rust --enable-cargo-online-mode" HARDENING_OPTIONS=""
37 matrix:
38   ## include creates builds with gcc, linux, sudo: false
39   include:
40     ## We include a single coverage build with the best options for coverage
41     - env: COVERAGE_OPTIONS="--enable-coverage" HARDENING_OPTIONS=""
42     ## We only want to check these build option combinations once
43     ## (they shouldn't vary by compiler or OS)
44     ## We run rust and coverage with hardening off, which seems like enough
45     # - env: HARDENING_OPTIONS=""
46     ## We check asciidoc with distcheck, to make sure we remove doc products
47     - env: ASCIIDOC_OPTIONS="" DISTCHECK="yes"
48     ## Check rust offline without distcheck (see above)
49     ## TOR_RUST_DEPENDENCIES is spelt RUST_DEPENDENCIES in 0.3.2
50     - env: RUST_OPTIONS="--enable-rust" RUST_DEPENDENCIES=true HARDENING_OPTIONS=""
52   ## Uncomment to allow the build to report success (with non-required
53   ## sub-builds continuing to run) if all required sub-builds have
54   ## succeeded.  This is somewhat buggy currently: it can cause
55   ## duplicate notifications and prematurely report success if a
56   ## single sub-build has succeeded.  See
57   ## https://github.com/travis-ci/travis-ci/issues/1696
58   # fast_finish: true
60   ## Careful! We use global envs, which makes it hard to exclude or
61   ## allow failures by env:
62   ## https://docs.travis-ci.com/user/customizing-the-build#matching-jobs-with-allow_failures
63   exclude:
64     ## Clang doesn't work in containerized builds, see below.
65     - compiler: clang
66       sudo: false
67     ## We also exclude non-containerized gcc, because they're slow and redundant.
68     - compiler: gcc
69       sudo: required
71 ## We don't need sudo. (The "apt:" stanza after this allows us to not need
72 ## sudo; otherwise, we would need it for getting dependencies.)
74 ## But we use "sudo: required" to force non-containerized builds, working
75 ## around a Travis CI environment issue: clang LeakAnalyzer fails
76 ## because it requires ptrace and the containerized environment no
77 ## longer allows ptrace.
78 ## https://github.com/travis-ci/travis-ci/issues/9033
80 ## In the matrix above, we exclude redundant combinations.
81 sudo:
82   - false
83   - required
85 ## (Linux only) Use the latest Linux image (Ubuntu Trusty)
86 dist: trusty
88 ## (Linux only) Download our dependencies
89 addons:
90   apt:
91     packages:
92       ## Required dependencies
93       - libevent-dev
94       - zlib1g-dev
95       ## Optional dependencies
96       - libcap-dev
97       - liblzma-dev
98       - libscrypt-dev
99       - libseccomp-dev
100       ## zstd doesn't exist in Ubuntu Trusty
101       #- libzstd
102       ## Conditional dependencies
103       ## Always installed, so we don't need sudo
104       - asciidoc
105       - docbook-xsl
106       - docbook-xml
107       - xmlto
109 ## (OSX only) Use the default OSX image
110 ## See https://docs.travis-ci.com/user/reference/osx#os-x-version
111 ## Default is Xcode 9.4 on macOS 10.13 as of August 2018
112 #osx_image: xcode9.4
114 before_install:
115   ## If we're on OSX, homebrew usually needs to updated first
116   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
117   ## We might be upgrading some useless packages, but that's better than missing an upgrade
118   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew upgrade; fi
120 install:
121   ## If we're on OSX use brew to install ccache (ccache is automatically installed on Linux)
122   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install ccache; fi
123   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi
124   ## If we're on OSX use brew to install required dependencies (for Linux, see the "apt:" section above)
125   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install libevent; fi
126   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install openssl; fi
127   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install pkg-config; fi
128   ## macOS comes with zlib by default, so the homebrew install is keg-only
129   # - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install zlib; fi
130   ## If we're on OSX also install the optional dependencies
131   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install libscrypt; fi
132   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install xz; fi
133   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install zstd; fi
134   ## If we're on OSX, OpenSSL is keg-only, so tor 0.2.9 and later need to be configured --with-openssl-dir= to build
135   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then OPENSSL_OPTIONS=--with-openssl-dir=`brew --prefix openssl`; fi
136   ## Install conditional features
137   ## Install coveralls
138   - if [[ "$COVERAGE_OPTIONS" != "" ]]; then pip install --user cpp-coveralls; fi
139   ## If we're on OSX, and using asciidoc, install asciidoc
140   - if [[ "$ASCIIDOC_OPTIONS" == "" ]] && [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install asciidoc; fi
141   ## If we're using Rust, download rustup
142   - if [[ "$RUST_OPTIONS" != "" ]]; then curl -Ssf -o rustup.sh https://sh.rustup.rs; fi
143   ## Install the stable channels of rustc and cargo and setup our toolchain environment
144   - if [[ "$RUST_OPTIONS" != "" ]]; then sh rustup.sh -y --default-toolchain stable; fi
145   - if [[ "$RUST_OPTIONS" != "" ]]; then source $HOME/.cargo/env; fi
146   ## If we're testing rust builds in offline-mode, then set up our vendored dependencies
147   - if [[ "$RUST_DEPENDENCIES" == "true" ]]; then export RUST_DEPENDENCIES=$PWD/src/ext/rust/crates; fi
148   ##
149   ## Finally, list installed package versions
150   - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then dpkg-query --show; fi
151   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew list --versions; fi
152   ## Get some info about rustup, rustc and cargo
153   - if [[ "$RUST_OPTIONS" != "" ]]; then which rustup; fi
154   - if [[ "$RUST_OPTIONS" != "" ]]; then which rustc; fi
155   - if [[ "$RUST_OPTIONS" != "" ]]; then which cargo; fi
156   - if [[ "$RUST_OPTIONS" != "" ]]; then rustup --version; fi
157   - if [[ "$RUST_OPTIONS" != "" ]]; then rustc --version; fi
158   - if [[ "$RUST_OPTIONS" != "" ]]; then cargo --version; fi
160 script:
161   - ./autogen.sh
162   - CONFIGURE_FLAGS="$ASCIIDOC_OPTIONS $COVERAGE_OPTIONS $HARDENING_OPTIONS $OPENSSL_OPTIONS $RUST_OPTIONS --enable-fatal-warnings --disable-silent-rules"
163   - echo $CONFIGURE_FLAGS
164   - ./configure $CONFIGURE_FLAGS
165   ## We run `make check` because that's what https://jenkins.torproject.org does.
166   - if [[ "$DISTCHECK" == "" ]]; then make check; fi
167   - if [[ "$DISTCHECK" != "" ]]; then make distcheck DISTCHECK_CONFIGURE_FLAGS="$CONFIGURE_FLAGS"; fi
169 after_failure:
170   ## configure will leave a log file with more details of config failures.
171   ## But the log is too long for travis' rendered view, so tail it.
172   - tail -1000 config.log
173   ## `make check` will leave a log file with more details of test failures.
174   - if [[ "$DISTCHECK" == "" ]]; then cat test-suite.log; fi
175   ## `make distcheck` puts it somewhere different.
176   - if [[ "$DISTCHECK" != "" ]]; then make show-distdir-testlog; fi
178 after_success:
179   ## If this build was one that produced coverage, upload it.
180   - if [[ "$COVERAGE_OPTIONS" != "" ]]; then coveralls -b . --exclude src/test --exclude src/trunnel --gcov-options '\-p'; fi
182 notifications:
183   irc:
184     channels:
185       - "irc.oftc.net#tor-ci"
186     template:
187       - "%{repository} %{branch} %{commit} - %{author}: %{commit_subject}"
188       - "Build #%{build_number} %{result}. Details: %{build_url}"
189     on_success: change
190     on_failure: change
191   email:
192     on_success: never
193     on_failure: change