Arduino magic? Compiler option? #ifdef #include #endif

#define __AVR_ATmega328__

Well; THAT shouldn't need to be there; it should be getting defined for you by the compiler/etc.
PlatformIO is supposed to be aggressively multi-platform - are you sure you're building what you think you're building?