Skip to content

Commit

Permalink
Add builds for more platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
gdvalle committed Mar 2, 2017
1 parent bde9b5f commit 9ed53d6
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 22 deletions.
93 changes: 72 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,89 @@
sudo: false
# Based on the "trust" template v0.1.1
# https://github.com/japaric/trust/tree/v0.1.1

language: generic
dist: trusty
language: rust
services: docker
sudo: required

env:
global:
- 'PATH=$HOME/.cargo/bin/:$PATH'
- CRATE_NAME=envsub

matrix:
include:
- os: linux
env: TARGET=x86_64-unknown-linux-musl
#- os: osx
# env: TARGET=x86_64-apple-darwin
# Linux
- env: TARGET=i686-unknown-linux-gnu
- env: TARGET=i686-unknown-linux-musl
- env: TARGET=x86_64-unknown-linux-gnu
- env: TARGET=x86_64-unknown-linux-musl

addons:
apt:
packages:
- upx-ucl
# OSX
- env: TARGET=i686-apple-darwin
os: osx
- env: TARGET=x86_64-apple-darwin
os: osx

# *BSD
- env: TARGET=i686-unknown-freebsd DISABLE_TESTS=1
- env: TARGET=x86_64-unknown-freebsd DISABLE_TESTS=1
- env: TARGET=x86_64-unknown-netbsd DISABLE_TESTS=1

# Other architectures
- env: TARGET=aarch64-unknown-linux-gnu
- env: TARGET=armv7-unknown-linux-gnueabihf
- env: TARGET=mips-unknown-linux-gnu
- env: TARGET=mips64-unknown-linux-gnuabi64
- env: TARGET=mips64el-unknown-linux-gnuabi64
- env: TARGET=mipsel-unknown-linux-gnu
- env: TARGET=powerpc-unknown-linux-gnu
- env: TARGET=powerpc64-unknown-linux-gnu
- env: TARGET=powerpc64le-unknown-linux-gnu
- env: TARGET=s390x-unknown-linux-gnu DISABLE_TESTS=1

# Testing other channels
- env: TARGET=x86_64-unknown-linux-gnu
rust: nightly
- env: TARGET=x86_64-apple-darwin
os: osx
rust: nightly

before_install: set -e

install:
- bash ./ci/install.sh
- source ~/.cargo/env || true

script:
- make bootstrap all
- cp target/$TARGET/release/envsub envsub-$TRAVIS_TAG-$TARGET
- bash ./ci/script.sh

after_script: set +e

before_deploy:
# This is a hack to fix deploy failures from dpl.
# Apparently they thought it wasn't worth pinning octokit.
- rvm 1.9.3 do gem install octokit -v 4.3.0
- bash ./ci/before_deploy.sh

