image: "rust:latest"

stages:
  - lint
  - build
  - build-flasher

before_script:
  - apt update && apt install -y binutils-arm-none-eabi gcc-mingw-w64-x86-64-win32
  - rustup target add thumbv7em-none-eabihf
  - rustup target add x86_64-pc-windows-gnu
  - rustup component add rustfmt
  - rustup component add clippy
  - cargo install flip-link

lint:
  stage: lint
  script:
    - cargo fmt -- --check
    - cargo clippy --all-features -- -D warnings

build:
  stage: build
  script:
    - cargo build --release
    - cp target/thumbv7em-none-eabihf/release/cats-mobile-transceiver-mainboard firmware.bin
    - arm-none-eabi-strip firmware.bin
  artifacts:
    paths:
      - firmware.bin

build-flasher:
  stage: build-flasher
  script:
    - mkdir flasher
    - cd ..
    - git clone https://gitlab.scd31.com/cats/firmware-flasher
    - cd firmware-flasher
    - cp ../mobile-transceiver-software/firmware.bin firmware.bin
    - cargo build --release
    - cargo build --release --target x86_64-pc-windows-gnu
    - cp target/release/stm32-firmware-flasher ../mobile-transceiver-software/flasher/flasher-linux
    - strip ../mobile-transceiver-software/flasher/flasher-linux
    - cp target/x86_64-pc-windows-gnu/release/stm32-firmware-flasher.exe ../mobile-transceiver-software/flasher/flasher-windows.exe
  artifacts:
    paths:
      - flasher/*