PlatformIO LDF inconsistent behavior with finding included header files

Hi PIO community,

I’m trying to build an example from a new FTP library I’m testing and unfortunately I’m getting the build error shown below:

In file included from C:/Users/nitin/Documents/PlatformIO/Projects/240302-225346-featheresp32/src/Arduino_esp32_SD.ino:14:
C:/Users/nitin/Documents/Arduino/libraries/EmotiBit_SimpleFTPServer/FtpServer.h:206:11: fatal error: WiFi.h: No such file or directory

The example I’m trying to run can be found here: EmotiBit_SimpleFTPServer/examples/Arduino_esp32_SD/Arduino_esp32_SD.ino at master · EmotiBit/EmotiBit_SimpleFTPServer · GitHub. The library is placed in my Documents/Arduino/libraries to support Arduino as well as PIO.
The one modification made to the above example, was to comment out the following includes,

[line 10] //#include <WiFi.h>
[line 11] //#include "SD.h"

because

  1. they are included by FtpServer.h downstream. (which is what is breaking)
  2. Im using this library as a part of a bigger project that supports more than 1 MCU so I want the library to selectively include the dependencies (instead of me defining them)
    The library is located in my /Documents/Arduino/libraries. Also, it compiles fine using Arduino IDE.

I have tried to compile this with 2 versions of the platformio.ini file.
File that does not work (gives the build error above):

[platformio]
lib_dir = ~/Documents/Arduino/libraries

[env:featheresp32]
platform = espressif32
board = featheresp32
framework = arduino
;lib_deps = symlink://C:/users/nitin/Documents/Arduino/libraries/EmotiBit_SimpleFTPServer/
lib_ldf_mode = chain+; added the "+" to enable Preprocessor conditional syntax: https://docs.platformio.org/en/latest/librarymanager/ldf.html#c-c-preprocessor-conditional-syntax

File that works:

[platformio]
;lib_dir = ~/Documents/Arduino/libraries

[env:featheresp32]
platform = espressif32
board = featheresp32
framework = arduino
lib_deps = symlink://C:/users/nitin/Documents/Arduino/libraries/EmotiBit_SimpleFTPServer/
;lib_ldf_mode = chain+

The issue, seems like, is coming from here: EmotiBit_SimpleFTPServer/FtpServer.h at 36818e9ea9417b04febf5738035eb7cf74ceaf76 · EmotiBit/EmotiBit_SimpleFTPServer · GitHub

Additional notes:

  1. The #defines are set correctly to activate that section
  2. If I just pull out the #include "WiFi.h" from inside the nested #if and place it at the top of the FtpServer.h file, it just works.

I’m just trying to figure out what is throwing the LDF off. The compiler is clearly reaching the correct parts of the code, just not able to find the right file. Also, WiFi.h is a core esp file, So I’m wondering how that is being missed.

Also, as I said, this library is a smaller piece of a bigger project. I would want to get the lib_dir approach working as that is how the current project is setup. Moving to lib_deps=symlink could be a bigger lift and just want to double check assumptions here before making a move.

Appreciate any thoughts!

Interestingly enough, if i change the #if statement here
from
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_ESP32)
to
#elif( 1 || (FTP_SERVER_NETWORK_TYPE == NETWORK_ESP32)) // Make it “always true”

Then it compiles fine.

Looks like there is an order of operations problem here. Something like, PIO is deciding the folders to add to the search path for dependent files before evaluating the #defines, and consequently, maybe I’m getting the WiFi.h not found error?