]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-100384: Error on `unguarded-availability` in macOS builds (#128155)
authorZanie Blue <contact@zanie.dev>
Sun, 22 Dec 2024 19:01:45 +0000 (13:01 -0600)
committerGitHub <noreply@github.com>
Sun, 22 Dec 2024 19:01:45 +0000 (11:01 -0800)
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.

.github/workflows/reusable-macos.yml
Misc/NEWS.d/next/Build/2024-12-21-09-56-37.gh-issue-100384.Ib-XrN.rst [new file with mode: 0644]
configure
configure.ac

index 6fa389b2d66e5eddd8720d84a691b7a2b2533752..cdbe05e09fb8e7a1237cd28ccee884818928d4e8 100644 (file)
@@ -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 (file)
index 0000000..75c19fe
--- /dev/null
@@ -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.
index e59c7046305d466e5bc1ea19e329562fa6a07526..a697bc1f87b01252295801eac2518096606ebabe 100755 (executable)
--- 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
index 074e2ce3dd3024aa19271a2dc240f71625fd6860..ebc15503f069cc5670c115a4fa2a171977bf33a4 100644 (file)
@@ -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