deploy:
provider: releases
api_key:
secure: imeZd34kwpLJ9lFuUhmydIVqnbf3Ws75doNHMOwBivm+UKuPzEmmgMuWB7j/FUSDI9AaFD1RZjWjvG+bMjlelp6CEArx9vdZPORhjnaSQGbUMsZ1PzFjTOkPeMOa+mweeAeTJkJYZkl8CvnOHwF3wqxiNuTD6m5rzomE6XRsZtBi1LKOz6Ynk/PQ1VoSoXwfa14i12hOYHzZWfET1/7fpm+EcUNjimDF1K44Uhgln7WqiEK32D0rOphkgHYJTaNMEMcm1lT7ModBrw+W83+ydfJfgSTHMz6VT8EXM4ou+9E80oXYAsOS13EOAihp2vxjrsh/h/Acdzzd+QMbJVp7qkI7mDh3M0IMpOMezxqWEFBwXn0SYGwHaRNbHFU0efKjCcqBVKyDRJ09Hu4KBvo/h4Vift0CSQHW4qj0zc5jYu9/nuxWOR8XcbogblJYkBKE+zzzETe8Nv4GdunzPDI30vyerNybcGp4FmMbLYINVYBl4Aslbi8B2MzVuXtqKl6+fGapRZoZWy0kw0aUJWAeU9mP8838L4lwICusd6RiXq2opb8xwpY2fDJkERogxNfyPVjJRDdh9y33RQ8JpCvFKd29cSt7oLb1wmJrNWSBlRXdVCLIRS+1iD4cdEr4LZ/77CPFcOCo2AjFF4p6xf55eFyKCvm3yBWjQmrVJASQXjA=
file: envsub-$TRAVIS_TAG-$TARGET
skip_cleanup: true
secure: FzOd114HkQwSOsTftckdJUUnym1VSIk6QdNYuxR/F89rfZYZYw3lCGNGOGgJ5TmzwJ3hjga5k32jC1Ms96wJdyiR6iEskrspuWZdBxQKi0zL9BbQcDcutBvh0Kj/sQgU4nuot0nrpKUJjnw+a1BEkf4itWM2eEOTupxjMZ5K05MhZoF6sN/vNey1tFdV53lu7cPBmdfj9QzkqYPVqFOjYkeO+/6OXsehHN1VFduYJQS8zk+3VdAhNaTMxOsEgw10p5MWN2O7cGWDC4cQOYBUh/A8lOMmNjegxp8QYD/LamM8v8eouKOaHjf56S5Wp76GxDHWm9AWmBp+TvrNOizQWtWVcilKJ/npDInSsyTUjTDB+P09mpHVr0DW6hTQq8HpSHMuKkWg5V3dMoElDpUDUaA+MVl1YnFNdpS7arxR6m3Pv0De1Il0YOd35EDWvzxz2V8MfdmLfXwT58FCYRqFKdwAdU3TQQ3aYaCs23lx0wPv+DWviUl/QXBxNwkxbiusbn15CR5JFRk8/9+RufHeflAxxiy/X0OKsCel8Cf03yW72FqnUBTIhAqdVYw9Jlh4cG2m4ecJ08brsQ3IQ1/BKOh9A9RbeUCBelssFvrJQ40hWMU6ZMPc7ZFo+0gZSbvfgm/qRoDSb7COg5HcyoXHTCa2rNxJTO52b6U0li93OGM=
file_glob: true
file: $CRATE_NAME-$TRAVIS_TAG-$TARGET.*
on:
repo: gdvalle/envsub
condition: $TRAVIS_RUST_VERSION = stable
tags: true
provider: releases
skip_cleanup: true

cache: cargo
before_cache:
# Travis can't cache files that are not readable by "others"
- chmod -R a+r $HOME/.cargo

branches:
only:
# release tags
- /^v\d+\.\d+\.\d+.*$/
- master

notifications:
email:
on_success: never
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ variables it will exit rather than expanding as empty strings. It also
fully buffers input before writing, so in-place replacement is possible.

