https://github.com/python/cpython/commit/9d3a8f494985e8bbef698c467099370e233fcbd4
commit: 9d3a8f494985e8bbef698c467099370e233fcbd4
branch: main
author: Zanie Blue <cont...@zanie.dev>
committer: ned-deily <n...@python.org>
date: 2024-12-22T11:01:45-08:00
summary:

gh-100384: Error on `unguarded-availability` in macOS builds (#128155)

Generate a build error on ``unguarded-availability`` in portable macOS builds 
(i.e. using MACOSX_DEPLOYMENT_TARGET), preventing invalid use of symbols that 
are not available in older versions of the OS.

files:
A Misc/NEWS.d/next/Build/2024-12-21-09-56-37.gh-issue-100384.Ib-XrN.rst
M .github/workflows/reusable-macos.yml
M configure
M configure.ac

diff --git a/.github/workflows/reusable-macos.yml 
b/.github/workflows/reusable-macos.yml
index 6fa389b2d66e5e..cdbe05e09fb8e7 100644
--- a/.github/workflows/reusable-macos.yml
+++ b/.github/workflows/reusable-macos.yml
@@ -45,6 +45,7 @@ jobs:
         brew link --overwrite tcl-tk@8
     - name: Configure CPython
       run: |
+        MACOSX_DEPLOYMENT_TARGET=10.15 \
         GDBM_CFLAGS="-I$(brew --prefix gdbm)/include" \
         GDBM_LIBS="-L$(brew --prefix gdbm)/lib -lgdbm" \
         ./configure \
diff --git 
a/Misc/NEWS.d/next/Build/2024-12-21-09-56-37.gh-issue-100384.Ib-XrN.rst 
b/Misc/NEWS.d/next/Build/2024-12-21-09-56-37.gh-issue-100384.Ib-XrN.rst
new file mode 100644
index 00000000000000..75c19fe3d8cef9
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2024-12-21-09-56-37.gh-issue-100384.Ib-XrN.rst
@@ -0,0 +1,2 @@
+Error on ``unguarded-availability`` in macOS builds, preventing invalid
+use of symbols that are not available in older versions of the OS.
diff --git a/configure b/configure
index e59c7046305d46..a697bc1f87b012 100755
--- a/configure
+++ b/configure
@@ -10406,6 +10406,47 @@ printf %s "checking which compiler should be used... " 
>&6; }
         { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
 printf "%s\n" "$CC" >&6; }
 
+        # Error on unguarded use of new symbols, which will fail at runtime for
+        # users on older versions of macOS
+        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C 
compiler accepts -Wunguarded-availability" >&5
+printf %s "checking whether C compiler accepts -Wunguarded-availability... " 
>&6; }
+if test ${ax_cv_check_cflags__Werror__Wunguarded_availability+y}
+then :
+  printf %s "(cached) " >&6
+else $as_nop
+
+  ax_check_save_flags=$CFLAGS
+  CFLAGS="$CFLAGS -Werror -Wunguarded-availability"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+  ax_cv_check_cflags__Werror__Wunguarded_availability=yes
+else $as_nop
+  ax_cv_check_cflags__Werror__Wunguarded_availability=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+  CFLAGS=$ax_check_save_flags
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: 
$ax_cv_check_cflags__Werror__Wunguarded_availability" >&5
+printf "%s\n" "$ax_cv_check_cflags__Werror__Wunguarded_availability" >&6; }
+if test "x$ax_cv_check_cflags__Werror__Wunguarded_availability" = xyes
+then :
+  as_fn_append CFLAGS_NODIST " -Werror=unguarded-availability"
+else $as_nop
+  :
+fi
+
+
         LIPO_INTEL64_FLAGS=""
         if test "${enable_universalsdk}"
         then
diff --git a/configure.ac b/configure.ac
index 074e2ce3dd3024..ebc15503f069cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2603,6 +2603,13 @@ AS_VAR_IF([ac_cv_gcc_compat], [yes], [
         esac
         AC_MSG_RESULT([$CC])
 
+        # Error on unguarded use of new symbols, which will fail at runtime for
+        # users on older versions of macOS
+        AX_CHECK_COMPILE_FLAG([-Wunguarded-availability],
+            [AS_VAR_APPEND([CFLAGS_NODIST], [" 
-Werror=unguarded-availability"])],
+            [],
+            [-Werror])
+
         LIPO_INTEL64_FLAGS=""
         if test "${enable_universalsdk}"
         then

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to