Skip to content

Commit

Permalink
Build Zephyr examples in CI (#100)
Browse files Browse the repository at this point in the history
* Add CI action to build the Zephyr examples

* Add CI action to build Pico examples

* Use caching to speed things up
  • Loading branch information
erlingrj authored Oct 25, 2024
1 parent 6eb74b1 commit 43a4c9c
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 16 deletions.
30 changes: 30 additions & 0 deletions .github/actions/pico/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Install and build Zephyr dependencies
description: Install and build Zephyr dependencies
runs:
using: "composite"
steps:
- name: Install packages
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends git cmake tar build-essential \
gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
shell: bash

- name: Cache Pico SDK
id: cache-pico-sdk
uses: actions/cache@v4
with:
path: /opt/pico-sdk
key: pico-sdk-${{ runner.os }}

- name: Install pico-sdk
if: steps.cache-pico-sdk.outputs.cache-hit != 'true'
run: |
git clone https://github.com/raspberrypi/pico-sdk /opt/pico-sdk
echo "PICO_SDK_PATH=/opt/pico-sdk" >> $GITHUB_ENV
shell: bash

- name: Set environment variables
run: |
echo "PICO_SDK_PATH=/opt/pico-sdk" >> $GITHUB_ENV
shell: bash
60 changes: 60 additions & 0 deletions .github/actions/zephyr/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Install and build Zephyr dependencies
description: Install and build Zephyr dependencies
runs:
using: "composite"
steps:
- name: Setup environment variables
run: |
echo "SDK_VERSION=0.16.8" >> $GITHUB_ENV
shell: bash
- name: Dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends git cmake ninja-build gperf \
ccache dfu-util device-tree-compiler wget \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1
shell: bash
- name: Install West
run: pip install west
shell: bash

- name: Cache SDK
id: cache-zephyr-sdk
uses: actions/cache@v4
with:
path: /opt/zephyr-sdk-${{env.SDK_VERSION}}
key: zephyr-sdk-${{env.SDK_VERSION}}-${{ runner.os }}

- name: Install Zephyr SDK
if: steps.cache-zephyr-sdk.outputs.cache-hit != 'true'
run : |
wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.xz"
wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/sha256.sum" | shasum --check --ignore-missing
sudo tar xvf "zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.xz" --directory /opt/
shell: bash

- name: Cache Zephyr RTOS
id: cache-zephyr-rtos
uses: actions/cache@v4
with:
path: /opt/lf-west-template
key: lf-west-template-${{ runner.os }}

- name: Download and install Zephyr RTOS with the lf-west-template
if: steps.cache-zephyr-rtos.outputs.cache-hit != 'true'
run: |
cd /opt
git clone https://github.com/lf-lang/lf-west-template && cd lf-west-template
west update
shell: bash
- name: Setup environment variables
run: |
cd "/opt/zephyr-sdk-${{env.SDK_VERSION}}"
sudo ./setup.sh -t all -h -c
echo "ZEPHYR_BASE=/opt/lf-west-template/deps/zephyr" >> $GITHUB_ENV
echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-${{env.SDK_VERSION}}/" >> $GITHUB_ENV
cd /opt/lf-west-template
west zephyr-export
pip install -r deps/zephyr/scripts/requirements.txt
shell: bash
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ jobs:
- name: Install deps
run: |
sudo apt-get install lcov
- name: Setup java and gradle for compiling lfc
uses: ./.github/actions/prepare-build-env
# Commented out because we dont do LFC tests at the moment.
# - name: Setup java and gradle for compiling lfc
# uses: ./.github/actions/prepare-build-env
# Uncomment to SSH into the runner.
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/pico.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Pico examples

on:
pull_request:

jobs:
ci:
name: Build Pico examples
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install dependencies
uses: ./.github/actions/pico
- name: Build examples
run: |
cd examples/pico
cmake -Bbuild && cd build
make
21 changes: 21 additions & 0 deletions .github/workflows/zephyr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Zephyr examples

on:
pull_request:

jobs:
ci:
name: Build zephyr examples
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install dependencies
uses: ./.github/actions/zephyr
- name: Build examples
run: |
cd examples/zephyr
./buildAll.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# reactor-uc

`reactor-uc` is a task scheduling runtime implementing the reactor
model-of-computation target at embedded and resource-constrained 32 bit systems.
model-of-computation target at embedded and resource-constrained systems.

## Getting started

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef struct {
TcpIpChannel chan;
ConnRecv conn;
FederatedInputConnection *inputs[1];
deserialize_hook deserialize_hooks[1];
} RecvSenderBundle;

void RecvSenderBundle_ctor(RecvSenderBundle *self, Reactor *parent) {
Expand All @@ -65,7 +66,7 @@ void RecvSenderBundle_ctor(RecvSenderBundle *self, Reactor *parent) {
self->inputs[0] = &self->conn.super;

NetworkChannel *chan = &self->chan.super;
chan->open_connection(channel);
chan->open_connection(chan);

lf_ret_t ret;
LF_DEBUG(ENV, "Recv: Connecting");
Expand All @@ -74,8 +75,8 @@ void RecvSenderBundle_ctor(RecvSenderBundle *self, Reactor *parent) {
} while (ret != LF_OK);
LF_DEBUG(ENV, "Recv: Connected");

FederatedConnectionBundle_ctor(&self->super, parent, &self->chan.super, (FederatedInputConnection **)&self->inputs, 1,
NULL, 0);
FederatedConnectionBundle_ctor(&self->super, parent, &self->chan.super, (FederatedInputConnection **)&self->inputs,
self->deserialize_hooks, 1, NULL, NULL, 0);
}

typedef struct {
Expand Down Expand Up @@ -104,5 +105,5 @@ ENTRY_POINT_FEDERATED(MainRecv, FOREVER, true, true, 1, false)

int main() {
setup_led();
lf_MainRecv_start();
lf_start();
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef struct {
TcpIpChannel chan;
ConnRecv conn;
FederatedInputConnection *inputs[1];
deserialize_hook deserialize_hooks[1];
} RecvSenderBundle;

void RecvSenderBundle_ctor(RecvSenderBundle *self, Reactor *parent) {
Expand All @@ -74,8 +75,8 @@ void RecvSenderBundle_ctor(RecvSenderBundle *self, Reactor *parent) {
} while (ret != LF_OK);
LF_DEBUG(ENV, "Recv: Connected");

FederatedConnectionBundle_ctor(&self->super, parent, &self->chan.super, (FederatedInputConnection **)&self->inputs, 1,
NULL, 0);
FederatedConnectionBundle_ctor(&self->super, parent, &self->chan.super, (FederatedInputConnection **)&self->inputs,
self->deserialize_hooks, 1, NULL, NULL, 0);
}

typedef struct {
Expand Down Expand Up @@ -104,5 +105,5 @@ ENTRY_POINT_FEDERATED(MainRecv, FOREVER, true, true, 1, false)

int main() {
setup_led();
lf_MainRecv_start();
lf_start();
}
14 changes: 8 additions & 6 deletions examples/zephyr/basic_federated/federated_sender/src/sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ typedef struct {
TcpIpChannel chan;
ConnSender1 conn;
FederatedOutputConnection *output[1];
serialize_hook serialize_hooks[1];
} SenderRecv1Bundle;

typedef struct {
FederatedConnectionBundle super;
TcpIpChannel chan;
ConnSender2 conn;
FederatedOutputConnection *output[1];
serialize_hook serialize_hooks[1];
} SenderRecv2Bundle;

void SenderRecv1Bundle_ctor(SenderRecv1Bundle *self, Reactor *parent) {
Expand All @@ -131,8 +133,8 @@ void SenderRecv1Bundle_ctor(SenderRecv1Bundle *self, Reactor *parent) {
validate(ret == LF_OK);
printf("Sender: Accepted 1\n");

FederatedConnectionBundle_ctor(&self->super, parent, &self->chan.super, NULL, 0,
(FederatedOutputConnection **)&self->output, 1);
FederatedConnectionBundle_ctor(&self->super, parent, &self->chan.super, NULL, NULL, 0,
(FederatedOutputConnection **)&self->output, self->serialize_hooks, 1);
}

void SenderRecv2Bundle_ctor(SenderRecv2Bundle *self, Reactor *parent) {
Expand All @@ -152,8 +154,8 @@ void SenderRecv2Bundle_ctor(SenderRecv2Bundle *self, Reactor *parent) {
validate(ret == LF_OK);
printf("Sender: Accepted 2\n");

FederatedConnectionBundle_ctor(&self->super, parent, &self->chan.super, NULL, 0,
(FederatedOutputConnection **)&self->output, 1);
FederatedConnectionBundle_ctor(&self->super, parent, &self->chan.super, NULL, NULL, 0,
(FederatedOutputConnection **)&self->output, self->serialize_hooks, 1);
}
// Reactor main
typedef struct {
Expand Down Expand Up @@ -185,6 +187,6 @@ ENTRY_POINT_FEDERATED(MainSender, FOREVER, true, true, 2, true)
int main() {
setup_button();
setup_led();
action_ptr = &MainSender_main.sender.action;
lf_MainSender_start();
action_ptr = &main_reactor.sender.action;
lf_start();
}
19 changes: 19 additions & 0 deletions examples/zephyr/buildAll.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

# List of folders
FOLDERS=("blinky" "hello" "basic_federated/federated_sender" "basic_federated/federated_receiver1" "basic_federated/federated_receiver2" )

BOARD=frdm_k64f

# Command to execute in each folder
COMMAND="west build -b $BOARD -p always"

# Iterate over each folder and execute the command
for dir in "${FOLDERS[@]}"; do
echo "Entering $dir"
pushd $dir
$COMMAND
popd
done

0 comments on commit 43a4c9c

Please sign in to comment.