|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright (c) 2016 Company 0, LLC. |
| 4 | +# Copyright (c) 2016-2020 The btcsuite developers |
| 5 | +# Use of this source code is governed by an ISC |
| 6 | +# license that can be found in the LICENSE file. |
| 7 | + |
| 8 | +# Simple bash script to build basic utreexod tools for all the platforms we support |
| 9 | +# with the golang cross-compiler. |
| 10 | + |
| 11 | +set -e |
| 12 | + |
| 13 | +# If no tag specified, use date + version otherwise use tag. |
| 14 | +if [[ $1x = x ]]; then |
| 15 | + DATE=`date +%Y%m%d` |
| 16 | + VERSION="01" |
| 17 | + TAG=$DATE-$VERSION |
| 18 | +else |
| 19 | + TAG=$1 |
| 20 | +fi |
| 21 | + |
| 22 | +go mod vendor |
| 23 | +tar -cvzf vendor.tar.gz vendor |
| 24 | + |
| 25 | +PACKAGE=utreexod |
| 26 | +MAINDIR=$PACKAGE-$TAG |
| 27 | +mkdir -p $MAINDIR |
| 28 | + |
| 29 | +cp vendor.tar.gz $MAINDIR/ |
| 30 | +rm vendor.tar.gz |
| 31 | +rm -r vendor |
| 32 | + |
| 33 | +PACKAGESRC="$MAINDIR/$PACKAGE-source-$TAG.tar" |
| 34 | +git archive -o $PACKAGESRC HEAD |
| 35 | +gzip -f $PACKAGESRC > "$PACKAGESRC.gz" |
| 36 | + |
| 37 | +cd $MAINDIR |
| 38 | + |
| 39 | +SYS= |
| 40 | + |
| 41 | +if [[ $(uname) == Linux ]]; then |
| 42 | + # If BTCDBUILDSYS is set the default list is ignored. Useful to release |
| 43 | + # for a subset of systems/architectures. |
| 44 | + SYS=${BTCDBUILDSYS:-" |
| 45 | + linux-armv6 |
| 46 | + linux-armv7 |
| 47 | + linux-arm64 |
| 48 | + linux-amd64 |
| 49 | + windows-amd64 |
| 50 | + "} |
| 51 | +elif [[ $(uname) == Darwin ]]; then |
| 52 | + # If BTCDBUILDSYS is set the default list is ignored. Useful to release |
| 53 | + # for a subset of systems/architectures. |
| 54 | + SYS=${BTCDBUILDSYS:-" |
| 55 | + darwin-amd64 |
| 56 | + darwin-arm64 |
| 57 | + "} |
| 58 | +fi |
| 59 | + |
| 60 | +CPUCORES= |
| 61 | +if [[ $(uname) == Linux ]]; then |
| 62 | + CPUCORES=$(lscpu | grep "Core(s) per socket" | awk '{print $4}') |
| 63 | +elif [[ $(uname) == Darwin ]]; then |
| 64 | + CPUCORES=$(sysctl -n hw.physicalcpu) |
| 65 | +fi |
| 66 | + |
| 67 | +# Use the first element of $GOPATH in the case where GOPATH is a list |
| 68 | +# (something that is totally allowed). |
| 69 | +PKG="github.com/utreexo/utreexod" |
| 70 | +COMMIT=$(git describe --tags --abbrev=40 --dirty) |
| 71 | + |
| 72 | +for i in $SYS; do |
| 73 | + OS=$(echo $i | cut -f1 -d-) |
| 74 | + ARCH=$(echo $i | cut -f2 -d-) |
| 75 | + ARM= |
| 76 | + CC= |
| 77 | + |
| 78 | + if [[ $ARCH = "armv6" ]]; then |
| 79 | + ARCH=arm |
| 80 | + ARM=6 |
| 81 | + elif [[ $ARCH = "armv7" ]]; then |
| 82 | + ARCH=arm |
| 83 | + ARM=7 |
| 84 | + fi |
| 85 | + |
| 86 | + mkdir $PACKAGE-$i-$TAG |
| 87 | + echo "cd to" $PACKAGE-$i-$TAG |
| 88 | + cd $PACKAGE-$i-$TAG |
| 89 | + |
| 90 | + # Build bdk wallet(rust) dependency. |
| 91 | + if [[ $ARCH = "arm64" ]] && [[ $OS = "linux" ]]; then |
| 92 | + TARGET="aarch64-unknown-linux-musl" |
| 93 | + CC=aarch64-linux-musl-gcc |
| 94 | + |
| 95 | + elif [[ $ARCH = "amd64" ]] && [[ $OS = "linux" ]]; then |
| 96 | + TARGET="x86_64-unknown-linux-musl" |
| 97 | + CC=x86_64-linux-musl-gcc |
| 98 | + |
| 99 | + elif [[ $ARCH = "arm" ]] && [[ $OS = "linux" ]] && [[ $ARM=7 ]]; then |
| 100 | + TARGET="armv7-unknown-linux-musleabihf" |
| 101 | + CC=armv7l-linux-musleabihf-gcc |
| 102 | + |
| 103 | + elif [[ $ARCH = "arm" ]] && [[ $OS = "linux" ]] && [[ $ARM=6 ]]; then |
| 104 | + TARGET="armv6-unknown-linux-musleabihf" |
| 105 | + CC=armv6-linux-musleabihf-gcc |
| 106 | + |
| 107 | + elif [[ $ARCH = "arm64" ]] && [[ $OS = "darwin" ]]; then |
| 108 | + TARGET="aarch64-apple-darwin" |
| 109 | + |
| 110 | + elif [[ $ARCH = "amd64" ]] && [[ $OS = "darwin" ]]; then |
| 111 | + TARGET="x86_64-apple-darwin" |
| 112 | + |
| 113 | + elif [[ $ARCH = "amd64" ]] && [[ $OS = "windows" ]]; then |
| 114 | + TARGET="x86_64-pc-windows-gnu" |
| 115 | + CC=x86_64-w64-mingw32-gcc |
| 116 | + fi |
| 117 | + |
| 118 | + env CARGO_TARGET_DIR=. cargo build --release --target=$TARGET --jobs=$CPUCORES |
| 119 | + mv $TARGET target |
| 120 | + |
| 121 | + echo "Building:" $OS $ARCH $ARM |
| 122 | + |
| 123 | + # Build utreexod |
| 124 | + if [[ $OS == "linux" ]]; then |
| 125 | + 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 |
| 126 | + elif [[ $OS == "darwin" ]]; then |
| 127 | + env CGO_ENABLED=1 GOOS=$OS GOARCH=$ARCH GOARM=$ARM go build -v -tags="bdkwallet" -ldflags="-s -w -buildid=" github.com/utreexo/utreexod |
| 128 | + fi |
| 129 | + |
| 130 | + # Remove bdk build things. |
| 131 | + rm -rf target |
| 132 | + rm -rf release |
| 133 | + |
| 134 | + # Build utreexoctl |
| 135 | + env CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH GOARM=$ARM go build -v -trimpath -ldflags="-s -w -buildid=" github.com/utreexo/utreexod/cmd/utreexoctl |
| 136 | + |
| 137 | + cd .. |
| 138 | + |
| 139 | + if [[ $OS = "windows" ]]; then |
| 140 | + zip -r $PACKAGE-$i-$TAG.zip $PACKAGE-$i-$TAG |
| 141 | + else |
| 142 | + tar -cvzf $PACKAGE-$i-$TAG.tar.gz $PACKAGE-$i-$TAG |
| 143 | + fi |
| 144 | + |
| 145 | + rm -r $PACKAGE-$i-$TAG |
| 146 | +done |
| 147 | + |
| 148 | +shasum -a 256 * > manifest-$TAG.txt |
0 commit comments