environment:
  SCCACHE_BUCKET: rust-lang-ci-sccache
  AWS_ACCESS_KEY_ID: AKIAIMX7VLAS3PZAVLUQ
  AWS_SECRET_ACCESS_KEY:
    secure: 1UkmbiDd15tWtYbMm5O2Uqm0b0Ur8v1MoSlydxl4ojcroPeerRMlUges0l57py8c
  SCCACHE_DIGEST: f808afabb4a4eb1d7112bcb3fa6be03b61e93412890c88e177c667eb37f46353d7ec294e559b16f9f4b5e894f2185fe7670a0df15fd064889ecbd80f0c34166c
  matrix:
  # 32/64 bit MSVC tests
  - MSYS_BITS: 64
    RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc
    SCRIPT: python x.py test
  - MSYS_BITS: 32
    RUST_CONFIGURE_ARGS: --build=i686-pc-windows-msvc --target=i586-pc-windows-msvc
    SCRIPT: python x.py test --host i686-pc-windows-msvc --target i686-pc-windows-msvc

  # MSVC aux tests
  - MSYS_BITS: 64
    RUST_CHECK_TARGET: check-aux
    RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc

  # 32/64-bit MinGW builds.
  #
  # The MinGW builds unfortunately have to both download a custom toolchain and
  # avoid the one installed by AppVeyor by default. Interestingly, though, for
  # different reasons!
  #
  # For 32-bit the installed gcc toolchain on AppVeyor uses the pthread
  # threading model. This is unfortunately not what we want, and if we compile
  # with it then there's lots of link errors in the standard library (undefined
  # references to pthread symbols).
  #
  # For 64-bit the installed gcc toolchain is currently 5.3.0 which
  # unfortunately segfaults on Windows with --enable-llvm-assertions (segfaults
  # in LLVM). See rust-lang/rust#28445 for more information, but to work around
  # this we go back in time to 4.9.2 specifically.
  #
  # Finally, note that the downloads below are all in the `rust-lang-ci` S3
  # bucket, but they cleraly didn't originate there! The downloads originally
  # came from the mingw-w64 SourceForge download site. Unfortunately
  # SourceForge is notoriously flaky, so we mirror it on our own infrastructure.
  #
  # And as a final point of note, the 32-bit MinGW build using the makefiles do
  # *not* use debug assertions and llvm assertions. This is because they take
  # too long on appveyor and this is tested by rustbuild below.
  - MSYS_BITS: 32
    RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu --enable-ninja
    SCRIPT: python x.py test
    MINGW_URL: https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror
    MINGW_ARCHIVE: i686-6.2.0-release-win32-dwarf-rt_v5-rev1.7z
    MINGW_DIR: mingw32
  - MSYS_BITS: 64
    SCRIPT: python x.py test
    RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-ninja
    MINGW_URL: https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror
    MINGW_ARCHIVE: x86_64-6.2.0-release-win32-seh-rt_v5-rev1.7z
    MINGW_DIR: mingw64

  # 32/64 bit MSVC and GNU deployment
  - RUST_CONFIGURE_ARGS: >
      --build=x86_64-pc-windows-msvc
      --enable-extended
    SCRIPT: python x.py dist
    DEPLOY: 1
  - RUST_CONFIGURE_ARGS: >
      --build=i686-pc-windows-msvc
      --target=i586-pc-windows-msvc
      --enable-extended
    SCRIPT: python x.py dist
    DEPLOY: 1
  - MSYS_BITS: 32
    RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu --enable-extended --enable-ninja
    SCRIPT: python x.py dist
    MINGW_URL: https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror
    MINGW_ARCHIVE: i686-6.2.0-release-win32-dwarf-rt_v5-rev1.7z
    MINGW_DIR: mingw32
    DEPLOY: 1
  - MSYS_BITS: 64
    SCRIPT: python x.py dist
    RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-extended --enable-ninja
    MINGW_URL: https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror
    MINGW_ARCHIVE: x86_64-6.2.0-release-win32-seh-rt_v5-rev1.7z
    MINGW_DIR: mingw64
    DEPLOY: 1

  # "alternate" deployment, see .travis.yml for more info
  - MSYS_BITS: 64
    RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended
    SCRIPT: python x.py dist
    DEPLOY_ALT: 1

matrix:
  fast_finish: true

clone_depth: 1
build: false

