From e66d383890684ac8f4b85469035110e4dd005c36 Mon Sep 17 00:00:00 2001 From: Calvin Kim Date: Thu, 25 Apr 2024 15:43:07 +0900 Subject: [PATCH] release: add a script to generate a release with bdkwallet --- release/get-rustup-targets.sh | 11 +++ release/install-musl-deps.sh | 27 ++++++ release/release-with-wallet.sh | 147 +++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 release/get-rustup-targets.sh create mode 100644 release/install-musl-deps.sh create mode 100755 release/release-with-wallet.sh diff --git a/release/get-rustup-targets.sh b/release/get-rustup-targets.sh new file mode 100644 index 00000000..e8c1fcda --- /dev/null +++ b/release/get-rustup-targets.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +rustup target add aarch64-unknown-linux-musl +rustup target add x86_64-unknown-linux-musl +rustup target add armv7-unknown-linux-musleabihf +rustup target add armv6-unknown-linux-musleabihf + +rustup target add aarch64-apple-darwin +rustup target add x86_64-apple-darwin + +rustup target add x86_64-pc-windows-gnu diff --git a/release/install-musl-deps.sh b/release/install-musl-deps.sh new file mode 100644 index 00000000..680d6998 --- /dev/null +++ b/release/install-musl-deps.sh @@ -0,0 +1,27 @@ +cd $HOME + +curl -LO https://musl.cc/aarch64-linux-musl-cross.tgz +curl -LO https://musl.cc/arm-linux-musleabihf-cross.tgz +curl -LO https://musl.cc/armv6-linux-musleabihf-cross.tgz +curl -LO https://musl.cc/x86_64-linux-musl-cross.tgz +curl -LO https://musl.cc/x86_64-w64-mingw32-cross.tgz + +tar -xzf aarch64-linux-musl-cross.tgz +tar -xzf arm-linux-musleabihf-cross.tgz +tar -xzf armv6-linux-musleabihf-cross.tgz +tar -xzf x86_64-linux-musl-cross.tgz +tar -xzf x86_64-w64-mingw32-cross.tgz + +rm aarch64-linux-musl-cross.tgz +rm arm-linux-musleabihf-cross.tgz +rm armv6-linux-musleabihf-cross.tgz +rm x86_64-linux-musl-cross.tgz +rm x86_64-w64-mingw32-cross.tgz + +echo export PATH=\$PATH:${HOME}/armv6-linux-musleabihf-cross/bin >> $HOME/.profile +echo export PATH=\$PATH:${HOME}/armv7-linux-musleabihf-cross/bin >> $HOME/.profile +echo export PATH=\$PATH:${HOME}/aarch64-linux-musl-cross/bin >> $HOME/.profile +echo export PATH=\$PATH:${HOME}/x86_64-linux-musl-cross/bin >> $HOME/.profile +echo export PATH=\$PATH:${HOME}/x86_64-w64-mingw32-cross/bin >> $HOME/.profile + +echo "To add the binary paths:" ". $HOME/.profile" diff --git a/release/release-with-wallet.sh b/release/release-with-wallet.sh new file mode 100755 index 00000000..f080567b --- /dev/null +++ b/release/release-with-wallet.sh @@ -0,0 +1,147 @@ +#!/bin/bash + +# Copyright (c) 2016 Company 0, LLC. +# Copyright (c) 2016-2020 The btcsuite developers +# Use of this source code is governed by an ISC +# license that can be found in the LICENSE file. + +# Simple bash script to build basic utreexod tools for all the platforms we support +# with the golang cross-compiler. + +set -e + +# If no tag specified, use date + version otherwise use tag. +if [[ $1x = x ]]; then + DATE=`date +%Y%m%d` + VERSION="01" + TAG=$DATE-$VERSION +else + TAG=$1 +fi + +go mod vendor +tar -cvzf vendor.tar.gz vendor + +PACKAGE=utreexod +MAINDIR=$PACKAGE-$TAG +mkdir -p $MAINDIR + +cp vendor.tar.gz $MAINDIR/ +rm vendor.tar.gz +rm -r vendor + +PACKAGESRC="$MAINDIR/$PACKAGE-source-$TAG.tar" +git archive -o $PACKAGESRC HEAD +gzip -f $PACKAGESRC > "$PACKAGESRC.gz" + +cd $MAINDIR + +SYS= + +if [[ $(uname) == Linux ]]; then + # If BTCDBUILDSYS is set the default list is ignored. Useful to release + # for a subset of systems/architectures. + SYS=${BTCDBUILDSYS:-" + linux-armv6 + linux-armv7 + linux-arm64 + linux-amd64 + "} +elif [[ $(uname) == Darwin ]]; then + # If BTCDBUILDSYS is set the default list is ignored. Useful to release + # for a subset of systems/architectures. + SYS=${BTCDBUILDSYS:-" + darwin-amd64 + darwin-arm64 + "} +fi + +CPUCORES= +if [[ $(uname) == Linux ]]; then + CPUCORES=$(lscpu | grep "Core(s) per socket" | awk '{print $4}') +elif [[ $(uname) == Darwin ]]; then + CPUCORES=$(sysctl -n hw.physicalcpu) +fi + +# Use the first element of $GOPATH in the case where GOPATH is a list +# (something that is totally allowed). +PKG="github.com/utreexo/utreexod" +COMMIT=$(git describe --tags --abbrev=40 --dirty) + +for i in $SYS; do + OS=$(echo $i | cut -f1 -d-) + ARCH=$(echo $i | cut -f2 -d-) + ARM= + CC= + + if [[ $ARCH = "armv6" ]]; then + ARCH=arm + ARM=6 + elif [[ $ARCH = "armv7" ]]; then + ARCH=arm + ARM=7 + fi + + mkdir $PACKAGE-$i-$TAG + echo "cd to" $PACKAGE-$i-$TAG + cd $PACKAGE-$i-$TAG + + # Build bdk wallet(rust) dependency. + if [[ $ARCH = "arm64" ]] && [[ $OS = "linux" ]]; then + TARGET="aarch64-unknown-linux-musl" + CC=aarch64-linux-musl-gcc + + elif [[ $ARCH = "amd64" ]] && [[ $OS = "linux" ]]; then + TARGET="x86_64-unknown-linux-musl" + CC=x86_64-linux-musl-gcc + + elif [[ $ARCH = "arm" ]] && [[ $OS = "linux" ]] && [[ $ARM=7 ]]; then + TARGET="armv7-unknown-linux-musleabihf" + CC=armv7-linux-musleabihf-gcc + + elif [[ $ARCH = "arm" ]] && [[ $OS = "linux" ]] && [[ $ARM=6 ]]; then + TARGET="armv6-unknown-linux-musleabihf" + CC=armv6-linux-musleabihf-gcc + + elif [[ $ARCH = "arm64" ]] && [[ $OS = "darwin" ]]; then + TARGET="aarch64-apple-darwin" + + elif [[ $ARCH = "amd64" ]] && [[ $OS = "darwin" ]]; then + TARGET="x86_64-apple-darwin" + + elif [[ $ARCH = "amd64" ]] && [[ $OS = "windows" ]]; then + TARGET="x86_64-pc-windows-gnu" + CC=x86_64-w64-mingw32-gcc + fi + + env CARGO_TARGET_DIR=. cargo build --release --target=$TARGET --jobs=$CPUCORES + mv $TARGET target + + echo "Building:" $OS $ARCH $ARM + + # Build utreexod + if [[ $OS == "linux" ]]; then + env CC=$CC CGO_ENABLED=1 GOOS=$OS GOARCH=$ARCH GOARM=$ARM go build -v -tags="bdkwallet" -ldflags="-s -w -extldflags "-static" -buildid=" github.com/utreexo/utreexod + elif [[ $OS == "darwin" ]]; then + env CGO_ENABLED=1 GOOS=$OS GOARCH=$ARCH GOARM=$ARM go build -v -tags="bdkwallet" -ldflags="-s -w -buildid=" github.com/utreexo/utreexod + fi + + # Remove bdk build things. + rm -rf target + rm -rf release + + # Build utreexoctl + env CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH GOARM=$ARM go build -v -trimpath -ldflags="-s -w -buildid=" github.com/utreexo/utreexod/cmd/utreexoctl + + cd .. + + if [[ $OS = "windows" ]]; then + zip -r $PACKAGE-$i-$TAG.zip $PACKAGE-$i-$TAG + else + tar -cvzf $PACKAGE-$i-$TAG.tar.gz $PACKAGE-$i-$TAG + fi + + rm -r $PACKAGE-$i-$TAG +done + +shasum -a 256 * > manifest-$TAG.txt