I use #ifdefs around any board specific stuff, and then use either build-in defines such as ARDUINO_ESP8266, ARDUINO_AVR_UNO or add custom ones via build_flags and then have custom env(vironment) blocks in my platformio.ini for each.
If the built-ins defines aren’t good or specific enough, or your want more control, and had say an UNO and ESP8266, and were writing shared code for them, you could do something like the below in your platformio.ini allowing you to #ifdef those defines.