Skip to content

Commit

Permalink
release: add a script to generate a release with bdkwallet
Browse files Browse the repository at this point in the history
  • Loading branch information
kcalvinalvin committed Apr 25, 2024
1 parent e26ce4b commit e66d383
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 0 deletions.
11 changes: 11 additions & 0 deletions release/get-rustup-targets.sh
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions release/install-musl-deps.sh
Original file line number Diff line number Diff line change
@@ -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"
147 changes: 147 additions & 0 deletions release/release-with-wallet.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e66d383

Please sign in to comment.