#! /bin/bash

set -e
set -u
set -o pipefail

# For information about setting up cross-compliation from Linux to Mac OS:
# https://www.reddit.com/r/rust/comments/6rxoty/tutorial_cross_compiling_from_linux_for_osx/
# http://alwayscoding.ca/momentos/2016/05/08/cross-compilation-to-osx-with-rust/

VERSION=$(git describe --tags)

build() {
	echo "Building for $1..."
	cargo build --release --target $2
	tar -cvjf nakacli-$VERSION-$2.tar.bz2 -C target/$2/release nakacli
	shasum -a 256 nakacli-$VERSION-$2.tar.bz2 > nakacli-$VERSION-$2.sha256
	mv *.bz2 *.sha256 target
}

rustup update
build "Mac OS" x86_64-apple-darwin
build "Linux" x86_64-unknown-linux-gnu
