this doesn’t make it easy to actually build and run the examples
there is too much nesting, folders with a single file are tedious
The first problem is actually the bigger issue. How do you get these examples to compile? Do I need to include a platformio.ini file with each? And then add lib_extra_dirs = ../../.. to find the library? That will cause PIO to scan all sibling directories as well, which would be confusing (and slow).
The second issue appears to be solvable with the following alternative:
The standard Arduino library structure works too: pull out the files from include/ and src/ into the mylib folder.
Have you tried the pio ci commands? They’re meant for continuous integration, e.g. compiling a library example and seeing if compilation goes through. Documentation is available (this page among lots of others). So something in the style of
pio ci path/to/example/file.cpp --lib="path/to/library/folder" --board=uno
(or whatever board.) Then you don’t need the examples to be full PlatformIO project folders.
And indeed, it compiles and builds perfectly, using:
pio ci examples/simple.cpp --lib=. --board=disco_f407vg
The only surprise was that it assumes Arduino’s setup/loop as main. I’m normally targeting stm32cube - but it turns out this can easily be addressed by adding -O 'framework=stm32cube'.
And I see that even uploads are supported - splendid!
I solved this by using a single platformio.ini and add new environments for every example I use. See the example below.
This works a bit more like Cargo from the Rust language operates. Also you know that the whole project keeps on working.
Thanks - as it so happens, the src_filter = …` approach is exactly what I’ve settled on. And as you point out, being able to compile all of them as a quick check is a nice convenience.