when:
  - event: [manual, push, pull_request]
    branch: main

depends_on:
  - build-x86_64-linux-gnu

matrix:
  include:
    - RUST_TRIPLE: aarch64-unknown-linux-gnu
      DEBIAN_TRIPLE: aarch64-linux-gnu
      DEBIAN_ARCH: arm64
      QEMU_ARCH: aarch64
    - RUST_TRIPLE: armv7-unknown-linux-gnueabihf
      DEBIAN_TRIPLE: arm-linux-gnueabihf
      DEBIAN_ARCH: armhf
      QEMU_ARCH: arm
    - RUST_TRIPLE: riscv64gc-unknown-linux-gnu
      DEBIAN_TRIPLE: riscv64-linux-gnu
      DEBIAN_ARCH: riscv64
      QEMU_ARCH: riscv64

steps:
  - name: build-${RUST_TRIPLE}
    image: amd64/rust:latest
    environment:
      RUST_BACKTRACE: 1
      RUST_LOG: trace
      CARGO_INCREMENTAL: 0
    commands:
      - rustup target add ${RUST_TRIPLE}
      - apt-get update --quiet
      - apt-get install --quiet --no-install-recommends --yes libclang1 clang gcc-${DEBIAN_TRIPLE} libc6-dev-${DEBIAN_ARCH}-cross qemu-user
      - cargo build --verbose --workspace --jobs=1 --target=${RUST_TRIPLE}
      - cargo test --verbose --workspace --jobs=1 --target=${RUST_TRIPLE} '--config=target.${RUST_TRIPLE}.linker="${DEBIAN_TRIPLE}-gcc"' '--config=target.${RUST_TRIPLE}.runner="qemu-${QEMU_ARCH} -L /usr/${DEBIAN_TRIPLE}"' --no-run
      - cargo test --verbose --workspace --jobs=1 --target=${RUST_TRIPLE} '--config=target.${RUST_TRIPLE}.linker="${DEBIAN_TRIPLE}-gcc"' '--config=target.${RUST_TRIPLE}.runner="qemu-${QEMU_ARCH} -L /usr/${DEBIAN_TRIPLE}"' -- --test-threads=1 --nocapture
