2016-06-13 15:46:03 +03:00
|
|
|
set -ex
|
|
|
|
|
|
|
|
# Add provided target to current Rust toolchain if it is not already
|
|
|
|
# the default or installed.
|
|
|
|
rustup_target_add() {
|
2016-06-30 18:35:14 +03:00
|
|
|
if ! rustup target list | grep -E "$1 \((default|installed)\)"
|
|
|
|
then
|
|
|
|
rustup target add $1
|
|
|
|
fi
|
2016-06-13 15:46:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Configure rustc target for cross compilation. Provided with a build
|
|
|
|
# target, this will determine which linker to use for cross compilation.
|
|
|
|
cargo_config() {
|
2016-06-30 18:35:14 +03:00
|
|
|
local prefix
|
|
|
|
|
|
|
|
case "$TARGET" in
|
|
|
|
aarch64-unknown-linux-gnu)
|
|
|
|
prefix=aarch64-linux-gnu
|
|
|
|
;;
|
|
|
|
arm*-unknown-linux-gnueabihf)
|
|
|
|
prefix=arm-linux-gnueabihf
|
|
|
|
;;
|
|
|
|
arm-unknown-linux-gnueabi)
|
|
|
|
prefix=arm-linux-gnueabi
|
|
|
|
;;
|
|
|
|
mipsel-unknown-linux-musl)
|
|
|
|
prefix=mipsel-openwrt-linux
|
|
|
|
;;
|
|
|
|
x86_64-pc-windows-gnu)
|
|
|
|
prefix=x86_64-w64-mingw32
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
mkdir -p ~/.cargo
|
|
|
|
cat >>~/.cargo/config <<EOF
|
2016-06-13 15:46:03 +03:00
|
|
|
[target.$TARGET]
|
|
|
|
linker = "$prefix-gcc"
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2016-06-22 17:47:29 +03:00
|
|
|
# Build current crate for given target and print file type information.
|
|
|
|
# If the second argument is set, a release build will be made.
|
2016-06-13 15:46:03 +03:00
|
|
|
cargo_build() {
|
2016-06-30 18:35:14 +03:00
|
|
|
local mode
|
|
|
|
if [ -z "$2" ]
|
|
|
|
then
|
|
|
|
mode=debug
|
|
|
|
else
|
|
|
|
mode=release
|
|
|
|
fi
|
|
|
|
|
|
|
|
local modeflag
|
|
|
|
if [ "$mode" == "release" ]
|
|
|
|
then
|
|
|
|
modeflag=--release
|
|
|
|
fi
|
|
|
|
|
|
|
|
cargo build --target $1 $modeflag
|
|
|
|
|
|
|
|
file $(get_binary $1 $mode)
|
2016-06-13 15:46:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Run current crate's tests if the current system supports it.
|
|
|
|
cargo_test() {
|
2016-06-30 18:35:14 +03:00
|
|
|
if echo "$1" | grep -E "(i686|x86_64)-unknown-linux-(gnu|musl)|darwin"
|
|
|
|
then
|
|
|
|
cargo test --target $1
|
|
|
|
fi
|
2016-06-22 17:47:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Returns relative path to binary
|
|
|
|
# based on build target and type ("release"/"debug").
|
|
|
|
get_binary() {
|
2016-06-30 18:35:14 +03:00
|
|
|
local ext
|
|
|
|
if [[ "$1" =~ "windows" ]]
|
|
|
|
then
|
|
|
|
ext=".exe"
|
|
|
|
fi
|
|
|
|
echo "target/$1/$2/geckodriver$ext"
|
2016-06-22 17:47:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create a compressed archive of the binary
|
|
|
|
# for the given given git tag, build target, and build type.
|
|
|
|
package_binary() {
|
2016-06-30 18:35:14 +03:00
|
|
|
local bin
|
2016-07-01 19:32:17 +03:00
|
|
|
bin=$(get_binary $2 $4)
|
2016-06-30 18:35:14 +03:00
|
|
|
cp $bin .
|
|
|
|
|
|
|
|
if [[ "$2" =~ "windows" ]]
|
|
|
|
then
|
2016-07-01 19:32:17 +03:00
|
|
|
zip geckodriver-$1-$3.zip geckodriver.exe
|
|
|
|
file geckodriver-$1-$3.zip
|
2016-06-30 18:35:14 +03:00
|
|
|
else
|
2016-07-01 19:32:17 +03:00
|
|
|
tar zcvf geckodriver-$1-$3.tar.gz geckodriver
|
|
|
|
file geckodriver-$1-$3.tar.gz
|
2016-06-30 18:35:14 +03:00
|
|
|
fi
|
2016-06-13 15:46:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2016-06-30 18:35:14 +03:00
|
|
|
rustup_target_add $TARGET
|
|
|
|
|
|
|
|
cargo_config $TARGET
|
|
|
|
cargo_build $TARGET
|
|
|
|
cargo_test $TARGET
|
|
|
|
|
|
|
|
# when something is tagged,
|
|
|
|
# also create a release build and package it
|
|
|
|
if [ ! -z "$TRAVIS_TAG" ]
|
|
|
|
then
|
|
|
|
cargo_build $TARGET 1
|
2016-07-01 19:32:17 +03:00
|
|
|
package_binary $TRAVIS_TAG $TARGET $NAME "release"
|
2016-06-30 18:35:14 +03:00
|
|
|
fi
|
2016-06-13 15:46:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
main
|