Description
Hi there,
I'm encountering a compilation error when attempting to install libpg-query-node
on macOS Sequoia 15.4. This issue appears to stem from a recent change in the macOS system headers, which now include the strchrnul
function, conflicting with the version defined within the library.
Below, I've outlined the details of the issue, including the environment, reproduction steps, error message, root cause, a suggested fix, a temporary workaround, and references to similar problems in other projects. I hope this information assists in resolving the issue. Please let me know if you need any additional details!
Environment
- macOS: Sequoia 15.4 (Build 24E248)
- Node.js: v22.13.1
- Yarn: v1.22.22
Steps to Reproduce
- Update your system to macOS Sequoia 15.4.
- Set up a new Node.js project or use an existing one that depends on
libpg-query
. - Run
yarn install
to trigger the installation and compilation process.
Error Message
During the build process with node-pre-gyp
, the following error occurs:
src/postgres/src_port_snprintf.c:374:1: error: static declaration of 'strchrnul' follows non-static declaration
374 | strchrnul(const char *s, int c)
| ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_string.h:198:9: note: previous declaration is here
198 | strchrnul(const char *__s, int __c);
| ^
Cause of the Issue
The error arises from a conflict between the strchrnul
function now provided by macOS 15.4's system headers and the static implementation defined in libpg-query
. Prior to this macOS version, strchrnul
may not have been available in the system, prompting libraries to include their own versions. With Sequoia 15.4, the system's non-static declaration clashes with the library's static one, resulting in a redefinition error.
Proposed Solution
To address this, I suggest wrapping the library's strchrnul
definition in a conditional compilation directive to prevent redefinition when the system already provides it. Here's an example:
#ifndef HAVE_STRCHRNUL
static char *strchrnul(const char *s, int c)
{
// Function implementation
}
#endif
Additionally, the build configuration should define HAVE_STRCHRNUL
during compilation on systems like macOS 15.4 where strchrnul
is natively available. This approach ensures compatibility across different platforms.
Temporary Workaround
As a short-term fix, users can:
- Locate the file
node_modules/libpg-query/build/libpg_query/src/postgres/src_port_snprintf.c
. - Manually add the conditional directive (as shown above) around the
strchrnul
definition. - Rebuild the module by running:
node-pre-gyp build --fallback-to-build
This should allow the compilation to succeed locally until an official fix is released.
Related Issues
This problem isn't isolated to libpg-query-node
. Similar compilation errors due to strchrnul
conflicts have been reported in other projects on macOS 15.4, including:
These cases reinforce that the issue stems from the updated system headers in macOS Sequoia 15.4.
Additional Note
The root of this issue may lie in the upstream libpg_query
library, which libpg-query-node
depends on. For instance, a related problem was reported in sqlc-dev/sqlc Issue #3916 for pg_query_go
, another libpg_query
wrapper. It might be worth applying the fix in the libpg_query
repository first (e.g., at github.com/pganalyze/libpg_query) and then updating libpg-query-node
to use the patched version.
Thank you for taking the time to review this issue. I’m happy to assist further if needed and look forward to a resolution!