PlatformIO installed an x86_64 arch python in M chip mac

Hi, everyone. I encountered a failure today and finally figured out what happened. The root cause is that the PlatformIO extension of the Visual Studio Code extension installed the wrong architecture portable Python.

This extension installs x86_64 architecture Python, which misleads Scons to build x86_64 .a/.o files. Failure happens when Scons tries to link those files to arm64 architecture SDL2, which was installed by homebrew:

ld: warning: ignoring file '/opt/homebrew/Cellar/sdl2/2.30.1/lib/libSDL2-2.0.0.dylib': found architecture 'arm64', required architecture 'x86_64'
ld: Undefined symbols:
  _SDL_CreateRenderer, referenced from:
      _window_create in sdl.o

The workaround is to add build_flags to platformio.ini:

build_flags =
  -arch arm64

However, everything is OK when I run pio from a native Python (arm64) environment. So, I believe the problem is that the extension should install the correct Python to avoid this.

GitHub issue related to this.