Platform-specific source files in a library

I’m currently trying to implement a library that can be built for different platforms. However some source code should only be included based on the actual platform used. From lots of reading I currently try to implement something based on and ended up with the following:

Directory structure

+ library.json
+ scripts/
+ src/
  + platform/
    + windows/
      + platform_win.c
    + esp32/
      + platform_esp32.c


  "build": {
    "srcDir": "src",
    "srcFilter": "+<*> -<platform/*>",
    "extraScript": "scripts/"

import os.path

platform = env.PioPlatform().name
if platform.startswith("windows"):
elif platform == "espressif32":
    esp32_path = os.path.realpath("../src/platform/esp32")

You can see that I have tried several alternatives such as using the notation from library.json inside (here only in the windows platform path) or using the absolute path (only in the ESP path). I also tried setting srcFilter instead of SRC_FILTER but always with the same result. It looks like these platform specific sources are never really added to the library.

Is there something I’m missing in this setup? Should this be possible?

OMG, I’m very sorry for potentially wasting anyones time :sweat_smile: I just figured it out myself:

  1. It’s not possible to use "srcFilter" and SRC_FILTER at the same time. If you want to use an extraScript, then you have to do everything in that Python file and remove the "srcFilter" in library.json
  2. To use multiple entries in the SRC_FILTER, they have to be added as a list:
env.Append(SRC_FILTER=["+<*>", "-<platform/*>", "+<platform/windows/*>"])