51 lines
1.5 KiB
Bash
Executable File
51 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euxo pipefail
|
|
|
|
THIS_SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
|
RUST_FOLDER="$THIS_SCRIPT_DIR/../p2panda-go"
|
|
GO_FOLDER="$THIS_SCRIPT_DIR/../"
|
|
|
|
LIB_NAME="libp2panda.a"
|
|
|
|
TARGETS="x86_64-unknown-linux-musl aarch64-unknown-linux-musl"
|
|
|
|
if ! command -v cross &> /dev/null; then
|
|
echo "▸ cross tool not found, installing"
|
|
cargo install cross --git https://github.com/cross-rs/cross
|
|
fi
|
|
|
|
if ! command -v rustup &> /dev/null; then
|
|
echo "▸ rustup not found, please install it"
|
|
exit 1
|
|
else
|
|
for TARGET in $TARGETS; do
|
|
rustup target add $TARGET
|
|
done
|
|
fi
|
|
|
|
export RUSTFLAGS="-C target-feature=+crt-static"
|
|
for TARGET in $TARGETS; do
|
|
echo "▸ building for $TARGET"
|
|
cross build --manifest-path "$RUST_FOLDER/Cargo.toml" --target "$TARGET" --lib --locked --release
|
|
mkdir -p "${GO_FOLDER}/libs/${TARGET}"
|
|
cp "${RUST_FOLDER}/target/${TARGET}/release/${LIB_NAME}" "${GO_FOLDER}/libs/${TARGET}/${LIB_NAME}"
|
|
done
|
|
|
|
BINDGEN_TARGET="x86_64-unknown-linux-musl"
|
|
echo "▸ generate Go bindings"
|
|
cd "$RUST_FOLDER"
|
|
uniffi-bindgen-go \
|
|
"${GO_FOLDER}/libs/${BINDGEN_TARGET}/${LIB_NAME}" \
|
|
--library \
|
|
--out-dir "${RUST_FOLDER}/target/go"
|
|
|
|
test -f "${RUST_FOLDER}/target/go/p2panda_ffi/p2panda_ffi.go"
|
|
cp -r "${RUST_FOLDER}/target/go/p2panda_ffi/p2panda_ffi.go" "${GO_FOLDER}"
|
|
|
|
test -f "${RUST_FOLDER}/target/go/p2panda_ffi/p2panda_ffi.h"
|
|
cp -r "${RUST_FOLDER}/target/go/p2panda_ffi/p2panda_ffi.h" "${GO_FOLDER}"
|
|
|
|
go -C "${GO_FOLDER}" fmt ./...
|
|
go -C "${GO_FOLDER}" build -v p2panda_ffi.go
|