#!/bin/bash set -euxo pipefail ROOT_DIR="${ROOT_DIR:-$( cd "$(dirname "$(realpath "$( dirname "${BASH_SOURCE[0]}" )")")" >/dev/null 2>&1 && pwd )}" NODE_DIR="$ROOT_DIR/vdf" BINARIES_DIR="$ROOT_DIR/target/release" pushd "$NODE_DIR" > /dev/null export CGO_ENABLED=1 os_type="$(uname)" case "$os_type" in "Darwin") # Check if the architecture is ARM if [[ "$(uname -m)" == "arm64" ]]; then # MacOS ld doesn't support -Bstatic and -Bdynamic, so it's important that there is only a static version of the library go build -ldflags "-linkmode 'external' -extldflags '-L$BINARIES_DIR -lvdf -ldl -lm -lflint -lgmp -lmpfr -lstdc++'" "$@" else echo "Unsupported platform" exit 1 fi ;; "Linux") ls -l $BINARIES_DIR export CGO_LDFLAGS="-L/usr/local/lib -lflint -lgmp -lmpfr -ldl -lm -L$BINARIES_DIR -lstdc++ -lvdf -static" go build -ldflags "-linkmode 'external'" "$@" ;; *) echo "Unsupported platform" exit 1 ;; esac