install:
  # If we need to download a custom MinGW, do so here and set the path
  # appropriately.
  #
  # Note that this *also* means that we're not using what is typically
  # /mingw32/bin/python2.7.exe, which is a "correct" python interpreter where
  # /usr/bin/python2.7.exe is not. To ensure we use the right interpreter we
  # move `C:\Python27` ahead in PATH and then also make sure the `python2.7.exe`
  # file exists in there (which it doesn't by default).
  - if defined MINGW_URL appveyor-retry appveyor DownloadFile %MINGW_URL%/%MINGW_ARCHIVE%
  - if defined MINGW_URL 7z x -y %MINGW_ARCHIVE% > nul
  - if defined MINGW_URL set PATH=%CD%\%MINGW_DIR%\bin;C:\msys64\usr\bin;%PATH%

  # Otherwise pull in the MinGW installed on appveyor
  - if NOT defined MINGW_URL set PATH=C:\msys64\mingw%MSYS_BITS%\bin;C:\msys64\usr\bin;%PATH%

  # Prefer the "native" Python as LLVM has trouble building with MSYS sometimes
  - copy C:\Python27\python.exe C:\Python27\python2.7.exe
  - set PATH=C:\Python27;%PATH%

  # Download and install sccache
  - appveyor-retry appveyor DownloadFile https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-04-04-sccache-x86_64-pc-windows-msvc
  - mv 2017-04-04-sccache-x86_64-pc-windows-msvc sccache.exe
  - set PATH=%PATH%;%CD%

  # Download and install ninja
  #
  # Note that this is originally from the github releases patch of Ninja
  - appveyor-retry appveyor DownloadFile https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-03-15-ninja-win.zip
  - 7z x 2017-03-15-ninja-win.zip
  # - set PATH=%PATH%;%CD% -- this already happens above for sccache

  # Install InnoSetup to get `iscc` used to produce installers
  - appveyor-retry choco install -y InnoSetup
  - set PATH="C:\Program Files (x86)\Inno Setup 5";%PATH%

  # Help debug some handle issues on AppVeyor
  - ps: Invoke-WebRequest -Uri https://download.sysinternals.com/files/Handle.zip -OutFile handle.zip
  - mkdir handle
  - ps: Expand-Archive handle.zip -dest handle
  - set PATH=%PATH%;%CD%\handle
  - handle.exe -accepteula -help

  # Attempt to debug sccache failures
  - set SCCACHE_ERROR_LOG=%CD%/sccache.log

test_script:
  - if not exist C:\cache\rustsrc\NUL mkdir C:\cache\rustsrc
  - sh src/ci/init_repo.sh . /c/cache/rustsrc
  - set SRC=.
  - set NO_CCACHE=1
  - sh src/ci/run.sh

on_failure:
  - cat %CD%\sccache.log
  - cat C:\Users\appveyor\AppData\Local\Temp\1\build-cache-logs\*.log

cache:
  - C:\cache\rustsrc
  - "build/i686-pc-windows-msvc/llvm -> src/rustllvm/llvm-rebuild-trigger"
  - "build/x86_64-pc-windows-msvc/llvm -> src/rustllvm/llvm-rebuild-trigger"
  - "i686-pc-windows-msvc/llvm -> src/rustllvm/llvm-rebuild-trigger"
  - "x86_64-pc-windows-msvc/llvm -> src/rustllvm/llvm-rebuild-trigger"

branches:
  only:
    - auto

before_deploy:
  - ps: |
        New-Item -Path deploy -ItemType directory
        Remove-Item -Recurse -Force build\dist\doc
        Get-ChildItem -Path build\dist | Move-Item -Destination deploy
        Get-ChildItem -Path deploy | Foreach-Object {
          Push-AppveyorArtifact $_.FullName -FileName ${env:APPVEYOR_REPO_COMMIT}/$_
        }

deploy:
  - provider: S3
    skip_cleanup: true
    access_key_id: AKIAIPQVNYF2T3DTYIWQ
    secret_access_key:
      secure: +11jsUNFTQ9dq5Ad1i2+PeUJaXluFJ0zIJAXESE1dFT3Kdjku4/eDdgyjgsB6GnV
    bucket: rust-lang-ci
    set_public: true
    region: us-east-1
    artifact: /.*/
    folder: rustc-builds
    on:
      branch: auto
      DEPLOY: 1
    max_error_retry: 5

  # This provider is the same as the one above except that it has a slightly
  # different upload directory and a slightly different trigger
  - provider: S3
    skip_cleanup: true
    access_key_id: AKIAIPQVNYF2T3DTYIWQ
    secret_access_key:
      secure: +11jsUNFTQ9dq5Ad1i2+PeUJaXluFJ0zIJAXESE1dFT3Kdjku4/eDdgyjgsB6GnV
    bucket: rust-lang-ci
    set_public: true
    region: us-east-1
    artifact: /.*/
    folder: rustc-builds-alt
    on:
      branch: auto
      DEPLOY_ALT: 1
    max_error_retry: 5

# init:
#   - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
# on_finish:
#   - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))