|
| 1 | +#!/bin/bash |
| 2 | +set -xeo pipefail |
| 3 | + |
| 4 | +# `x86_64-osx` is also available, requires osxcross to be installed (see bwt/builder-osx.Dockerfile) |
| 5 | +TARGETS=${TARGETS:-x86_64-linux,x86_64-win,arm32v7-linux,arm64v8-linux} |
| 6 | + |
| 7 | +# for stderr logging and automatic detection of bitcoind's data dir location |
| 8 | +FEATURES=${FEATURES:-pretty_env_logger,dirs} |
| 9 | + |
| 10 | +[ -f bwt/Cargo.toml ] || (echo >&2 "Missing bwt submodule, run 'git submodule update --init'" && exit 1) |
| 11 | + |
| 12 | +version=$(grep -E '^version =' Cargo.toml | cut -d'"' -f2) |
| 13 | + |
| 14 | +if [[ -n "$SCCACHE_DIR" && -d "$SCCACHE_DIR" ]]; then |
| 15 | + export RUSTC_WRAPPER=$(which sccache) |
| 16 | +fi |
| 17 | + |
| 18 | +# Build library for a single platform/variant with the specified feature set |
| 19 | +build_platform_variant() { |
| 20 | + local platform_nick=$1 |
| 21 | + local platform_rust=$2 |
| 22 | + local features=$3 |
| 23 | + local variant=$4 |
| 24 | + local name=libbwt-$version$variant-$platform_nick |
| 25 | + local filename=$(lib_filename $platform_rust) |
| 26 | + |
| 27 | + cargo build --release --target $platform_rust --no-default-features --features $FEATURES,$features |
| 28 | + |
| 29 | + mkdir -p dist/$name |
| 30 | + mv target/$platform_rust/release/$filename dist/$name/ |
| 31 | + strip_symbols $platform_rust dist/$name/$filename || true |
| 32 | + cp LICENSE README.md libbwt.h dist/$name/ |
| 33 | + pack $name |
| 34 | +} |
| 35 | + |
| 36 | +# Build variants (full/electrum_only) for the specified platform |
| 37 | +build_platform() { |
| 38 | + if [[ $TARGETS != *"$1"* ]]; then return; fi |
| 39 | + |
| 40 | + [ -n "$ELECTRUM_ONLY_ONLY" ] || build_platform_variant $1 $2 http,electrum '' |
| 41 | + build_platform_variant $1 $2 electrum '-electrum_only' |
| 42 | +} |
| 43 | + |
| 44 | +lib_filename() { |
| 45 | + # Windows dll files ar built as `bwt.dll`, without the `lib` prefix |
| 46 | + local pre=$([[ $1 == *"-windows-"* ]] || echo lib) |
| 47 | + local ext=$([[ $1 == *"-windows-"* ]] && echo .dll || ([[ $1 == *"-apple-"* ]] && echo .dylib || echo .so)) |
| 48 | + echo -n ${pre}bwt${ext} |
| 49 | +} |
| 50 | + |
| 51 | +strip_symbols() { |
| 52 | + case $1 in |
| 53 | + "x86_64-unknown-linux-gnu") x86_64-linux-gnu-strip $2 ;; |
| 54 | + "x86_64-pc-windows-gnu") x86_64-w64-mingw32-strip $2 ;; |
| 55 | + "x86_64-apple-darwin") x86_64-apple-darwin15-strip $2 ;; |
| 56 | + "armv7-unknown-linux-gnueabihf") arm-linux-gnueabihf-strip $2 ;; |
| 57 | + "aarch64-unknown-linux-gnu") aarch64-linux-gnu-strip $2 ;; |
| 58 | + *) echo >&2 Platform not found: $1; strip $2 ;; |
| 59 | + esac |
| 60 | +} |
| 61 | + |
| 62 | +# pack tar.gz with static/removed metadata attrs and deterministic file order for reproducibility |
| 63 | +pack() { |
| 64 | + local name=$1 |
| 65 | + touch -t 1711081658 dist/$name dist/$name/* |
| 66 | + pushd dist |
| 67 | + TZ=UTC tar --mtime='2017-11-08 16:58:00' --owner=0 --sort=name -I 'gzip --no-name' -chf $name.tar.gz $name |
| 68 | + popd |
| 69 | +} |
| 70 | + |
| 71 | +build_platform x86_64-linux x86_64-unknown-linux-gnu |
| 72 | +build_platform x86_64-osx x86_64-apple-darwin |
| 73 | +build_platform x86_64-windows x86_64-pc-windows-gnu |
| 74 | +build_platform arm32v7-linux armv7-unknown-linux-gnueabihf |
| 75 | +build_platform arm64v8-linux aarch64-unknown-linux-gnu |
0 commit comments