All Projects → IARSystems → bx-github-ci

IARSystems / bx-github-ci

Licence: MIT license
This tutorial provides one example on how a CI (Continuous Integration) workflow with the IAR Build Tools for Linux can be set up on GitHub. The IAR Build Tools on Linux are available for Arm, RISC-V and Renesas (RH850, RL78 and RX).

Projects that are alternatives of or similar to bx-github-ci

bx-docker
Tutorial on how to build Docker Images for the IAR Build Tools on Linux hosts. The IAR Build Tools on Linux are available for Arm, RISC-V and Renesas (RH850, RL78 and RX).
Stars: ✭ 28 (+40%)
Mutual labels:  ci, rx, risc-v, iar, ewarm, rl78, bxarm, iarsystems, rh850
mdepx
MDEPX — A BSD-style RTOS
Stars: ✭ 17 (-15%)
Mutual labels:  arm, embedded, cortex-m, risc-v
Tock
A secure embedded operating system for microcontrollers
Stars: ✭ 3,258 (+16190%)
Mutual labels:  arm, embedded, cortex-m, risc-v
project-migration-tools
Project Migration tools to help you migrating to IAR Embedded Workbench more efficiently.
Stars: ✭ 36 (+80%)
Mutual labels:  embedded, iar, ewarm, iarsystems
Lbforth
Self-hosting metacompiled Forth, bootstrapping from a few lines of C; targets Linux, Windows, ARM, RISC-V, 68000, PDP-11, asm.js.
Stars: ✭ 293 (+1365%)
Mutual labels:  arm, cortex-m, risc-v
async-stm32f1xx
Abstractions for asynchronous programming on the STM32F1xx family of microcontrollers.
Stars: ✭ 24 (+20%)
Mutual labels:  arm, embedded, cortex-m
Distortos
object-oriented C++ RTOS for microcontrollers
Stars: ✭ 354 (+1670%)
Mutual labels:  arm, embedded, cortex-m
Eclipse Plugins
The Eclipse Embedded CDT plug-ins for Arm & RISC-V C/C++ developers (formerly known as the GNU MCU Eclipse plug-ins). Includes the archive of previous plug-ins versions, as Releases.
Stars: ✭ 507 (+2435%)
Mutual labels:  arm, embedded, risc-v
Pyocd
Open source Python library for programming and debugging Arm Cortex-M microcontrollers
Stars: ✭ 550 (+2650%)
Mutual labels:  arm, embedded, cortex-m
F9 Kernel
An efficient and secure microkernel built for ARM Cortex-M cores, inspired by L4
Stars: ✭ 596 (+2880%)
Mutual labels:  arm, embedded, cortex-m
rebuild
Zero-dependency, reproducible build environments
Stars: ✭ 48 (+140%)
Mutual labels:  toolchain, arm, embedded
Daplink
Stars: ✭ 1,162 (+5710%)
Mutual labels:  arm, embedded, cortex-m
Platformio Core
PlatformIO is a professional collaborative platform for embedded development 👽 A place where Developers and Teams have true Freedom! No more vendor lock-in!
Stars: ✭ 5,539 (+27595%)
Mutual labels:  arm, embedded, risc-v
Rt Thread
RT-Thread is an open source IoT operating system.
Stars: ✭ 6,466 (+32230%)
Mutual labels:  arm, cortex-m, risc-v
bleeding-edge-toolchain
All-in-one script to build bleeding-edge-toolchain for ARM microcontrollers
Stars: ✭ 60 (+200%)
Mutual labels:  toolchain, arm, cortex-m
embedded-in-rust
A blog about Rust and embedded stuff
Stars: ✭ 49 (+145%)
Mutual labels:  arm, cortex-m
iOSDC2020-Talk-Sample
iOSDC 2020「GitHub ActionsでiOSアプリをCIする個人的ベストプラクティス」レギュラートークのサンプルリポジトリ
Stars: ✭ 35 (+75%)
Mutual labels:  ci, github-actions
setup-graalvm
No description or website provided.
Stars: ✭ 63 (+215%)
Mutual labels:  ci, github-actions
cortexm-AES
high performance AES implementations optimized for cortex-m microcontrollers
Stars: ✭ 18 (-10%)
Mutual labels:  arm, cortex-m
utest
Lightweight unit testing framework for C/C++ projects. Suitable for embedded devices.
Stars: ✭ 18 (-10%)
Mutual labels:  arm, cortex-m

