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 </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 { - 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 -}