I have to keep editing PlatformIO.ini for PC vs Mac -- help?

As I am still a PlatformIO newbie, I finally figured out how to get my same Teensy project to compile on both PC and Mac, but I have to keep editing my PlatformIO.ini file everytime I switch between my PC laptop and Mac laptop on the same project.

Is there a way to simplify this? See the last two lines:

[env:teensy40]
platform = teensy
board = teensy40
framework = arduino
upload_protocol = teensy-gui
lib_deps = 
    Arduino
    https://github.com/pedvide/ADC
build_flags = 
    -D LAYOUT_US_ENGLISH
    -D USB_CUSTOM

;;; Activate a few custom USB descriptor customizations without editing
;;; the original Teensy files, this overrides the system usb_desc.h when
;;; rebuilding the Teensy libraries. Need to "Full Clean" and rebuild.
;;; Include paths. Uncomment the Windows vs PC/Mac version as applicable.
    -I src
    -include .\\src\\usb_desc.h 
;    -include ./src/usb_desc.h

The last two lines I keep editing –

Is there a pragma (like an #ifdef WINDOWS versus #ifdef MAC) I can use for platformio.ini files?

I frequently switch between my Mac and PC for my project, since I’m doing a multiplatform project that can connect to a custom accessory I’m building that now has a custom USB VID/PID pair (legitimate) installed into the Teensy. It’s the only file I keep editing every time I switch…

I’d rather not resort to editing the teensy library files, as it’s reloaded automatically (library updates, fresh installs of the environment, etc)

What I’ve tried to do so far:

– Move file to try to remove the path requirement
– To try to standardize UNIX paths (which is a technique I do for other projects other than PlatformIO) – I also tried to use WSL on Windows but PlatformIO doesn’t support it. FWIW, command line via Linux arduino works to build project in WSL. Then manully load firmware via launching the Windows .exe version of teensy-cli from the WSL environment (had to use a bit of creativity due to my custom USB PID/VID).

1 Like

Doh – figured it out on my own.
I just realized that I can use the / slash on Windows.

MacBook: works with /
Windows: works with both \\ and /

I did have to avoid using ${PROJECT_DIR} because that wasn’t cross platform compatible. That did not work on Windows (–include ${PROJECT_DIR}/src/usb_desc.h) but using relative paths worked, in further experimenting.

So, I have now standardized on / at least for the platformio.ini file.

(Still wish I can use WSL with PlatformIO though)

1 Like

(Update, in further WSL research… because inevitably WSL lovers may start asking me questions here.)

I found out I could modify a file to add WSL support; google “PlatformIO WSL patch” which brought up this support reply. In theory it means I can go all-UNIX-paths. I’d still have to run the teensy-cli exe (still runnable from WSL back to Windows to install the .hex, so I can still install the .hex from a bash script, in a firmware upgrader).

(Clearly, Pros/cons. For stock PlatformIO upgrades, I’ll just stay non-WSL; just a bit annoying to switch in/out of Remote mode for my other projects versus this project.)

Also, a bit of extra big hoop jumping has to occur if you modify the USB PID/VID away from the Teensy standard, just adding this here. My project compiles at the command line under WSL, so that’s fine for now, as I have a backup command line build process. So it’s a workflow pros/cons thing.

From the github stuff I am seeing on PlatformIO it is my understanding that eventually a new verison of PlatformIO is coming out eventually that’s more prepared to support WSL remotes. Just adding an extra vote that I’ll be eager to anticipate WSL support once things settle down in the country a bit more. (Only learned that tidbit recently.)

On that note, I think I’m finally 100% fully set up, and can sunset Arduino IDE for almost everything except a vestigal install to provide the needed CLI stuff.