Tutorial
IAR Build Tools for Linux in a GitHub CI

Each of the IAR Build Tools for Linux packages requires its specific license. Please feel free to contact us if you would like to learn how to get access to them.

If you want to be notified in your GitHub inbox about updates to this tutorial, you can start watching this repository. You can customize which types of notification you want to get. Read more about notifications and how to customize them.

If you end up with a question specifically related to this tutorial, you might be interested in verifying if it was already answered from earlier questions. Or, ask a new question if you could not find any answer for your question.

Introduction

This tutorial provides a simple example with general guidelines on how to set up a CI (Continuous Integration) workflow with IAR Build Tools for Linux alongside GitHub.

GitHub

At GitHub, a private project repository, called origin in the Git jargon, starts with a master branch containing the production code.

The repository also contains a "recipe" for the workflow under .github/workflows. The recipe is written in the YAML format and can be customized. We provided one simple example as base, although the official documentation can help with further customizations.

The repository will be configured to use one GitHub's self-hosted runner.

⚠️ GitHub requires an account. An Azure account also can be used.

Build server

The build server will be where the IAR Build Tools for Linux are installed.

It will serve as a self-hosted runner from where the GitHub's Actions workflow will take place. This runner will be configured to automatically connect to the origin. When triggered, the runner will execute a job that, after cloning the repository and will use the IAR Build Tools for Linux to build these projects.

Development workstation

On his workstation, a developer clones the repository to start working on a new feature for some project. For that, he creates a feature branch.

The developer then launches the IAR Embedded Workbench, from where he can code, build and debug the project.

When the developer is done with that, he can, through his own GitHub account, push the branch to the origin using a git client.

⚠️ Popular choices for Windows that provide a git client are Git for Windows, GitHub for Desktop or even Ubuntu WSL. In this tutorial, we are going to use the git from the command-line.

The typical CI workflow

The objective is to have automated builds for keeping track of which changes break the build before they are introduced into the master branch. This practice can help raise the project's overall quality metrics.

When a developer pushes changes to the origin, GitHub Actions comes into play and triggers an action to notify the runner in the build server about the new push.

On the build server, the runner will then execute the "recipe" to build the project with the IAR Build Tools.

If the new feature passes, the code reviewer can decide if these changes are ready to be merged to the master branch.

If the new feature fails, the follow-up can be performed within GitHub's facilities for code revision.

This CI repeats as many times as required.

Conventions

As this tutorial is intended to be flexible with respect to the tools and packages that can be used, it becomes important to establish some conventions for when referring to certain entities.

Packages

Placeholder Meaning
<arch> Architecture
Valid: arm, riscv, rh850, rl78, rx
<package> Product package
Valid: arm, armfs, riscv, rh850, rh850fs, rl78, rx
<version> Package version
Valid: major.minor.patch [.build]

Here you will find some examples for different packages and their versions:

Package/Version Replace with
BXARM 9.10.1 IAR Build Tools for Arm version 9.10.1
<arch>=arm
<package>=arm
<version>=9.10.1
BXARMFS 8.50.10.35167 IAR Build Tools for Arm, Functional Safety Edition, version 8.50.10
<arch>=arm
<package>=armfs
<version>=8.50.10.35167
BXRISCV 1.40.1 IAR Build Tools for RISC-V version 1.40.1
<arch>=riscv
<package>=riscv
<version>=1.40.1

Others

Placeholder Meaning
<username> Refer to the user's GitHub's account or the user's account in the local machine, according to the context.

Preparing the repository

