version: "0.99.0.{build}-{branch}"

skip_commits:
  files:
    - README.md

environment:
  global:
    PROJECT_NAME: doukutsu-rs
  matrix:
    - channel: stable
      target: x86_64-pc-windows-msvc
      target_name: win64
      job_name: windows-x64
      appveyor_build_worker_image: Visual Studio 2019
#    - channel: stable
#      target: i686-pc-windows-msvc
#      target_name: win32
#      job_name: windows-x32
    - channel: stable
      target: x86_64-unknown-linux-gnu
      target_name: linux
      job_name: linux-x64
      appveyor_build_worker_image: Ubuntu
    - channel: stable
      target: x86_64-apple-darwin
      target_name: mac-intel
      job_name: mac-x64
      appveyor_build_worker_image: macos-monterey
    - channel: stable
      target: aarch64-apple-darwin
      target_name: mac-m1
      job_name: mac-arm64
      appveyor_build_worker_image: macos-monterey

matrix:
  fast_finish: true

for:
  -
    matrix:
      only:
        - appveyor_build_worker_image: Visual Studio 2019

    install:
      - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
      - rustup-init -yv --default-toolchain %channel% --default-host %target%
      - set PATH=%PATH%;%USERPROFILE%\.cargo\bin
      - rustup update
      - rustup default %channel%
      - rustc -vV
      - cargo -vV

    cache:
      - '%USERPROFILE%\.cache -> Cargo.toml'
      - '%USERPROFILE%\.cargo\bin -> Cargo.toml'
      - '%USERPROFILE%\.cargo\registry\index -> Cargo.toml'
      - '%USERPROFILE%\.cargo\registry\cache -> Cargo.toml'
      - '%USERPROFILE%\.cargo\git\db -> Cargo.toml'
      - '%USERPROFILE%\.rustup -> Cargo.toml'
      - 'target -> Cargo.toml'

    build_script:
      - set DRS_BUILD_VERSION_OVERRIDE=%APPVEYOR_BUILD_VERSION%
      - set CARGO_INCREMENTAL=1
      - cargo build --release --bin doukutsu-rs
      - mkdir release
      - copy LICENSE release\LICENSE
      - copy target\release\doukutsu-rs.exe release\doukutsu-rs.x86_64.exe
      - cd release
      - 7z a ../doukutsu-rs_%target_name%.zip *
      - appveyor PushArtifact ../doukutsu-rs_%target_name%.zip

  -
    matrix:
      only:
        - appveyor_build_worker_image: macos-monterey
        
    install:
      - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -yv --default-toolchain $channel
      - export PATH=$PATH:$HOME/.cargo/bin
      - rustup update
      - rustup default $channel
      - rustup target add $target
      - rustc -vV
      - cargo -vV
      - cargo install cargo-bundle --force

    cache:
      - '$HOME/.cache -> Cargo.toml'
      - '$HOME/.cargo/bin -> Cargo.toml'
      - '$HOME/.cargo/registry/index -> Cargo.toml'
      - '$HOME/.cargo/registry/cache -> Cargo.toml'
      - '$HOME/.cargo/git/db -> Cargo.toml'
      - '$HOME/.rustup -> Cargo.toml'
      - 'target -> Cargo.toml'

    build_script:
      - export DRS_BUILD_VERSION_OVERRIDE=$APPVEYOR_BUILD_VERSION
      - CARGO_INCREMENTAL=1 cargo bundle --release --target $target
      - mkdir release
      - cp LICENSE ./release/LICENSE
      - cp -a target/$target/release/bundle/osx/doukutsu-rs.app ./release/doukutsu-rs.app
      - cd release
      - codesign -s - -f ./doukutsu-rs.app/Contents/MacOS/doukutsu-rs
      - 7z a ../doukutsu-rs_$target_name.zip *
      - appveyor PushArtifact ../doukutsu-rs_$target_name.zip

  -
    matrix:
      only:
        - appveyor_build_worker_image: Ubuntu

    install:
      - sudo apt-get update && sudo apt-get -y install libasound2-dev libudev-dev libgl1-mesa-dev pkg-config
      - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -yv --default-toolchain $channel --default-host $target
      - export PATH=$PATH:$HOME/.cargo/bin
      - rustup update
      - rustup default $channel
      - rustc -vV
      - cargo -vV

    cache:
      - '$HOME/.cache -> Cargo.toml'
      - '$HOME/.cargo/bin -> Cargo.toml'
      - '$HOME/.cargo/registry/index -> Cargo.toml'
      - '$HOME/.cargo/registry/cache -> Cargo.toml'
      - '$HOME/.cargo/git/db -> Cargo.toml'
      - '$HOME/.rustup -> Cargo.toml'
      - 'target -> Cargo.toml'

    build_script:
      - export DRS_BUILD_VERSION_OVERRIDE=$APPVEYOR_BUILD_VERSION
      - RUSTFLAGS="-C link-arg=-s" CARGO_INCREMENTAL=1 cargo build --release --bin doukutsu-rs
      - mkdir release
      - cp LICENSE ./release/LICENSE
      - cp -a target/release/doukutsu-rs ./release/doukutsu-rs.x86_64.elf
      - cd release
      - 7z a ../doukutsu-rs_$target_name.zip *
      - appveyor PushArtifact ../doukutsu-rs_$target_name.zip