[![Linux build status](https://travis-ci.org/gdvalle/envsub.svg?branch=master)](https://travis-ci.org/gdvalle/envsub)
[![Windows build status](https://ci.appveyor.com/api/projects/status/glvad7l46n6cq8lt/branch/master?svg=true)](https://ci.appveyor.com/project/gdvalle/envsub/branch/master)

## Why
I found the combination of unset variable expansion and unconfigurable
Expand Down
76 changes: 76 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Based on the "trust" template v0.1.1
# https://github.com/japaric/trust/tree/v0.1.1

environment:
global:
RUST_VERSION: stable

CRATE_NAME: envsub

matrix:
# MinGW
- TARGET: i686-pc-windows-gnu
- TARGET: x86_64-pc-windows-gnu

# MSVC
- TARGET: i686-pc-windows-msvc
- TARGET: x86_64-pc-windows-msvc

# Testing other channels
- TARGET: x86_64-pc-windows-gnu
RUST_VERSION: nightly
- TARGET: x86_64-pc-windows-msvc
RUST_VERSION: nightly

install:
- ps: >-
If ($Env:TARGET -eq 'x86_64-pc-windows-gnu') {
$Env:PATH += ';C:\msys64\mingw64\bin'
} ElseIf ($Env:TARGET -eq 'i686-pc-windows-gnu') {
$Env:PATH += ';C:\msys64\mingw32\bin'
}
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
- rustup-init.exe -y --default-host %TARGET% --default-toolchain %RUST_VERSION%
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- rustc -Vv
- cargo -V

test_script:
# we don't run the "test phase" when doing deploys
- if [%APPVEYOR_REPO_TAG%]==[false] (
cargo build --target %TARGET% &&
cargo build --target %TARGET% --release &&
cargo test --target %TARGET% &&
cargo test --target %TARGET% --release
)

before_deploy:
- cargo rustc --target %TARGET% --release --bin envsub -- -C lto -C panic=abort
- ps: ci\before_deploy.ps1

deploy:
artifact: /.*\.zip/
auth_token:
secure: 0C4QL3dVOD9QMqHScEhT7lIOvrtMiynv5cncHw7CrGl6WCAjIlYUZX1m29LmTUOm
description: ''
on:
RUST_VERSION: stable
appveyor_repo_tag: true
provider: GitHub

cache:
- C:\Users\appveyor\.cargo\registry
- target

branches:
only:
# Release tags
- /^v\d+\.\d+\.\d+.*$/
- master

notifications:
- provider: Email
on_build_success: false

# disable automatic builds
build: false
23 changes: 23 additions & 0 deletions ci/before_deploy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This script takes care of packaging the build artifacts that will go in the
# release zipfile

$SRC_DIR = $PWD.Path
$STAGE = [System.Guid]::NewGuid().ToString()

Set-Location $ENV:Temp
New-Item -Type Directory -Name $STAGE
Set-Location $STAGE

$ZIP = "$SRC_DIR\$($Env:CRATE_NAME)-$($Env:APPVEYOR_REPO_TAG_NAME)-$($Env:TARGET).zip"

# TODO Update this to package the right artifacts
Copy-Item "$SRC_DIR\target\$($Env:TARGET)\release\envsub.exe" '.\'

7z a "$ZIP" *

Push-AppveyorArtifact "$ZIP"

Remove-Item *.* -Force
Set-Location ..
Remove-Item $STAGE
Set-Location $SRC_DIR
40 changes: 40 additions & 0 deletions ci/before_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This script takes care of building your crate and packaging it for release

BIN="envsub"

set -ex

main() {
local src=$(pwd) \
stage=

case $TRAVIS_OS_NAME in
linux)
stage=$(mktemp -d)
;;
osx)
stage=$(mktemp -d -t tmp)
;;
esac

test -f Cargo.lock || cargo generate-lockfile

cross rustc --bin "$BIN" --target $TARGET --release -- -C lto -C "panic=abort"

cp "target/$TARGET/release/$BIN" $stage/

# Strip and compress the executable.
# Binary strip will fail on non x86 platforms because we're using the
# host's strip binary.
strip -s "$stage/$BIN" || echo "Failed stripping binary; proceeding anyway"
# Some platforms, like mips, return an UnknownExecutableFormatException.
upx --brute "$stage/$BIN" || echo "Failed compressing binary; proceeding anyway"

cd $stage
tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz *
cd $src

rm -rf $stage
}

main
33 changes: 33 additions & 0 deletions ci/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set -ex

main() {
curl https://sh.rustup.rs -sSf | \
sh -s -- -y --default-toolchain $TRAVIS_RUST_VERSION

local target=
if [ $TRAVIS_OS_NAME = linux ]; then
target=x86_64-unknown-linux-gnu
sort=sort
sudo apt-get install -y --no-install-recommends upx-ucl
else
target=x86_64-apple-darwin
sort=gsort # for `sort --sort-version`, from brew's coreutils.
brew install upx
fi

# This fetches latest stable release
local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \
| cut -d/ -f3 \
| grep -E '^v[0-9.]+$' \
| $sort --version-sort \
| tail -n1)
echo cross version: $tag
curl -LSfs https://japaric.github.io/trust/install.sh | \
sh -s -- \
--force \
--git japaric/cross \
--tag $tag \
--target $target
}

main
24 changes: 24 additions & 0 deletions ci/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This script takes care of testing your crate

set -ex

# TODO This is the "test phase", tweak it as you see fit
main() {
cross build --target $TARGET
cross build --target $TARGET --release

if [ ! -z $DISABLE_TESTS ]; then
return
fi

cross test --target $TARGET
cross test --target $TARGET --release

#cross run --target $TARGET
#cross run --target $TARGET --release
}

# we don't run the "test phase" when doing deploys
if [ -z $TRAVIS_TAG ]; then
main
fi
2 changes: 2 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn output_without_replacements() {
assert_eq!(output, expected);
}

#[cfg(not(windows))]
#[test]
fn output_with_one_replacement() {
let expected = "foo foo baz";
Expand All @@ -72,6 +73,7 @@ fn output_with_one_replacement() {
assert_eq!(output, expected);
}

#[cfg(not(windows))]
#[test]
fn multiple_inputs() {
/// Test data from kubernetes var expansion proposal doc.
Expand Down

0 comments on commit 9ed53d6

Please sign in to comment.