Under GitHub's account, we are going to import the bx-workspaces-ci repository. This is a public repository containing a collection of workspaces which were created using the IAR Embedded Workbench. They can be imported to become a private repository and then used for experimentation with the IAR Build Tools for Linux.

Importing an example repository

Navigate to

https://github.com/new/import

Fill Your old repository's clone URL with

https://github.com/IARSystems/bx-workspaces-ci

On Your new repository details, fill with the new name. For this example, let's use shr-private:

shr-private

Make sure that Privacy is set to private.

⚠️ GitHub adverts against using self-hosted runners with public repositories due security reasons.

Finally, click Begin import.

Once the importing process is complete, a message will show up:

"Your new repository `<username>/shr-private` is ready."

Click on the link to the new repository provided in the message to go to the new repository.

Adding a workflow

On your shr-private repository, use the GitHub interface to add the following new file .github/workflows/bx.yaml. This workflow contains a single job that runs on a self-hosted runner called "iarbuild" with 3 steps to build the projects in the sequence library, componentA and componentB, after the repository is checked out:

name: IAR Build Tools CI
on:
  push:
    branches: [ dev* ]
env:
  BUILD_TYPE: Debug  
  IARBUILD_PATH: /opt/iarsystems/bx<package>-<version>/common/bin
  IARBUILD_OPTS: -log all -parallel 2
jobs:
  iarbuild:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v2
      - name: Build Library
        run: $IARBUILD_PATH/iarbuild ./<package>/library.ewp    -build $BUILD_TYPE $IARBUILD_OPTS
      - name: Build Component A
        run: $IARBUILD_PATH/iarbuild ./<package>/componentA.ewp -build $BUILD_TYPE $IARBUILD_OPTS
      - name: Build Component B
        run: $IARBUILD_PATH/iarbuild ./<package>/componentB.ewp -build $BUILD_TYPE $IARBUILD_OPTS    

⚠️ Update <package> and <version> to match with the IAR Build Tools for Linux you are using. Please refer to Conventions for details.

Adding a runner to the repository

The GitHub repository must be set to use a runner.

Go to Settings/Actions/Runners/New:

https://github.com/<username>/shr-private/settings/actions/runner/new

For Operating System: select Linux.

For Architecture: select x64.

Leave this page open.

Setup the Build Server

Go to the build server and perform the following setup.

Setup the runner

Use the GitHub's provided instructions for Download and Configure the self-hosted runner, using its default configurations.

⚠️ By downloading and configuring the GitHub Actions Runner, you agree to the GitHub Terms of Service or GitHub Corporate Terms of Service, as applicable.

Once the runner is in place, go to the repository's Settings/Actions page at:

https://github.com/<username>/shr-private/settings/actions

The status for the Self-hosted runner should be Idle at this point:

Install the IAR Build Tools for Linux

Install the IAR Build Tools for Linux.

⚠️ Follow the instructions and recommendations of the User Guide that comes with the product.

Additionally, it is possible to add the IAR Build Tools directories containing the executables to the search PATH, so they can be executed from anywhere without entering with their full path. This is not a requirement for this tutorial, but it might be convenient for some users.

For example, paste the snippet below to the user's $HOME/.profile (or else the $HOME/.bashrc) file:

if [ -d "/opt/iarsystems/bx<package>-<version>" ]; then
  PATH="/opt/iarsystems/bx<package>-<version>/<arch>/bin:/opt/iarsystems/bx<package>-<version>/common/bin:$PATH"
fi

⚠️ Change <arch>, <package> and <version> to match with the IAR Build Tools for Linux you are using. Please refer to Conventions for details.

After the file is saved, it is possible to source the file you modified so the changes take effect immediately. For example,

source ~/.profile

Developing a Project

Now that the server-side of the setup is done, let's start to try it from a developer's perspective, from within the Development workstation.

Cloning the repository

Launch the terminal which provides your git client and clone the shr-private repository you imported into your <username> account:

git clone https://github.com/<username>/shr-private.git /mnt/c/shr-private && cd /mnt/c/shr-private

⚠️ For this tutorial we are assuming that the clone location will be the C:\shr-private folder.

