#!/usr/bin/bash
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#

set -uvex -o pipefail

cd $(dirname ${BASH_SOURCE[0]})/../

ARCH=$(uname -m)

cargo +stable test --release --target ${ARCH}-unknown-linux-musl --locked --all-targets --all-features
cargo +stable test --release --target ${ARCH}-unknown-linux-musl --locked --doc --all-features
for FEATURE in $(cargo metadata --locked --format-version 1 | jq '.packages | [.[] | select(.name=="avml")][0].features | keys | @tsv' -r); do
    cargo +stable check --release --target ${ARCH}-unknown-linux-musl --locked --no-default-features --features ${FEATURE} --features native-tls
done
cargo +stable build --release --no-default-features --target ${ARCH}-unknown-linux-musl --locked
cp target/${ARCH}-unknown-linux-musl/release/avml target/${ARCH}-unknown-linux-musl/release/avml-minimal
cargo +stable build --release --target ${ARCH}-unknown-linux-musl --locked
cargo +stable build --release --target ${ARCH}-unknown-linux-musl --locked --bin avml-upload --features "put blobstore status"
strip target/${ARCH}-unknown-linux-musl/release/avml
strip target/${ARCH}-unknown-linux-musl/release/avml-minimal
strip target/${ARCH}-unknown-linux-musl/release/avml-convert
strip target/${ARCH}-unknown-linux-musl/release/avml-upload
