Skip to content

Conversation

@dudanov
Copy link
Contributor

@dudanov dudanov commented Nov 12, 2025

Hi. Thanks for your work!

This simple patch fixes an issue with compiling source files in the examples directory when the directory name is different from examples, in this case samples.

The default value of srcDir is src, with a fallback to the recursive .. This means that the samples directory is also considered a source directory by the Platformio builder. This patch safely defines srcDir as include, which solves the issue.

For example, when building a project for the native platform, compiling the samples/Arduino example results in a logical error about the missing header file Arduino.h.

Compiling .pio\build\native\libd8e\plog\samples\Arduino\src\main.o
.pio\libdeps\native\plog\samples\Arduino\src\main.cpp:1:10: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://registry.platformio.org/search?q=header:Arduino.h
*
*****************************************************************

    1 | #include <Arduino.h>
      |          ^~~~~~~~~~~
compilation terminated.

Perhaps this issue could be more effectively addressed in the Platformio build system by adding the example directories from the examples key of library.json to the compilation exceptions. However, this solution will allow you to work around the issue for now.

Thanks.

@dudanov dudanov marked this pull request as draft November 12, 2025 09:32
@dudanov dudanov force-pushed the platformio-build-exclude-samples branch from f039872 to 7791a90 Compare November 12, 2025 10:19
@dudanov dudanov changed the title [platformio]: exclude samples directory from build [platformio]: prevent compile samples directory Nov 12, 2025
@dudanov dudanov marked this pull request as ready for review November 12, 2025 10:36
@dudanov dudanov force-pushed the platformio-build-exclude-samples branch from 7791a90 to 414253e Compare November 12, 2025 10:38
@SergiusTheBest
Copy link
Owner

Thank you for the PR!

The behavior is unexpected and looks like a bug in platformio build system or their documentation.

@SergiusTheBest SergiusTheBest merged commit b0db518 into SergiusTheBest:master Nov 12, 2025
7 of 18 checks passed
@dudanov dudanov deleted the platformio-build-exclude-samples branch November 13, 2025 02:48
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