image: "rust:latest"

stages:
  - lint
  - build

before_script:
  - rustup target add thumbv6m-none-eabi
  - rustup component add rustfmt
  - rustup component add clippy
  - cargo install flip-link
  - cargo install elf2uf2-rs

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

build-rev3:
  stage: build
  script:
    - cargo build --release
    - elf2uf2-rs target/thumbv6m-none-eabi/release/cats-mobile-transceiver-mainboard firmware-rev3.uf2
  artifacts:
    paths:
      - firmware-rev3

build-rev2:
  stage: build
  script:
    - sed -i "s/pub const REV_3_BOARD: bool = true;/pub const REV_3_BOARD: bool = false;/" companion-software/src/main.rs
    - cargo build --release
    - elf2uf2-rs target/thumbv6m-none-eabi/release/cats-mobile-transceiver-mainboard firmware-rev2.uf2
  artifacts:
    paths:
      - firmware-rev2
