-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
…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.
@per1234 |
@per1234 Is it possible that a sketch runs fine when you compile it on PIO but gives errors when compile it on arduino cli? |
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
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 PlatformSo 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 ESP32-C3-Examples/.github/workflows/compile_examples.yml Lines 18 to 20 in 275aad4
ESP32-C3-Examples/.github/workflows/compile_examples.yml Lines 34 to 37 in 275aad4
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 ConditionalsThe 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: |
Hi @per1234 thanks for the explanation.
|
@per1234 Do you have an Idea? |
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. |
Will test this config…
|
Works thanks for the hint! |
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
Arduino CLI can be configured to use libraries from arbitrary paths by specifying those paths via the
--library
flag of thearduino-cli compile
command. The arduino/compile-sketches action supports the injection of arbitrary arguments into thearduino-cli compile
commands it runs via the action'scli-compile-flags
input. So by adding the--library
flag and path to theinclude
folder to the action's input, the compilation can be made to find that header in situ.