summaryrefslogtreecommitdiffhomepage
path: root/build.sh
blob: 5f967f035adefbb0bf93dbffc3d61eb5c18c29c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash

# This script is used to build, and sign a release artifact. See `README.md` for instructions on
# how to just build a development/testing version.

set -eu

REQUIRED_RUSTC_VERSION="rustc 1.26.0 (a77568041 2018-05-07)"
RUSTC_VERSION=`rustc +stable --version`
if [[ $RUSTC_VERSION != $REQUIRED_RUSTC_VERSION ]]; then
    echo "You are running the wrong Rust compiler version."
    echo "You are running $RUSTC_VERSION, but this project requires $REQUIRED_RUSTC_VERSION"
    echo "for release builds."
    exit 1
fi

if [[ "${1:-""}" != "--allow-dirty" ]]; then
    if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
        echo "Dirty working directory!"
        echo "You should only build releases in clean working directories in order to make it"
        echo "easier to reproduce the same build."
        echo ""
        echo "Use --allow-dirty to skip this check. Never do this for official releases."
        exit 1
    fi
fi

if [[ "$(uname -s)" = "Darwin" ]]; then
    export MACOSX_DEPLOYMENT_TARGET="10.7"

    # if CSC_LINK is set, then we do signing
    if [[ ! -z ${CSC_LINK-} ]]; then
        echo "Building with macOS signing activated. Using certificate at $CSC_LINK"
        if [[ -z ${CSC_KEY_PASSWORD-} ]]; then
            read -sp "CSC_KEY_PASSWORD = " CSC_KEY_PASSWORD
            echo ""
            export CSC_KEY_PASSWORD
        fi
        export CSC_IDENTITY_AUTO_DISCOVERY=true
    else
        echo "!! CSC_LINK not set. This build will not be signed !!"
        unset CSC_LINK CSC_KEY_PASSWORD
        export CSC_IDENTITY_AUTO_DISCOVERY=false
    fi
fi


# Remove binaries. To make sure it is rebuilt with the stable toolchain and the latest changes.
cargo +stable clean

echo "Compiling mullvad-daemon in release mode with $RUSTC_VERSION..."
cargo +stable build --release


binaries=(
    ./target/release/mullvad-daemon
    ./target/release/mullvad
    ./target/release/problem-report
)
for binary in ${binaries[*]}; do
    echo "Stripping debugging symbols from $binary"
    strip $binary
done

echo "Updating relay list..."
./target/release/list-relays > dist-assets/relays.json

echo "Installing JavaScript dependencies..."
yarn install

echo "Packing final release artifact..."
case "$(uname -s)" in
    Linux*)     yarn pack:linux;;
    Darwin*)    yarn pack:mac;;
esac

RELEASE_VERSION=`./target/release/mullvad-daemon --version | cut -f2 -d' '`
echo "**********************************"
echo ""
echo " The build finished successfully! "
echo " You have built:"
echo ""
echo " $RELEASE_VERSION"
echo ""
echo "**********************************"