Switching to a feature branch

Now let's consider starting to work on a new feature for the ComponentB. Checkout a new branch named "dev-componentB", derived from the master branch:

git checkout -b dev-componentB master

In the IAR Embedded Workbench IDE choose FileOpen Workspace... and navigate to C:\shr-project\<arch>. You will find a workspace.eww file. Go ahead and open it.

This example workspace comes with 3 projects:

  • library
  • componentA
  • componentB

Right-click on the library project and choose Make (or F7). The library project should be built with no errors.

Now right-click on the componentB project and Set as Active.

Unfold the componentB project tree and double click on its main.c file so it will open in the Code Editor.

Right-click on componentB and choose Make (or F7). The componentB project should be built with no errors.

Changing the code for the componentB project

The developer starts to work on the dev-componentB branch and, for illustrative purposes, the DATATYPE used in componentB had to change from uint16_t to float, for example, to hold values greater than 0xFFFF.

On the main.c file, right-click on the line with the #include "library.h" and choose Open "library.h".

In the library.h file, find the line #define DATATYPE uint16_t and replace it with

#define DATATYPE float

In the main.c file, update the constant z to 100000.

  const DATATYPE z = 100000;

On the same file, update the debug_log() function string format to handle the float type. Change the formatted string from %d to %f as below:

  debug_log("Sum = %f\r\n", sum);

and

  debug_log("Mul = %f\r\n", mul);

Rebuild the library project using right-click on library and choose Make (or F7). It should build with no errors.

Rebuild the componentB project using right-click on componentB and choose Make (or F7). It should build with no errors.

⚠️ If you want, you can debug the project using ProjectDownload & Debug (or CTRL+D). The details of debugging a project are not going to be covered in this tutorial. For further details on debugging a project, refer to the HelpC-SPY Debugging Guide document that is shipped with the product.

Commit the changes

Go back to the terminal where you used your git client.

Commit to the changes to the tracked files in the cloned shr-project repository:

git commit --all --message "Improvement proposal for componentB"

The expected output is similar to this, but with a different commit hash:

[dev-componentB 5b03ed8] Improvement proposal for componentB
 2 files changed, 5 insertions(+), 5 deletions(-)

Finally publish these changes with git push, so the code changes go back to the origin repository:

git push --set-upstream origin dev-componentB

Creating a Pull Request

Then it is time for the developer to go back his GitHub.com:

Go to https://github.com/<username>/shr-private and notice that there is a new yellow banner on the top

Click Compare & pull request.

Here, GitHub will give you the opportunity to write an explanation of the new feature you are pushing for the componentB project. That way, the code reviewer can have a better picture of what is going on.

Once ready, click Create pull request.

⚠️ Follow the link to learn more about pull requests.

Reviewing the Pull Request

The bx-workspaces-ci repository comes pre-loaded with a workflow configured in the .github/workflows/bx.yml file that will trigger the notification the runner in the build server needs to build all the 3 projects automatically when a new feature branch goes through a pull request.

Now a project's code reviewer can start reviewing the pull request containing the proposed changes in the new feature.

With the right workflow for a project, if some developer created something new that breaks the existing build, it will fail the automated verification. So a code reviewer can know immediately about the breakage and its details.

In this case, the author's proposed change to the shared library worked nicely for componentB but it didn't for componentA.

The code reviewer can contact the author using pull request page, so it is easy to keep track of any amends to the proposed code, until it is approved or rejected.

Summary

In short, in this tutorial we went through one of the many ways that the IAR Build Tools for Linux can be used in CI scenarios.

Over time, a practice like this can help guaranteeing convergence to improved quality of the production grade code base. It also helps avoiding that new features break other parts of a project. Ultimately it builds a development log of the project which, when properly used, can become a solid asset for consistent deliveries as the project evolves.

The IAR Build Tools for Linux along with the GitHub CI provides a great and scalable way to manage automation tasks for building, and analyzing embedded software projects. Hence it might be suitable for many use cases.

For more tutorials like this, stay tuned on our GitHub page.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].