Welcome to mirror list, hosted at ThFree Co, Russian Federation.

build.sh - github.com/mozilla/geckodriver.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8bf54e98239dfca75266d87a3eaa56893de3a9db (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
set -ex

print_versions() {
    rustc -V
    cargo -V
    cc --version
}

rustup_install() {
    export PATH="$PATH:$HOME/.cargo/bin"
    curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$1
}

# Add provided target to current Rust toolchain if it is not already
# the default or installed.
rustup_target_add() {
    if ! rustup target list | grep -E "$1 \((default|installed)\)"
    then
        rustup target add $1
    fi
}

setup_docker() {
    apt-get -qq -y install zip
    cd /mnt/host
}

mingw_i686_install() {
    curl https://static.rust-lang.org/dist/rust-mingw-nightly-i686-pc-windows-gnu.tar.gz \
        | tar xzvf - -C /tmp
    /tmp/rust-mingw-nightly-i686-pc-windows-gnu/install.sh --prefix=`rustc --print sysroot`
}

# Configure rustc target for cross compilation.  Provided with a build
# target, this will determine which linker to use for cross compilation.
cargo_config() {
    local prefix

    case "$TARGET" in
    aarch64-unknown-linux-gnu)
        prefix=aarch64-linux-gnu
        ;;
    arm*-unknown-linux-gnueabihf)
        prefix=arm-linux-gnueabihf
        ;;
    arm-unknown-linux-gnueabi)
        prefix=arm-linux-gnueabi
        ;;
    mipsel-unknown-linux-musl)
        prefix=mipsel-openwrt-linux
        ;;
    x86_64-pc-windows-gnu)
        prefix=x86_64-w64-mingw32
        ;;
    i686-pc-windows-gnu)
        prefix=i686-w64-mingw32
        ;;
    *)
        return
        ;;
    esac

    mkdir -p ~/.cargo
    cat >~/.cargo/config <<EOF
[target.$TARGET]
linker = "$prefix-gcc"
EOF

    cat ~/.cargo/config
}

# Build current crate for given target and print file type information.
# If the second argument is set, a release build will be made.
cargo_build() {
    local mode
    if [ -z "$2" ]
    then
        mode=debug
    else
        mode=release
    fi

    local modeflag
    if [ "$mode" == "release" ]
    then
        modeflag=--release
    fi

    cargo build --target $1 $modeflag

    file $(get_binary $1 $mode)
}

# Run current crate's tests if the current system supports it.
cargo_test() {
    if echo "$1" | grep -E "(i686|x86_64)-unknown-linux-(gnu|musl)|darwin"
    then
        cargo test --target $1
    fi
}

# Returns relative path to binary
# based on build target and type ("release"/"debug").
get_binary() {
    local ext
    if [[ "$1" =~ "windows" ]]
    then
        ext=".exe"
    fi
    echo "target/$1/$2/geckodriver$ext"
}

# Create a compressed archive of the binary
# for the given given git tag, build target, and build type.
package_binary() {
    local bin
    bin=$(get_binary $2 $4)
    cp $bin .

    if [[ "$2" =~ "windows" ]]
    then
        filename="geckodriver-$1-$3.zip"
        zip "$filename" geckodriver.exe
        file "$filename"
    else
        filename="geckodriver-$1-$3.tar.gz"
        tar zcvf "$filename" geckodriver
        file "$filename"
    fi
    if [ ! -z "$DOCKER_IMAGE" ]
    then
        chown "$USER_ID:$GROUP_ID" "$filename"
    fi
}

main() {
    TOOLCHAIN=${TOOLCHAIN:=stable}

    if [ ! -z "$DOCKER_IMAGE" ]
    then
        setup_docker
    fi

    rustup_install $TOOLCHAIN
    print_versions
    rustup_target_add $TARGET

    # custom mingw component required
    # when compiling on 32-bit windows
    # see https://github.com/mozilla/geckodriver/pull/138#issuecomment-232139097
    if [[ $TARGET == "i686-pc-windows-gnu" ]]
    then
        mingw_i686_install
    fi

    cargo_config $TARGET
    cargo_build $TARGET
    cargo_test $TARGET

    # when something is tagged,
    # also create a release build and package it
    if [ ! -z "$TRAVIS_TAG" ]
    then
        cargo_build $TARGET 1
        package_binary $TRAVIS_TAG $TARGET $NAME "release"
    fi
}

main