#!/bin/bash
set -e # exit on failure

# do compile tests for the defined set of embedded boards
# Usage: verify_embedded_compile

# ensure necessary targets are installed
rustup target add thumbv6m-none-eabi
rustup target add thumbv7em-none-eabi
rustup target add thumbv7em-none-eabihf
rustup target add thumbv8m.main-none-eabi
rustup target add thumbv8m.main-none-eabihf
rustup target add riscv32imac-unknown-none-elf

# @TODO: 
PLATFORMS="espressif-esp32-c3-devkit-rust-1, espressif-esp32-c6-devkitc-1, bbc-microbit-v2, nrf52840dk, rpi-pico, rpi-pico2"

# test availability of compile targets with first example
for BOARD in $PLATFORMS
do
    clear
    laze build -b $BOARD -C embedded/ariel-os/t01_build_your_first_tree
done

for BOARD in $PLATFORMS
do
    # examples
    clear
    laze build -b $BOARD -C embedded/ariel-os/t02_basic_ports
    clear
    laze build -b $BOARD -C embedded/ariel-os/t03_generic_ports
    clear
    laze build -b $BOARD -C embedded/ariel-os/t04_reactive_sequence
    clear
    laze build -b $BOARD -C embedded/ariel-os/t05_crossdoor
    clear
    laze build -b $BOARD -C embedded/ariel-os/t06_subtree_port_remappings
    clear
    laze build -b $BOARD -C embedded/ariel-os/t07_load_multiple_xml
    clear
    laze build -b $BOARD -C embedded/ariel-os/t08_additional_node_args
    clear
    laze build -b $BOARD -C embedded/ariel-os/t09_scripting
    clear
    laze build -b $BOARD -C embedded/ariel-os/t10_observer
    clear
    CONFIG_WIFI_NETWORK=dummy CONFIG_WIFI_PASSWORD=dummy laze build -b $BOARD -C embedded/ariel-os/t11_groot_howto
    clear
    laze build -b $BOARD -C embedded/ariel-os/t12_default_ports
    clear
    laze build -b $BOARD -C embedded/ariel-os/t13_access_by_ref
    clear
    laze build -b $BOARD -C embedded/ariel-os/t14_subtree_model
    clear
    laze build -b $BOARD -C embedded/ariel-os/t15_behavior_mocking
    clear
    laze build -b $BOARD -C embedded/ariel-os/t16_global_blackboard
    #clear
    #laze build -b $BOARD -C embedded/ariel-os/t17_blackboard_backup
    clear
    laze build -b $BOARD -C embedded/ariel-os/t18_waypoints
done

# apps
laze build -b rpi-pico2 -C embedded/ariel-os/garage_door_opener
laze build -b rpi-pico2-w -C embedded/ariel-os/garage_door_opener

# embassy examples
cd embedded/embassy/nrf52840dk
cargo build --bin t01_build_your_first_tree
cd ../rp2040
cargo build --bin t01_build_your_first_tree
cd ../rp235x
cargo build --bin t01_build_your_first_tree
