Skip to content

Compile warning with strchrnul in macOS 15.4 #1659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Explorer09 opened this issue Apr 3, 2025 · 4 comments · Fixed by #1660
Closed

Compile warning with strchrnul in macOS 15.4 #1659

Explorer09 opened this issue Apr 3, 2025 · 4 comments · Fixed by #1660
Labels
dependencies Pull requests that update a dependency file MacOS 🍏 MacOS / Darwin related issues

Comments

@Explorer09
Copy link
Contributor

./XUtils.h:92:11: warning: 'strchrnul' is only available on macOS 15.4 or newer [-Wunguarded-availability-new]
   92 |    return strchrnul(s, c);
      |           ^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_string.h:198:9: note: 'strchrnul' has been marked as being introduced in macOS 15.4 here, but the deployment target is macOS 15.0.0
  198 |         strchrnul(const char *__s, int __c);
      |         ^

And we are not alone in encountering this warning.

sqlc-dev/sqlc#3916
https://www.postgresql.org/message-id/E1tziZ6-002AW9-2C%40gemulon.postgresql.org

@BenBE BenBE added MacOS 🍏 MacOS / Darwin related issues dependencies Pull requests that update a dependency file labels Apr 4, 2025
@BenBE
Copy link
Member

BenBE commented Apr 4, 2025

As some systems don't have it, we could fall back to use our internal implementation in that case. Mind to write a quick PR?

@Explorer09
Copy link
Contributor Author

@BenBE I was asking for some ideas for the fix before I try to make one for me. This compatibility problem sounds like a new one (and it's macOS exclusive)

It's because macOS 15.4 (Sequoia) does ship with strchrnul in it's standard library, but the macOS SDK that comes with macOS 15.4 defaults to building for macOS 15.0, which does not have strchrnul.

For me, there are two changes needed here:

  1. We need to check strchrnul with a header include now. Can't just use AC_CHECK_FUNCS that checks the function by linking without the header.
  2. We need to inform the builder (one who runs configure) about the MACOSX_DEPLOYMENT_TARGET in the config result. This can reduce surprise when the users find that certain functions are disabled / not used during the build.

@BenBE
Copy link
Member

BenBE commented Apr 4, 2025

The changes for configure.ac in the pgsql source seem reasonable:
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=a39eb9c77faaf51f8d02da718546e77e00a7622a

The important part of that diff is the following section:

diff --git a/configure.ac b/configure.ac
index e2d8ca9f1a0d8dc0db3767c11105fa0879cdba24..e7cd4de01639d42404ba54088ad01b461eb2ef96 100644 (file)
--- a/configure.ac
+++ b/configure.ac
@@ -1809,7 +1809,6 @@ AC_CHECK_FUNCS(m4_normalize([
    pthread_is_threaded_np
    setproctitle
    setproctitle_fast
-   strchrnul
    strsignal
    syncfs
    sync_file_range
@@ -1849,6 +1848,7 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
 # won't handle deployment target restrictions on macOS
 AC_CHECK_DECLS([preadv], [], [AC_LIBOBJ(preadv)], [#include <sys/uio.h>])
 AC_CHECK_DECLS([pwritev], [], [AC_LIBOBJ(pwritev)], [#include <sys/uio.h>])
+AC_CHECK_DECLS([strchrnul], [], [], [#include <string.h>])
 
 # This is probably only present on macOS, but may as well check always
 AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include <fcntl.h>])

Explorer09 added a commit to Explorer09/htop-1 that referenced this issue Apr 4, 2025
The strchrnul() function is also introduced in macOS 15.4, however, for
macOS build, a compiler may default to building for an older macOS
version (such as 15.0). The configure script can wrongly assume the
function may be used.

Fix the configure script's detection of strchrnul() by ensuring it's
actually available through the header.

Fixes: htop-dev#1659

Signed-off-by: Kang-Che Sung <[email protected]>
@Explorer09
Copy link
Contributor Author

I think I'll leave out the second suggested change as it's more of a usability feature than a necessary bug fix. The -mmacos-version-min option specified by the builder can be checked by the predefined macro __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ when compiling a source file, but there would parsing needed to transform the value to a human readable text. The work would be non-trivial in configure.

/* Default value for macOS SDK in macOS Sequoia (15.x) */
#define __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 150000
/* If -mmacos-version-min=15.1 is specified in CFLAGS */
#define __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 150100

Explorer09 added a commit to Explorer09/htop-1 that referenced this issue Apr 6, 2025
The strchrnul() function is also introduced in macOS 15.4, however, for
macOS build, a compiler may default to building for an older macOS
version (such as 15.0). The configure script can wrongly assume the
function may be used.

Fix the configure script's detection of strchrnul() by ensuring it's
actually available through the header.

Fixes: htop-dev#1659

Signed-off-by: Kang-Che Sung <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file MacOS 🍏 MacOS / Darwin related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants