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
|
|
|
|
2023-09-19 10:28:12 +00:00
|
|
|
[[ -z "${build_dir}" ]] && { echo "No build directory specified"; exit 1; }
|
|
|
|
[[ -z "${rln_version}" ]] && { echo "No rln version specified"; exit 1; }
|
|
|
|
[[ -z "${output_filename}" ]] && { echo "No output filename specified"; exit 1; }
|
2023-09-18 05:26:58 +00:00
|
|
|
|
2023-03-21 07:37:10 +00:00
|
|
|
# Get the host triplet
|
2023-09-19 10:28:12 +00:00
|
|
|
host_triplet=$(rustc --version --verbose | awk '/host:/{print $2}')
|
2023-03-21 07:37:10 +00:00
|
|
|
|
2024-05-17 09:18:29 +00:00
|
|
|
tarball="${host_triplet}"
|
|
|
|
|
2024-06-20 09:35:21 +00:00
|
|
|
# use arkzkey feature for v0.5.1
|
2024-05-17 09:18:29 +00:00
|
|
|
# TODO: update this script in the future when arkzkey is default
|
2024-06-20 09:35:21 +00:00
|
|
|
if [[ "${rln_version}" == "v0.5.1" ]]; then
|
2024-05-17 09:18:29 +00:00
|
|
|
tarball+="-arkzkey-rln.tar.gz"
|
|
|
|
else
|
|
|
|
tarball+="-rln.tar.gz"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2023-03-21 07:37:10 +00:00
|
|
|
# Download the prebuilt rln library if it is available
|
2023-09-19 10:28:12 +00:00
|
|
|
if curl --silent --fail-with-body -L \
|
2024-05-17 09:18:29 +00:00
|
|
|
"https://github.com/vacp2p/zerokit/releases/download/$rln_version/$tarball" \
|
|
|
|
-o "${tarball}";
|
2023-03-21 07:37:10 +00:00
|
|
|
then
|
2024-05-17 09:18:29 +00:00
|
|
|
echo "Downloaded ${tarball}"
|
|
|
|
tar -xzf "${tarball}"
|
2023-09-19 10:28:12 +00:00
|
|
|
mv "release/librln.a" "${output_filename}"
|
2024-05-17 09:18:29 +00:00
|
|
|
rm -rf "${tarball}" release
|
2023-03-21 07:37:10 +00:00
|
|
|
else
|
2024-05-17 09:18:29 +00:00
|
|
|
echo "Failed to download ${tarball}"
|
2023-03-21 07:37:10 +00:00
|
|
|
# Build rln instead
|
2023-09-18 05:26:58 +00:00
|
|
|
# first, check if submodule version = version in Makefile
|
2023-09-19 10:28:12 +00:00
|
|
|
cargo metadata --format-version=1 --no-deps --manifest-path "${build_dir}/rln/Cargo.toml"
|
2024-10-23 06:29:37 +00:00
|
|
|
|
|
|
|
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
|
|
|
|
submodule_version=$(cargo metadata --format-version=1 --no-deps --manifest-path "${build_dir}/rln/Cargo.toml" | sed -n 's/.*"name":"rln","version":"\([^"]*\)".*/\1/p')
|
|
|
|
else
|
|
|
|
submodule_version=$(cargo metadata --format-version=1 --no-deps --manifest-path "${build_dir}/rln/Cargo.toml" | jq -r '.packages[] | select(.name == "rln") | .version')
|
|
|
|
fi
|
|
|
|
|
2023-09-19 10:28:12 +00:00
|
|
|
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}"
|
2023-09-18 05:26:58 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
# if submodule version = version in Makefile, build rln
|
2024-06-20 09:35:21 +00:00
|
|
|
cargo build --release -p rln --manifest-path "${build_dir}/rln/Cargo.toml" --features arkzkey
|
2023-09-19 10:28:12 +00:00
|
|
|
cp "${build_dir}/target/release/librln.a" "${output_filename}"
|
2023-03-21 07:37:10 +00:00
|
|
|
fi
|