Using platformio ci with multiple incompatible libraries/platforms

I currently have the following library.json file:

{
    "name": "painlessMesh",
    "keywords": "ethernet, m2m, iot",
    "description": "A painless way to setup a mesh with ESP8266 and ESP32 devices",
    "repository": {
        "type": "git",
        "url": "https://gitlab.com/painlessMesh/painlessMesh"
    },
    "version": "1.5.4",
    "frameworks": "arduino",
    "platforms": "espressif8266, espressif32",
    "dependencies": [
        { "owner": "esp32async", "name": "AsyncTCP", "version": "^3.4.7",  "platforms" : ["espressif32"] },
        { "owner": "esp32async", "name": "ESPAsyncTCP", "version": "^2.0.0",  "platforms" : ["espressif8266"] },
        { "owner": "bblanchon", "name": "ArduinoJson", "version": "^7.4.2" },
        { "owner": "arkhipenko", "name": "TaskScheduler", "version": "^3.8.5" }
    ],
    "authors": [
        { "name": "Scotty Franzyshen" }, 
        { 
            "name": "Coopdis",
            "url": "https://github.com/Coopdis"
        }, 
        { "name": "Edwin van Leeuwen" },
        { "name": "Germán Martín" },
        { "name": "Maximilian Schwarz" },
        { "name": "Doanh Doanh" }
    ],
    "headers": "painlessMesh.h"
}

And my project has multiple examples. As part of my CI workflow I would like to build the examples and make sure there are no build errors. I am doing that using:

platformio ci --lib="." --board=nodemcuv2 examples/startHere/startHere.ino -O "build_flags = -Wall -Wextra -Wno-unused-parameter -Werror" &&
platformio ci --lib="." --board=esp32dev examples/startHere/startHere.ino -O "build_flags = -std=c++14 -Wno-incompatible-pointer-types" 

This fails, because it will try to build the incompatible asynctcp library on the esperiff8266 platform. Does anyone know how to solve this?

The following files/directories have been created in /tmp/tmpr83vnlk4
include - Put project header files here
lib - Put project specific (private) libraries here
src - Put project source files here
platformio.ini - Project Configuration File
Resolving nodemcuv2 dependencies...
Library Manager: Installing esp32async/AsyncTCP @ ^3.4.7
Unpacking  [####################################]  100%
Library Manager: AsyncTCP@3.4.7 has been installed!
Library Manager: Installing esp32async/ESPAsyncTCP @ ^2.0.0
Unpacking  [####################################]  100%
Library Manager: ESPAsyncTCP@2.0.0 has been installed!
Library Manager: Installing bblanchon/ArduinoJson @ ^7.4.2
Unpacking  [####################################]  100%
Library Manager: ArduinoJson@7.4.2 has been installed!
Library Manager: Installing arkhipenko/TaskScheduler @ ^3.8.5
Unpacking  [####################################]  100%
Library Manager: TaskScheduler@3.8.5 has been installed!
Already up-to-date.
Project has been successfully initialized!
Processing nodemcuv2 (platform: espressif8266; board: nodemcuv2; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/nodemcuv2.html
PLATFORM: Espressif 8266 (4.2.1) > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:
 - framework-arduinoespressif8266 @ 3.30102.0 (3.1.2)
 - tool-esptool @ 1.413.0 (4.13)
 - tool-esptoolpy @ 1.30000.201119 (3.0.0)
 - toolchain-xtensa @ 2.100300.220621 (10.3.0)
Converting startHere.ino
/tmp/tmpr83vnlk4/src/startHere.ino:18: warning: "LED" redefined
   18 | #define LED 2
      |
/tmp/tmpr83vnlk4/src/startHere.ino:16: note: this is the location of the previous definition
   16 | #define LED LED_BUILTIN
      |
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 42 compatible libraries
Scanning dependencies...
Dependency Graph
|-- painlessMesh @ 1.5.4
Building in release mode
Compiling .pio/build/nodemcuv2/src/startHere.ino.cpp.o
Generating LD script .pio/build/nodemcuv2/ld/local.eagle.app.v6.common.ld
Compiling .pio/build/nodemcuv2/libb3b/AsyncTCP/AsyncTCP.cpp.o
In file included from .pio/libdeps/nodemcuv2/AsyncTCP/src/AsyncTCP.cpp:4:
.pio/libdeps/nodemcuv2/AsyncTCP/src/AsyncTCP.h:11:10: fatal error: esp_idf_version.h: No such file or directory

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

   11 | #include <esp_idf_version.h>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
Compiling .pio/build/nodemcuv2/libdba/ESPAsyncTCP/AsyncPrinter.cpp.o

Can you replace this with

    "platforms": ["espressif8266, espressif32"],
    "build": {
         "libCompatMode": "strict"
    }

Then I run into another issue that it won’t pick up the local library any more, which is available on “.”:

Converting basic.ino
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 41 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/nodemcuv2/src/basic.ino.cpp.o
Generating LD script .pio/build/nodemcuv2/ld/local.eagle.app.v6.common.ld
Archiving .pio/build/nodemcuv2/libFrameworkArduinoVariant.a
Indexing .pio/build/nodemcuv2/libFrameworkArduinoVariant.a
Compiling .pio/build/nodemcuv2/FrameworkArduino/Crypto.cpp.o
Compiling .pio/build/nodemcuv2/FrameworkArduino/Esp-frag.cpp.o
Compiling .pio/build/nodemcuv2/FrameworkArduino/Esp-version.cpp.o
/tmp/tmpvonqj95r/src/basic.ino:9:10: fatal error: painlessMesh.h: No such file or directory

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

    9 | #include "painlessMesh.h"
      |          ^~~~~~~~~~~~~~~~

Mhm, not sure. Maybe the library dependecy finder is borked again.Looks like maybe https://github.com/platformio/platformio-core/issues/5171 or https://github.com/platformio/platformio-core/issues/5073. Try to push the issue in the core (https://github.com/platformio/platformio-core/issues).

Related to this, is there a way to have it use the platformio.ini in the example directory? Some of my examples need other libraries installed, and they were not picked up automatically.

In that case you should be able to just add another -O flags with lib_deps = .....

We "solved’ it by adding this to platformio.ini

lib_ignore = ESPAsyncTCP

Thank you for the suggestion. I ended up adding a script that goes into each example directory and build it there.

https://gitlab.com/painlessMesh/painlessMesh/-/blob/feature/update_dependencies/test/ci/test_platformio.sh?ref_type=heads