2023-03-21 07:37:10 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# This script is used to build the rln library for the current platform, or download it from the
|
|
|
|
# release page if it is available.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# first argument is the build directory
|
|
|
|
build_dir=$1
|
2023-09-18 05:26:58 +00:00
|
|
|
rln_version=$2
|
|
|
|
output_filename=$3
|
2023-03-21 07:37:10 +00:00
|
|
|
|
|
|
|
if [[ -z "$build_dir" ]]; then
|
|
|
|
echo "No build directory specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-09-18 05:26:58 +00:00
|
|
|
if [[ -z "$rln_version" ]]; then
|
|
|
|
echo "No rln version specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$output_filename" ]]; then
|
|
|
|
echo "No output filename specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-03-21 07:37:10 +00:00
|
|
|
# Get the host triplet
|
|
|
|
host_triplet=$(rustup show | grep "Default host: " | cut -d' ' -f3)
|
|
|
|
|
|
|
|
# Download the prebuilt rln library if it is available
|
2023-09-18 05:26:58 +00:00
|
|
|
if curl --silent --fail-with-body -L "https://github.com/vacp2p/zerokit/releases/download/$rln_version/$host_triplet-rln.tar.gz" >> "$host_triplet-rln.tar.gz"
|
2023-03-21 07:37:10 +00:00
|
|
|
then
|
|
|
|
echo "Downloaded $host_triplet-rln.tar.gz"
|
|
|
|
tar -xzf "$host_triplet-rln.tar.gz"
|
2023-09-18 05:26:58 +00:00
|
|
|
mv release/librln.a $output_filename
|
2023-03-21 07:37:10 +00:00
|
|
|
rm -rf "$host_triplet-rln.tar.gz" release
|
|
|
|
else
|
|
|
|
echo "Failed to download $host_triplet-rln.tar.gz"
|
|
|
|
# Build rln instead
|
2023-09-18 05:26:58 +00:00
|
|
|
# first, check if submodule version = version in Makefile
|
|
|
|
submodule_version=$(cargo metadata --format-version=1 --no-deps | jq '.packages[] | select(.name == "rln") | .version')
|
|
|
|
if [[ "v$submodule_version" != "$rln_version" ]]; then
|
|
|
|
echo "Submodule version (v$submodule_version) does not match version in Makefile ($rln_version)"
|
|
|
|
echo "Please update the submodule to $rln_version"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
# if submodule version = version in Makefile, build rln
|
2023-07-24 17:25:28 +00:00
|
|
|
cargo build --release -p rln --manifest-path "$build_dir/rln/Cargo.toml"
|
2023-09-18 05:26:58 +00:00
|
|
|
cp "$build_dir/target/release/librln.a" $output_filename
|
2023-03-21 07:37:10 +00:00
|
|
|
fi
|