Skip to content

Commit 28b4727

Browse files
committed
Add build/CI scripts
1 parent 6623a92 commit 28b4727

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

.travis.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
language: rust
2+
rust: [ stable ]
3+
cache: { cargo: true }
4+
env: [ CARGO_TERM_COLOR=always ]
5+
6+
jobs:
7+
include:
8+
- stage: Check
9+
name: cargo fmt
10+
env: CACHE_BUCKET=fmt
11+
install: rustup component add rustfmt
12+
script: cargo fmt -- --check
13+
- name: cargo check
14+
env: CACHE_BUCKET=check
15+
script: cargo check
16+
- name: clippy
17+
env: CACHE_BUCKET=clippy
18+
install: rustup component add clippy
19+
script: cargo clippy --all-targets -- -A clippy::redundant_field_names
20+
21+
- &build
22+
stage: Reproducible builds
23+
cache: false
24+
25+
before_script: |
26+
git submodule update --init
27+
docker build -t bwt-builder - < bwt/scripts/builder.Dockerfile
28+
[ "$IMAGE" == "builder" ] || docker build -t bwt-$IMAGE - < bwt/scripts/$IMAGE.Dockerfile
29+
30+
script:
31+
- >
32+
echo -e tr''avis_fo''ld:start:build\\nBuilding... &&
33+
docker run -u `id -u` -v `pwd`:/usr/src/libbwt -w /usr/src/libbwt \
34+
--entrypoint scripts/build.sh bwt-$IMAGE &&
35+
echo tr''avis_fol''d:end:build
36+
- >
37+
echo '-----BEGIN SHA256SUM-----' &&
38+
(cd dist && sha256sum *.tar.gz) &&
39+
echo
40+
# XXX if: branch in (master, dev, stable) OR tag IS present
41+
42+
43+
name: Linux/Windows/ARMv7/ARMv8
44+
env: IMAGE=builder
45+
46+
- <<: *build
47+
name: Mac OSX
48+
env: IMAGE=builder-osx

scripts/build.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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

Comments
 (0)