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 extra_script.py
and ended up with the following:
Directory structure
+ library.json
+ scripts/
+ extra_script.py
+ src/
+ platform/
+ windows/
+ platform_win.c
+ esp32/
+ platform_esp32.c
library.json:
{
"build": {
"srcDir": "src",
"srcFilter": "+<*> -<platform/*>",
"extraScript": "scripts/extra_script.py"
}
}
extra_script.py:
Import("env")
import os.path
platform = env.PioPlatform().name
if platform.startswith("windows"):
env.Append(SRC_FILTER=["+<platform/windows>"])
elif platform == "espressif32":
esp32_path = os.path.realpath("../src/platform/esp32")
env.Append(SRC_FILTER=[f"+<{esp32_path}>"])
You can see that I have tried several alternatives such as using the notation from library.json
inside extra_script.py
(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?