Skip to content

Commit

Permalink
Build macOS releases via osxcross
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed Sep 25, 2020
1 parent 9b4c7fc commit f600a67
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 20 deletions.
10 changes: 10 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[target.x86_64-apple-darwin]
linker = "x86_64-apple-darwin15-cc"
ar = "x86_64-apple-darwin15-ar"
# fails with "Undefined symbols for architecture x86_64" errors when these are not set
rustflags = [ "-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup" ]

[target.x86_64-pc-windows-gnu]
# use --no-insert-timestamp to drop PE timestamps in Windows builds for reproducibility
# https://wiki.debian.org/ReproducibleBuilds/TimestampsInPEBinaries#building_with_mingw-w64
rustflags = [ "-C", "link-arg=-Wl,--no-insert-timestamp" ]
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ script:
- >
docker build -t bwt-builder -f scripts/builder.Dockerfile . &&
docker run -v `pwd`:/usr/src/bwt bwt-builder &&
docker build -t bwt-builder-osx -f scripts/builder-osx.Dockerfile . &&
docker run -v `pwd`:/usr/src/bwt bwt-builder-osx &&
echo '-----BEGIN SHA256SUM-----' &&
(cd dist && sha256sum *) | sort &&
echo ''
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Unreleased

- Reproducible builds using Docker
- Reproducible builds using Docker (#51)

- Pre-built binary releases for macOS (#24)

- Scriptable transaction broadcast command via `--tx-broadcast-cmd <cmd>` (#7)

Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1213,12 +1213,19 @@ The builds can be reproduced in a Docker container environment as follows:

```
$ git clone https://github.com/shesek/bwt && cd bwt
# Linux & Windows
$ docker build -t bwt-builder -f scripts/builder.Dockerfile .
$ docker run -it --rm -v `pwd`:/usr/src/bwt bwt-builder
# Mac OSX (cross-compiled via osxcross)
$ docker build -t bwt-builder-osx -f scripts/builder-osx.Dockerfile .
$ docker run -it --rm -v `pwd`:/usr/src/bwt bwt-builder-osx
$ sha256sum dist/*
```

The builds are [reproduced on Travis CI](https://travis-ci.org/github/shesek/bwt). The SHA256 checksums are available at the end of the build log.
The builds are [reproduced on Travis CI](https://travis-ci.org/github/shesek/bwt/branches). The SHA256 checksums are available at the end of the build log.

You can get the checksums for the latest stable release via the API as follows:

Expand Down
40 changes: 23 additions & 17 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#!/bin/bash
set -xeo pipefail

# `osx` is also available, but requires osxcross installed (see builder-os.Dockerfile)
TARGETS=${TARGETS:-linux,win}

build() {
name=$1; platform=$2; features=$3
ext=$([[ $platform != *"-windows-"* ]] || echo .exe)
name=$1; target=$2; features=$3
ext=$([[ $target != *"-windows-"* ]] || echo .exe)
dest=dist/$name
mkdir -p $dest

echo Building $name for $platform with features $features
echo Building $name for $target with features $features

cargo build --release --target $target --no-default-features --features "$features"

# drop PE timestamps in windows builds for reproducibility (https://wiki.debian.org/ReproducibleBuilds/TimestampsInPEBinaries#building_with_mingw-w64)
RUSTFLAGS="$RUSTFLAGS $([[ $platform != *"-windows-"* ]] || echo '-Clink-arg=-Wl,--no-insert-timestamp')" \
cargo build --release --target $platform --no-default-features --features "$features"
mv target/$target/release/bwt$ext $dest

mv target/$platform/release/bwt$ext $dest
strip $dest/bwt$ext
[[ $target == *"-apple-"* ]] || strip $dest/bwt$ext

cp README.md LICENSE $dest/

Expand All @@ -38,21 +40,25 @@ version=`cat Cargo.toml | egrep '^version =' | cut -d'"' -f2`

rm -rf dist/*

for target in linux,x86_64-unknown-linux-gnu \
win,x86_64-pc-windows-gnu; do
IFS=',' read pnick platform <<< $target
for cfg in linux,x86_64-unknown-linux-gnu \
win,x86_64-pc-windows-gnu \
osx,x86_64-apple-darwin; do
IFS=',' read platform target <<< $cfg
if [[ $TARGETS != *"$platform"* ]]; then continue; fi

build bwt-$version-x86_64-$pnick $platform http,electrum,webhooks,track-spends
build bwt-$version-electrum_only-x86_64-$pnick $platform electrum
build bwt-$version-x86_64-$platform $target http,electrum,webhooks,track-spends
build bwt-$version-electrum_only-x86_64-$platform $target electrum
done

echo Building electrum plugin
for pnick in linux win; do
name=bwt-$version-electrum_plugin-x86_64-$pnick
for platform in linux win; do
if [[ $TARGETS != *"$platform"* ]]; then continue; fi

name=bwt-$version-electrum_plugin-x86_64-$platform
dest=dist/$name
mkdir $dest
cp contrib/electrum-plugin/*.py $dest
cp dist/bwt-$version-electrum_only-x86_64-$pnick/* $dest
cp dist/bwt-$version-electrum_only-x86_64-$platform/* $dest
# needs to be inside a directory with a name that matches the plugin module name for electrum to load it,
# create a temporary link to get tar/zip to pack it properly. (can also be done for tar.gz with --transform)
ln -s $name dist/bwt
Expand All @@ -63,4 +69,4 @@ done
# remove subdirectories, keep release tarballs
rm -r dist/*/

[ -n "$OWNER" ] && chown -R $OWNER dist || true
[ -n "$OWNER" ] && chown -R $OWNER dist target || true
18 changes: 18 additions & 0 deletions scripts/builder-osx.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM bwt-builder

ARG CROSSOSX_COMMIT=364703ca0962c4a12688daf8758802a5df9e3221
ARG OSX_SDK_VERSION=10.11
ARG OSX_SDK_SHASUM=694a66095a3514328e970b14978dc78c0f4d170e590fa7b2c3d3674b75f0b713

RUN apt-get install -y git wget clang cmake libxml2-dev zlib1g-dev && \
rustup target add x86_64-apple-darwin

RUN git clone https://github.com/tpoechtrager/osxcross /usr/src/osxcross && \
cd /usr/src/osxcross && \
git checkout $CROSSOSX_COMMIT && \
wget -q https://s3.dockerproject.org/darwin/v2/MacOSX$OSX_SDK_VERSION.sdk.tar.xz --directory-prefix=tarballs && \
echo "$OSX_SDK_SHASUM tarballs/MacOSX$OSX_SDK_VERSION.sdk.tar.xz" | sha256sum -c - && \
UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh

ENV TARGETS=osx
ENV PATH=$PATH:/usr/src/osxcross/target/bin
1 change: 1 addition & 0 deletions scripts/builder.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ RUN mkdir src .cargo && touch src/lib.rs src/main.rs && \
cargo vendor > .cargo/config

VOLUME /usr/src/bwt
ENV TARGETS=linux,win
ENTRYPOINT [ "/usr/src/bwt/scripts/build.sh" ]
9 changes: 8 additions & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ cargo fmt -- --check
if [ -z "$SKIP_BUILD" ]; then
echo Building releases...

if [ -z "$NO_DOCKER_BUILD" ]; then
if [ -z "$BUILD_HOST" ]; then
docker build -t bwt-builder -f scripts/builder.Dockerfile .
docker run -it --rm -e OWNER=`id -u` -v `pwd`:/usr/src/bwt bwt-builder
if [ -z "$SKIP_OSX" ]; then
docker build -t bwt-builder-osx -f scripts/builder-osx.Dockerfile .
docker run -it --rm -e OWNER=`id -u` -v `pwd`:/usr/src/bwt bwt-builder-osx
fi
else
# macOS builds are disabled by default when building on the host.
# to enable, set TARGETS=linux,win,osx
./scripts/build.sh
fi


echo Making SHA256SUMS...
(cd dist && sha256sum *) | sort | gpg --clearsign --digest-algo sha256 > SHA256SUMS.asc
fi
Expand Down

0 comments on commit f600a67

Please sign in to comment.