@@ -644,6 +644,26 @@ def replace_in_all(search, replace):
644644 replace_in_file(SYSCONFIGDATA, search, replace)
645645
646646
647+ def replace_in_sysconfigdata(search, replace, keys):
648+ """Replace a string in the sysconfigdata file for select keys."""
649+ with open(SYSCONFIGDATA, "rb") as fh:
650+ data = fh.read()
651+
652+ globals_dict = {}
653+ locals_dict = {}
654+ exec(data, globals_dict, locals_dict)
655+ build_time_vars = locals_dict['build_time_vars']
656+
657+ for key in keys:
658+ if key in build_time_vars:
659+ build_time_vars[key] = build_time_vars[key].replace(search, replace)
660+
661+ with open(SYSCONFIGDATA, "wb") as fh:
662+ fh.write(b'# system configuration generated and used by the sysconfig module\n')
663+ fh.write(('build_time_vars = %s' % json.dumps(build_time_vars, indent=4, sort_keys=True)).encode("utf-8"))
664+ fh.close()
665+
666+
647667def format_sysconfigdata():
648668 """Reformat the sysconfigdata file to avoid implicit string concatenations.
649669
@@ -670,6 +690,18 @@ def format_sysconfigdata():
670690# Format sysconfig to ensure that string replacements take effect.
671691format_sysconfigdata()
672692
693+ # Remove ` -Werror=unguarded-availability-new` from ` CFLAGS` and ` CPPFLAGS` .
694+ # These flags are passed along when building extension modules. In that context,
695+ # ` -Werror=unguarded-availability-new` can cause builds that would otherwise
696+ # succeed to fail. While the issues raised by ` -Werror=unguarded-availability-new`
697+ # are legitimate, enforcing them in extension modules is stricter than CPython's
698+ # own behavior.
699+ replace_in_sysconfigdata(
700+ "-Werror=unguarded-availability-new",
701+ "",
702+ ["CFLAGS", "CPPFLAGS"],
703+ )
704+
673705# Remove the Xcode path from the compiler flags.
674706#
675707# CPython itself will drop this from ` sysconfig.get_config_var(" CFLAGS" )` and
0 commit comments