Bug report
On macOS, various adjustments are made to sysconfig.get_config_vars() values via Lib/_osx_support.py. In particular, if $ARCHFLAGS is set in the environment, any -arch XYZ options are removed from CFLAGS and similar entries and are replaced by the value of $ARCHFLAGS.
For example, with Python 3.9 (the macOS system Python, one of the few non-brew hence universal2 Pythons I have locally installed):
$ python3.9 -c 'import sysconfig; print(sysconfig.get_config_var("CFLAGS"))'
-Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -Wno-error=unreachable-code -Wno-error=unused-but-set-variable -Wno-error=cast-function-type-mismatch -Wno-unknown-warning-option
ARCHFLAGS='-arch foo' python3.9 -c 'import sysconfig; print(sysconfig.get_config_var("CFLAGS"))'
-Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -Werror=implicit-function-declaration -Wno-error=unreachable-code -Wno-error=unused-but-set-variable -Wno-error=cast-function-type-mismatch -Wno-unknown-warning-option -arch foo
Notice that -arch arm64 -arch x86_64 has been removed in the middle (leaving several adjacent spaces where they were removed) and -arch foo has been appended.
With Python 3.13 installed from python.org, we get:
$ python3.13 -c 'import sysconfig; print(sysconfig.get_config_var("CFLAGS"))'
-fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -arch arm64 -arch x86_64
$ ARCHFLAGS='-arch foo' python3.13 -c 'import sysconfig; print(sysconfig.get_config_var("CFLAGS"))'
-fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -arch x86_64 -arch foo
Notice that -arch arm64 has been removed (leaving two adjacent spaces marking the location) but -arch x86_64 was not removed, and -arch foo has been appended.
Cibuildwheel sets ARCHFLAGS to build single-architecture wheels on a universal2 Python. Runs such as this pysam wheel build (see the macOS jobs in particular) exercise this functionality on a variety of Python versions. They show the -arch flags being modified correctly on versions up to 3.12, but incorrectly on 3.13, 3.14, and 3.15.
Up to version 3.12 the original CFLAGS value has these -arch options in the middle of the string. From version 3.13 onwards, the original CFLAGS value has them at the end of the string, and the last one (right at the end of the string) should be removed but is not.
CPython versions tested on:
3.13, 3.14, 3.15 releases, CPython main branch
Operating systems tested on:
macOS