summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2016-09-05 20:08:46 -0400
committerAndrew Gallant <jamslam@gmail.com>2016-09-05 20:08:46 -0400
commit1a3e7c0bb2b7f4269856f3e1f0377a6a64f4339c (patch)
treef8bd31de2e47df9ae4d4f2deda09a824e0a6fff5
parent02ac331529e2570b48ffcd4a735ad8bccb0cb72c (diff)
Trying CI.
-rw-r--r--.travis.yml82
-rw-r--r--ci/before_deploy.sh35
-rw-r--r--ci/install.sh60
-rw-r--r--ci/script.sh53
-rw-r--r--ci/utils.sh56
-rw-r--r--src/sys.rs97
6 files changed, 276 insertions, 107 deletions
diff --git a/.travis.yml b/.travis.yml
index b26fdbbd..6dca2122 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,74 @@
+#language: rust
+#rust:
+# - stable
+# - beta
+# - nightly
+#script:
+# - cargo build --verbose
+# - cargo doc
+# - cargo test --verbose
+# - if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then
+# cargo bench --verbose;
+# fi
+
language: rust
-rust:
- - stable
- - beta
- - nightly
+cache: cargo
+
+env:
+ global:
+ - PROJECT_NAME=xrep
+matrix:
+ include:
+ # Nightly channel
+ - os: osx
+ rust: nightly
+ env: TARGET=i686-apple-darwin
+ - os: osx
+ rust: nightly
+ env: TARGET=x86_64-apple-darwin
+ - os: linux
+ rust: nightly
+ env: TARGET=i686-unknown-linux-musl
+ - os: linux
+ rust: nightly
+ env: TARGET=x86_64-unknown-linux-musl
+
+before_install:
+ - export PATH="$PATH:$HOME/.cargo/bin"
+
+install:
+ - bash ci/install.sh
+
script:
- - cargo build --verbose
- - cargo doc
- - cargo test --verbose
- - if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then
- cargo bench --verbose;
- fi
+ - bash ci/script.sh
+
+before_deploy:
+ - bash ci/before_deploy.sh
+
+deploy:
+ provider: releases
+ api_key:
+ secure: aDT53aTIcl6RLcd4/StnKT55LgJyjiCtsmu1Byy0TIEtP4ZfNhsHwCbqyZT6TLownLJPi5wLM1WRncGKNYQelFDk/mUA8YugcFDfiSN//ZZ8KLAQiI+PX6JCrFYr/ZmP4dJzFWS1hPsr/X0gdbrlb3kuQG7BI9gH3GY4yTsLNiY=
+ file_glob: true
+ file: ${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.*
+ # don't delete the artifacts from previous phases
+ skip_cleanup: true
+ # deploy when a new tag is pushed
+ on:
+ # channel to use to produce the release artifacts
+ # NOTE make sure you only release *once* per target
+ # TODO you may want to pick a different channel
+ condition: $TRAVIS_RUST_VERSION = nightly
+ tags: true
+
+branches:
+ only:
+ # Pushes and PR to the master branch
+ - master
+ # IMPORTANT Ruby regex to match tags. Required, or travis won't trigger deploys when a new tag
+ # is pushed. This regex matches semantic versions like v1.2.3-rc4+2016.02.22
+ - /^\d+\.\d+\.\d+.*$/
+
+notifications:
+ email:
+ on_success: never
diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh
new file mode 100644
index 00000000..b18c9b61
--- /dev/null
+++ b/ci/before_deploy.sh
@@ -0,0 +1,35 @@
+# `before_deploy` phase: here we package the build artifacts
+
+set -ex
+
+. $(dirname $0)/utils.sh
+
+# Generate artifacts for release
+mk_artifacts() {
+ RUSTFLAGS="-C target-feature=+ssse3" cargo build --target $TARGET --release --features simd-accel
+}
+
+mk_tarball() {
+ # create a "staging" directory
+ local td=$(mktempd)
+ local out_dir=$(pwd)
+
+ # TODO update this part to copy the artifacts that make sense for your project
+ # NOTE All Cargo build artifacts will be under the 'target/$TARGET/{debug,release}'
+ cp target/$TARGET/release/xrep $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
+}
+
+main() {
+ mk_artifacts
+ mk_tarball
+}
+
+main
diff --git a/ci/install.sh b/ci/install.sh
new file mode 100644
index 00000000..3b3f28d4
--- /dev/null
+++ b/ci/install.sh
@@ -0,0 +1,60 @@
+# `install` phase: install stuff needed for the `script` phase
+
+set -ex
+
+. $(dirname $0)/utils.sh
+
+install_c_toolchain() {
+ case $TARGET in
+ aarch64-unknown-linux-gnu)
+ sudo apt-get install -y --no-install-recommends \
+ gcc-aarch64-linux-gnu libc6-arm64-cross libc6-dev-arm64-cross
+ ;;
+ *)
+ # For other targets, this is handled by addons.apt.packages in .travis.yml
+ ;;
+ esac
+}
+
+install_rustup() {
+ # uninstall the rust toolchain installed by travis, we are going to use rustup
+ sh ~/rust/lib/rustlib/uninstall.sh
+
+ curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$TRAVIS_RUST_VERSION
+
+ rustc -V
+ cargo -V
+}
+
+install_standard_crates() {
+ if [ $(host) != "$TARGET" ]; then
+ rustup target add $TARGET
+ fi
+}
+
+configure_cargo() {
+ local prefix=$(gcc_prefix)
+
+ if [ ! -z $prefix ]; then
+ # information about the cross compiler
+ ${prefix}gcc -v
+
+ # tell cargo which linker to use for cross compilation
+ mkdir -p .cargo
+ cat >>.cargo/config <<EOF
+[target.$TARGET]
+linker = "${prefix}gcc"
+EOF
+ fi
+}
+
+main() {
+ install_c_toolchain
+ install_rustup
+ install_standard_crates
+ configure_cargo
+
+ # TODO if you need to install extra stuff add it here
+}
+
+main
diff --git a/ci/script.sh b/ci/script.sh
new file mode 100644
index 00000000..b93c686d
--- /dev/null
+++ b/ci/script.sh
@@ -0,0 +1,53 @@
+# `script` phase: you usually build, test and generate docs in this phase
+
+set -ex
+
+. $(dirname $0)/utils.sh
+
+# NOTE Workaround for rust-lang/rust#31907 - disable doc tests when cross compiling
+# This has been fixed in the nightly channel but it would take a while to reach the other channels
+disable_cross_doctests() {
+ if [ $(host) != "$TARGET" ] && [ "$TRAVIS_RUST_VERSION" = "stable" ]; then
+ if [ "$TRAVIS_OS_NAME" = "osx" ]; then
+ brew install gnu-sed --default-names
+ fi
+
+ find src -name '*.rs' -type f | xargs sed -i -e 's:\(//.\s*```\):\1 ignore,:g'
+ fi
+}
+
+# TODO modify this function as you see fit
+# PROTIP Always pass `--target $TARGET` to cargo commands, this makes cargo output build artifacts
+# to target/$TARGET/{debug,release} which can reduce the number of needed conditionals in the
+# `before_deploy`/packaging phase
+run_test_suite() {
+ case $TARGET in
+ # configure emulation for transparent execution of foreign binaries
+ aarch64-unknown-linux-gnu)
+ export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu
+ ;;
+ arm*-unknown-linux-gnueabihf)
+ export QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf
+ ;;
+ *)
+ ;;
+ esac
+
+ if [ ! -z "$QEMU_LD_PREFIX" ]; then
+ # Run tests on a single thread when using QEMU user emulation
+ export RUST_TEST_THREADS=1
+ fi
+
+ cargo build --target $TARGET --verbose
+ cargo test --target $TARGET
+
+ # sanity check the file type
+ file target/$TARGET/debug/xrep
+}
+
+main() {
+ disable_cross_doctests
+ run_test_suite
+}
+
+main
diff --git a/ci/utils.sh b/ci/utils.sh
new file mode 100644
index 00000000..32c7de37
--- /dev/null
+++ b/ci/utils.sh
@@ -0,0 +1,56 @@
+mktempd() {
+ echo $(mktemp -d 2>/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|i686-unknown-linux-musl)
+ echo i386
+ ;;
+ arm*-unknown-linux-gnueabihf)
+ echo armhf
+ ;;
+ *)
+ die "architecture: unexpected target $TARGET"
+ ;;
+ esac
+}
diff --git a/src/sys.rs b/src/sys.rs
index ae65f8e8..838f3541 100644
--- a/src/sys.rs
+++ b/src/sys.rs
@@ -5,9 +5,6 @@ redirected to a file? etc... We use this information to tweak various default
configuration parameters such as colors and match formatting.
*/
-use std::fs::{File, Metadata};
-use std::io;
-
use libc;
#[cfg(unix)]
@@ -43,97 +40,3 @@ pub fn stdout_is_atty() -> bool {
kernel32::GetConsoleMode(handle, &mut out) != 0
}
}
-
-// Probably everything below isn't actually needed. ---AG
-
-#[cfg(unix)]
-pub fn metadata(fd: libc::c_int) -> Result<Metadata, io::Error> {
- use std::os::unix::io::{FromRawFd, IntoRawFd};
-
- let f = unsafe { File::from_raw_fd(fd) };
- let md = f.metadata();
- // Be careful to transfer ownership back to a simple descriptor. Dropping
- // the File itself would close the descriptor, which would be quite bad!
- drop(f.into_raw_fd());
- md
-}
-
-#[cfg(unix)]
-pub fn stdin_is_file() -> bool {
- metadata(libc::STDIN_FILENO)
- .map(|md| md.file_type().is_file())
- .unwrap_or(false)
-}
-
-#[cfg(unix)]
-pub fn stdout_is_file() -> bool {
- metadata(libc::STDOUT_FILENO)
- .map(|md| md.file_type().is_file())
- .unwrap_or(false)
-}
-
-#[cfg(unix)]
-pub fn stdin_is_char_device() -> bool {
- use std::os::unix::fs::FileTypeExt;
-
- metadata(libc::STDIN_FILENO)
- .map(|md| md.file_type().is_char_device())
- .unwrap_or(false)
-}
-
-#[cfg(unix)]
-pub fn stdout_is_char_device() -> bool {
- use std::os::unix::fs::FileTypeExt;
-
- metadata(libc::STDOUT_FILENO)
- .map(|md| md.file_type().is_char_device())
- .unwrap_or(false)
-}
-
-#[cfg(unix)]
-pub fn stdin_is_fifo() -> bool {
- use std::os::unix::fs::FileTypeExt;
-
- metadata(libc::STDIN_FILENO)
- .map(|md| md.file_type().is_fifo())
- .unwrap_or(false)
-}
-
-#[cfg(unix)]
-pub fn stdout_is_fifo() -> bool {
- use std::os::unix::fs::FileTypeExt;
-
- metadata(libc::STDOUT_FILENO)
- .map(|md| md.file_type().is_fifo())
- .unwrap_or(false)
-}
-
-#[cfg(windows)]
-pub fn stdin_is_file() -> bool {
- false
-}
-
-#[cfg(windows)]
-pub fn stdout_is_file() -> bool {
- false
-}
-
-#[cfg(windows)]
-pub fn stdin_is_char_device() -> bool {
- false
-}
-
-#[cfg(windows)]
-pub fn stdout_is_char_device() -> bool {
- false
-}
-
-#[cfg(windows)]
-pub fn stdin_is_fifo() -> bool {
- false
-}
-
-#[cfg(windows)]
-pub fn stdout_is_fifo() -> bool {
- false
-}