Arduino CLI 0.23 makes your projects future-proof with Build Profiles

Reading Time: 4 minutes
Arduino CLI build profiles

This new release of Arduino CLI delivers more than the usual bug fixes and performance enhancements. Today we’re delighted to bring you Build Profiles. These have been long in the works and we kept it a bit hush-hush despite releasing a public RFC a bit shy of a year ago.

Build Profiles

Sometimes Arduino users end up not being able to build and upload a Sketch after the project is completed, and this might be due to libraries changing an API, or cores having deprecated some parts in favor of a more modern approach.

Legacy is the enemy of progress, and sometimes developers need to rip the band-aid off and break things. We see this all the time.

Build Profiles aim at fixing this, and allow users of Arduino CLI to define a configuration file which contains the exact version of platforms and libraries to use, ensuring the project can be built at any time in the future.

This relies on the libraries being part of the Arduino Library Registry and the platforms to be source-able by the Arduino CLI. All platforms developed by Arduino are available by default, but users can add additional URLs to their configuration and make sure the required platform can always be found and installed.

For detailed documentation, take a look at the official Arduino CLI docs on GitHub. But let’s take a closer look at how it works so you can get started making your Arduino project future-proof.

Arduino CLI 0.23

How does this work?

Let’s assume you have an Arduino IoT Cloud project running on an Arduino Nano RP2040 Connect that is based on the following:

  • Platform: Arduino Mbed OS Nano Boards 3.1.1
  • Libraries:
    • ArduinoIoTCloud 1.6.0
    • Arduino_ConnectionHandler 0.6.6
    • WiFiNINA 1.8.13
    • Arduino_DebugUtils 1.1.0
    • ArduinoECCX08 1.3.6
    • ArduinoMqttClient 0.1.5

Your project will compile successfully, but what about five years from now?

Libraries get updated. That’s the beauty of the open source philosophy that has made Arduino so popular and the same happens with platforms.

Any dependency might discontinue an API or introduce other kinds of breaking changes, and your sketch may no longer compile. At that point, you won’t be able to upload it to a board.

We can finally address this shortcoming by creating a Build Profile for the future.

Let’s learn how to generate one and use it when the day comes.

To create a Build Profile we need to know which libraries and platforms are used during compilation,, and such dependencies can be made available to the user when compiling using `arduino-cli` and adding `–dump-profile` to the `compile` command as follows.

`arduino-cli compile -b arduino:mbed_nano:nanorp2040connect --dump-profile`

Core platforms and libraries used during the build will be listed in the report at the end of the operation, and can be copied and saved into your Build Profile, but in the future you will be able to directly create a Profile entry from a `compile` directive so the leg work will not be required.

Note that multiple profile configurations can be entered into the Build Profile and used at a later time.

The output will look something like this.

```
arduino-cli compile -b arduino:mbed_nano:nanorp2040connect --dump-profile Sketch uses 387234 bytes (2%) of program storage space. Maximum is 16777216 bytes.
Global variables use 68868 bytes (25%) of dynamic memory, leaving 201468 bytes for local variables. Maximum is 270336 bytes. profile: nanorp2040connect: fqbn: arduino:mbed_nano:nanorp2040connect platforms: - platform: arduino:mbed_nano (3.0.1) libraries: - ArduinoIoTCloud (1.6.0) - Arduino_ConnectionHandler (0.6.6) - WiFiNINA (1.8.13) - Arduino_DebugUtils (1.1.0) - ArduinoECCX08 (1.3.6) - ArduinoMqttClient (0.1.5) ```

Followed by a full report of dependencies and their paths on your system, which we will ignore in this guide.

Creating a Build Profile

Using the information above we can create a file named `sketch.yaml` and add the following content to it.

```
profile: nanorp2040connect: fqbn: arduino:mbed_nano:nanorp2040connect platforms: - platform: arduino:mbed_nano (3.0.1) libraries: - ArduinoIoTCloud (1.6.0) - Arduino_ConnectionHandler (0.6.6) - WiFiNINA (1.8.13) - Arduino_DebugUtils (1.1.0) - ArduinoECCX08 (1.3.6) - ArduinoMqttClient (0.1.5) ```

We can now rely on this file to compile our project even if we don’t have any of the libraries or the Mbed core installed by doing as follows:

`arduino-cli compile --profile nanorp2040connect`

This command will install the appropriate platforms and libraries and proceed to build your sketch into a working firmware for your board.

You can add multiple profiles in the Project file and build with different versions of a platform or any library.

When you store or distribute your sketch make sure your `sketch.yaml` file is also part of the archive, and you can have the sketch compiled cleanly at any time in the future. 

No, we can’t do anything about the past, but you can spend some time upgrading your old projects and creating their own `sketch.yaml` file, which will make your work future-proof.

Sit back, relax and watch out for Terminators coming back to hunt you down.

Website: LINK

Von Quad Oner

LEGENDS MAY SLEPP BUT THEY NEVER DIE

Schreibe einen Kommentar