Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure compile workflow to use include folder as additional library folder #1

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Nov 22, 2024

The "Compile examples foolder" GitHub Actions workflow uses the "arduino/compile-sketches" action to compile this project's Arduino sketches. This action uses Arduino CLI under the hood to perform the compilation.

The include folder of the repository contains a header file referenced by an #include directive in sketch code. Arduino CLI only discovers libraries under specific default paths, and since that folder is not under one of those paths, this causes compilation of the sketch by the workflow to fail:

https://github.com/hasenradball/ESP32-C3-Examples/actions/runs/11979141944/job/33400679677#step:4:175

Compiling sketch: examples/wifiTest
  /home/runner/work/ESP32-C3-Examples/ESP32-C3-Examples/examples/wifiTest/wifiTest.ino:5:10: fatal error: wifi_secrets.h: No such file or directory
      5 | #include "wifi_secrets.h"
        |          ^~~~~~~~~~~~~~~~
  compilation terminated.

Arduino CLI can be configured to use libraries from arbitrary paths by specifying those paths via the --library flag of the arduino-cli compile command. The arduino/compile-sketches action supports the injection of arbitrary arguments into the arduino-cli compile commands it runs via the action's cli-compile-flags input. So by adding the --library flag and path to the include folder to the action's input, the compilation can be made to find that header in situ.

…ary folder

The "Compile examples foolder" GitHub Actions workflow uses the "arduino/compile-sketches" action to compile this
project's Arduino sketches. This action uses Arduino CLI under the hood to perform the compilation.

The `include` folder of the repository contains a header file referenced by an `#include` directive in sketch code.
Arduino CLI only discovers libraries under specific default paths, and since that folder is not under one of those
paths, this causes compilation of the sketch by the workflow to fail:

```
Compiling sketch: examples/wifiTest
  /home/runner/work/ESP32-C3-Examples/ESP32-C3-Examples/examples/wifiTest/wifiTest.ino:5:10: fatal error: wifi_secrets.h: No such file or directory
      5 | #include "wifi_secrets.h"
        |          ^~~~~~~~~~~~~~~~
  compilation terminated.
```

Arduino CLI can be configured to use libraries from arbitrary paths by specifying those paths via the `--library` flag
of the `arduino-cli compile` command. The "arduino/compile-sketches" action supports the injection of arbitrary
arguments into the `arduino-cli compile` commands it runs via the action's `cli-compile-flags` input. So by adding the
`--library` flag and path to the `include` folder to the action's input, the compilation can be made to find that header
in situ.
@hasenradball hasenradball merged commit 6fa47ec into hasenradball:main Nov 22, 2024
@hasenradball
Copy link
Owner

@per1234
Thank you so much for the fast reply!
👍

@hasenradball
Copy link
Owner

@per1234
May I ask a final question.

Is it possible that a sketch runs fine when you compile it on PIO but gives errors when compile it on arduino cli?
See therfore the example with timerInterrupt.
workflow result

@per1234
Copy link
Contributor Author

per1234 commented Nov 23, 2024

Hi @hasenradball. Yes, it is definitely possible, for a variety of reasons.

In this specific case, there is a mismatch between the core API provided by the "platformio/espressif32" PlatformIO platform and the "esp32" Arduino boards platform.

The PlatformIO platforms for the Arduino framework are based on the Arduino boards platforms, so this means the PlatformIO platforms trail behind the development of the Arduino boards platforms. The developers of the esp32 Arduino boards platform made some very significant breaking changes in the 3.0.0 release six months ago. This included breaking changes to the Timer core API:

https://github.com/espressif/arduino-esp32/blob/master/docs/en/migration_guides/2.x_to_3.0.rst#timer

Removed APIs

[...]

  • timerAlarmWrite

[...]

  • timerAlarmEnable

[...]

timerBegin has now only 1 parameter (frequency). There is an automatic calculation of the divider using different clock sources to achieve the selected frequency.

timerAttachInterrupt has now only 2 parameters. The edge parameter has been removed.

Your sketch code uses the old Timer API, so it fails to compile when used with with a version of the esp32 Arduino boards platform >=3.0.0

The maintainers of the platformio/espressif32 PlatformIO platform have not pulled the changes from the Arduino boards platform into their project (platformio/platform-espressif32#1225), so when you use PlatformIO, you get the core API of the 2.x version of the esp32 Arduino boards platform.

There are a couple of possible approaches to make your projects compile for ESP32 boards when using the Arduino development tools and PlatformIO:

Use Version 2.x of the Arduino Platform

So the most simple way to make your projects compile for ESP32 boards when using the Arduino development tools and PlatformIO is to install the last version of the 2.x series of the esp32 Arduino boards platform, which is 2.0.17. I see you are using the version property of arduino/compile-sketches action's platform input in your workflow, so you already know how you can specify which version of the platform dependency the action should install:

core:
- version: 3.0.6
- version: 3.0.7

platforms: |
- name: esp32:esp32
source-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
version: ${{ matrix.core.version }}

You should note that many Arduino users will have the modern versions of the esp32 platform installed, so if you hope your project will be used by the Arduino community, it will be important to document that it is not compatible with version 3.x of the esp32 platform and that they will need to use Boards Manager to install version 2.0.17 of the platform to make the project compile.

Preprocessor Conditionals

The superior, but more complex alternative approach would be to add some preprocessor conditionals to your code to cause it to use the 2.x core API when compiled with a 2.x version of the platform, and use the 3.x API when compiled with a 3.x version of the platform:

#if ESP_ARDUINO_VERSION_MAJOR == 2
// 2.x core API code here.
#else
// 3.x core API code here.
#endif

Reference:

@hasenradball
Copy link
Owner

Hi @per1234 thanks for the explanation.
I want to use the latest Arduino-core.
So I can use it directly in PIO by using this config right?

[env:esp32-c3-devkitm-1]
platform = https://github.com/platformio/platform-espressif32.git
board = esp32-c3-devkitm-1
framework = arduino
platform_packages =
    framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32#master

@hasenradball
Copy link
Owner

hasenradball commented Nov 23, 2024

@per1234
No seems not to work with the above mentioned configuration.
Having issues with the libs...

image

Do you have an Idea?

@per1234
Copy link
Contributor Author

per1234 commented Nov 23, 2024

Unfortunately I have essentially zero experience using PlatformIO, so I can't offer any assistance.

There is a tremendous amount of information on the subject of version 3.x of the esp32 platform and PlatformIO in the thread of the issue here:

platformio/platform-espressif32#1225

I didn't read through it carefully enough to be able to say whether any solutions are offered there. If you don't find anything there, I recommend asking over on the PlatformIO forum. I'm sure some of the helpers there are very knowledgeable on the subject.

@hasenradball
Copy link
Owner

Will test this config…


[env:esp32-s3-devkitc-1]
platform = espressif32
platform_packages =
    platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.7
    platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.1/esp32-arduino-libs-idf-release_v5.1-632e0c2a.zip
framework = arduino

@hasenradball
Copy link
Owner

Works thanks for the hint!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants