Building same project (platformio.ini) on multiple Operating systems - (Window/Linux sections)

What I need is to be able build a project on both Windows and Linux without the need to alter the platformio.ini file or alter the generated c_cpp_properies.json file.

This problem has appeared due to system administrators have restricted where a Windows development can output it’s build directories. Also there is a need to keep the directory structure Arduino CLI compatible. The project is stored on a git server and then pulled by remote developers using whatever operating system they have.
As you can see from the platformio.ini example below there are directories that are windows specific and although the managed to get translated into a linux file/path they are not ideal or required for Linux systems.

What I’m hoping for.
I would have thought that Platformio would allow conditional sectioning within the platformio.ini so that it would have “windows:” or “linux:” or some such mechanism similar to the vscode tasks.ini
Is there some functionality within PlatformIO that can meet the above requirements ?

build_dir = c:\projects\Build\DevOp
build_cache_dir = c:\projects\Build\Cache
src_dir = sketches\myproject
lib_dir = libraries

platform = espressif32
board = esp32doit-devkit-v1
framework = arduino

These are usually project-global settings. You can however change them per-OS-environment anyways using advanced scripting. Specficially, you can influence the construction variables

using a minimal test project like

; auto-added to all environments
extra_scripts =

platform = atmelavr
board = uno
framework = arduino

with at the same level of the platformio.ini as

import sys

IS_WINDOWS = sys.platform.startswith("win")
IS_LINUX = sys.platform.startswith("linux")
IS_MAC = sys.platform.startswith("darwin")

# should be absolute paths, not relative ones
new_build_dir = ""
   new_build_dir = "c:\\projects\\Build\\DevOp"
elif IS_LINUX:
   new_build_dir = "$PROJECT_DIR/.pio/build_custom_linux/$PIOENV"
elif IS_MAC:
   new_build_dir = "$PROJECT_DIR/.pio/build_custom_mac/$PIOENV"
   sys.stderr.write("Unrecognized OS.\n")

print("Replacing old build dir %s with %s." % (env["BUILD_DIR"], new_build_dir))

You can expand this to BUILD_CACHE_DIR as well.

1 Like

Thank you Maximilian.

I’ve give that a try and can add that to my prebuild scripts that refresh the version / build information files.