geckodriver: Merge pull request #213 from mozilla/win32_docker
authorJames Graham <james@hoppipolla.co.uk>
Tue, 06 Sep 2016 11:07:10 +0100
changeset 407675 e5c831bcf2e23d54e581b14217f398df26093a03
parent 407674 169f4391d9d02e641c8294f32592d3044b6ed2d6
child 407676 18eacdaabacee9eff1226f8dc3c9678aa47b80e0
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
geckodriver: Merge pull request #213 from mozilla/win32_docker Cross-compile on win32 using Docker image from port-of-rust Source-Repo: https://github.com/mozilla/geckodriver Source-Revision: 39b2b269df496d17c8041bd579a4a409ee2e3050
testing/geckodriver/.travis.yml
testing/geckodriver/build.sh
testing/geckodriver/ci.sh
--- a/testing/geckodriver/.travis.yml
+++ b/testing/geckodriver/.travis.yml
@@ -1,9 +1,14 @@
 language: generic
+cache:
+  directories:
+    - $HOME/.cargo
+    - $TRAVIS_BUILD_DIR/target
+    - $HOME/docker/
 
 matrix:
   include:
     - os: linux
       env:
         - TARGET=armv7-unknown-linux-gnueabihf
         - NAME=arm7hf
         - EXT=tar.gz
@@ -33,28 +38,31 @@ matrix:
       dist: trusty
       addons:
         apt:
           packages:
           - gcc-mingw-w64
           - gcc-mingw-w64-x86-64
           - binutils-mingw-w64-x86-64
           - libbz2-dev
+    - os: linux
+      env:
+        - TARGET=i686-pc-windows-gnu
+        - NAME=win32
+        - EXT=zip
+        - USE_DOCKER=1
+      dist: trusty
+      services:
+        - docker
     - os: osx
       env:
         - TARGET=x86_64-apple-darwin
         - NAME=macos
         - EXT=tar.gz
 
-install:
-  - export PATH="$PATH:$HOME/.cargo/bin"
-  - curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=beta
-  - rustc -V
-  - cargo -V
-
 script:
   - bash ci.sh
 
 deploy:
   provider: releases
   api_key:
     secure:
       OY6y0xRhlGSBH+3+7+7K6s4pp0Tf3BA61NAubEK4gpO23AKfyJUK+vqqCbdo06Z0E4QO4O1ke6fot7Gq9EdxJmsl/Kk5LDd9Rv3BXSYdjPupzs7coYuD8wv10NfAX6ETd9ITyPim2Zq6bq8nx1S2ESTpos/js1HCtVW3nrlCV58=
copy from testing/geckodriver/ci.sh
copy to testing/geckodriver/build.sh
--- a/testing/geckodriver/ci.sh
+++ b/testing/geckodriver/build.sh
@@ -1,19 +1,34 @@
 set -ex
 
+print_versions() {
+    rustc -V
+    cargo -V
+}
+
+rustup_install() {
+    export PATH="$PATH:$HOME/.cargo/bin"
+    curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=beta
+}
+
 # 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
+}
+
 # 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
@@ -31,17 +46,17 @@ cargo_config() {
         prefix=x86_64-w64-mingw32
         ;;
     *)
         return
         ;;
     esac
 
     mkdir -p ~/.cargo
-    cat >>~/.cargo/config <<EOF
+    cat >~/.cargo/config <<EOF
 [target.$TARGET]
 linker = "$prefix-gcc"
 EOF
 }
 
 # 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() {
@@ -87,26 +102,40 @@ get_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
-        zip geckodriver-$1-$3.zip geckodriver.exe
-        file geckodriver-$1-$3.zip
+        filename="geckodriver-$1-$3.zip"
+        zip "$filename" geckodriver.exe
+        file "$filename"
     else
-        tar zcvf geckodriver-$1-$3.tar.gz geckodriver
-        file geckodriver-$1-$3.tar.gz
+        filename="geckodriver-$1-$3.tar.gz"
+        tar zcvf "$filename" geckodriver
+        file "$filename"
+    fi
+    if [ ! -z "$USE_DOCKER" ]
+    then
+        chown "$USER_ID:$GROUP_ID" "$filename"
     fi
 }
 
 main() {
-    rustup_target_add $TARGET
+    if [ ! -z "$USE_DOCKER" ]
+    then
+        setup_docker
+        print_versions
+    else
+        rustup_install
+        print_versions
+        rustup_target_add $TARGET
+    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" ]
--- a/testing/geckodriver/ci.sh
+++ b/testing/geckodriver/ci.sh
@@ -1,119 +1,21 @@
 set -ex
 
-# 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
-}
-
-# 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
-        ;;
-    *)
-        return
-        ;;
-    esac
-
-    mkdir -p ~/.cargo
-    cat >>~/.cargo/config <<EOF
-[target.$TARGET]
-linker = "$prefix-gcc"
-EOF
-}
-
-# 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
-        zip geckodriver-$1-$3.zip geckodriver.exe
-        file geckodriver-$1-$3.zip
-    else
-        tar zcvf geckodriver-$1-$3.tar.gz geckodriver
-        file geckodriver-$1-$3.tar.gz
-    fi
-}
-
-main() {
-    rustup_target_add $TARGET
-
-    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
+if [ ! -z "$USE_DOCKER" ]
+then
+    ls .
+    tag="port-of-rust/$TARGET/latest"
+    docker build https://github.com/alexcrichton/port-of-rust.git -f "$TARGET/Dockerfile" -t $tag
+    docker run\
+           -e USER="$USER"\
+           -e TARGET="$TARGET"\
+           -e USE_DOCKER=1\
+           -e NAME="$NAME"\
+           -e TRAVIS_TAG="$TRAVIS_TAG"\
+           -e USER_ID=$(id -u)\
+           -e GROUP_ID=$(id -g)\
+           -v $PWD:/mnt/host\
+           -i $tag\
+           bash -s -- < build.sh
+else
+    bash build.sh
+fi