image:
  - Ubuntu
  - macOS
  - Visual Studio 2019

## Build Matrix ##

# This configuration will setup a build for each channel & target combination (12 windows
# combinations in all).
#
# There are 3 channels: stable, beta, and nightly.
#
# Alternatively, the full version may be specified for the channel to build using that specific
# version (e.g. channel: 1.5.0)
#
# The values for target are the set of windows Rust build targets. Each value is of the form
#
# ARCH-pc-windows-TOOLCHAIN
#
# Where ARCH is the target architecture, either x86_64 or i686, and TOOLCHAIN is the linker
# toolchain to use, either msvc or gnu. See https://www.rust-lang.org/downloads.html#win-foot for
# a description of the toolchain differences.
# See https://github.com/rust-lang-nursery/rustup.rs/#toolchain-specification for description of
# toolchains and host triples.
#
# Comment out channel/target combos you do not wish to build in CI.
#
# You may use the `cargoflags` and `RUSTFLAGS` variables to set additional flags for cargo commands
# and rustc, respectively. For instance, you can uncomment the cargoflags lines in the nightly
# channels to enable unstable features when building for nightly. Or you could add additional
# matrix entries to test different combinations of features.

environment:
  APPVEYOR_YML_DISABLE_PS_LINUX: true
  matrix:
    - channel: stable
    - channel: beta
    - channel: nightly

# OSX tests are allowed to fail until upstream serialport-rs crate fixes handling buadrate control for virtual serial
# ports.  See:
#  - https://gitlab.com/susurrus/serialport-rs/-/issues/105
#  - https://gitlab.com/susurrus/serialport-rs/-/merge_requests/101

matrix:
  allow_failures:
    - image: macOS
# This is the most important part of the Appveyor configuration. This installs the version of Rust
# specified by the 'channel' and 'target' environment variables from the build matrix. This uses
# rustup to install Rust.
#
# For simple configurations, instead of using the build matrix, you can simply set the
# default-toolchain and default-host manually here.
install:
  # Windows Install
  - cmd: cd .github
  - cmd: C:\"Program Files (x86)"\"Windows Kits"\10\bin\10.0.19041.0\x64\CertMgr.exe /add com0com.cer /s /r localMachine root
  - cmd: C:\"Program Files (x86)"\"Windows Kits"\10\bin\10.0.19041.0\x64\CertMgr.exe /add com0com.cer /s /r localMachine trustedpublisher
  - cmd: set CNC_INSTALL_CNCA0_CNCB0_PORTS=YES
  - cmd: .\setup_com0com_W7_x64_signed.exe /S
  - cmd: cd C:\"Program Files (x86)"\com0com
  - cmd: .\setupc.exe install PortName=COM10,EmuBR=yes PortName=COM11,EmuBR=yes
  - cmd: cd "%APPVEYOR_BUILD_FOLDER%"
  - cmd: appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
  - cmd: rustup-init -yv --default-toolchain %channel%
  - cmd: set PATH=%PATH%;%USERPROFILE%\.cargo\bin
  # - cmd: choco install com0com
  # - cmd: cd "C:\Program Files (x86)\com0com\"
  # - cmd: set CNC_INSTALL_CNCA0_CNCB0_PORTS=YES
  # - cmd: dir
  # - cmd: .\setupc.exe --silent install PortName=COM10,EmuBR=yes PortName=COM11,EmuBR=yes
  # - cmd: cd "%APPVEYOR_BUILD_FOLDER%"
  # Linux install (socat already installed)
  - sh: echo Image is $APPVEYOR_BUILD_WORKER_IMAGE
  - sh: if [ "$APPVEYOR_BUILD_WORKER_IMAGE" = "macOS" ]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install socat; fi
  # - sh: sudo apt-get update && sudo apt-get install socat
  - sh: curl --proto '=https' --tlsv1.2 -sSf -o rustup-init https://sh.rustup.rs
  - sh: chmod u+x rustup-init
  - sh: ./rustup-init -y --default-toolchain ${channel}
  - sh: source $HOME/.cargo/env
  #- sh: export PATH=${PATH};${HOME}/.cargo/bin
  - rustc -vV
  - cargo -vV
  - sh: socat -V

## Build Script ##

# 'cargo test' takes care of building for us, so disable Appveyor's build stage. This prevents
# the "directory does not contain a project or solution file" error.
build: false

# Don't run tests, they require actual serial ports and will fail on CI
test_script:
  - cmd: set TEST_PORT_NAMES=COM10;COM11
  - cmd: set RUST_LOG=trace
  - sh: export TEST_PORT_NAMES='/tmp/ttyS0;/tmp/ttyS1'
  - sh: set RUST_LOG=trace
  - cargo test -j1 -- --test-threads=1
