Skip to content

Compilation Error on macOS Sequoia 15.4 Due to strchrnul Conflict #88

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

Open
jaicmatija opened this issue Apr 8, 2025 · 4 comments
Open

Comments

@jaicmatija
Copy link

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

  1. Update your system to macOS Sequoia 15.4.
  2. Set up a new Node.js project or use an existing one that depends on libpg-query.
  3. 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:

  1. Locate the file node_modules/libpg-query/build/libpg_query/src/postgres/src_port_snprintf.c.
  2. Manually add the conditional directive (as shown above) around the strchrnul definition.
  3. 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!

@emieljanson
Copy link

Ran into this issue but the node_modules/libpg-query/build... isn't available as it isn't built yet. Haven't found a solution to install libpg-query on 15.4 yet.

@emieljanson
Copy link

It seems like the libpg_query already got fixed pganalyze/libpg_query#282 (comment)

@diego-coba
Copy link

Our team is facing this issue. As a workaround I had to run a Linux container and work on it using Remote Explorer in VSCode. We'd be really grateful for a new version released using the versión of libpg_query compatible with Mac Os 15.4

@dallen4
Copy link

dallen4 commented Apr 23, 2025

we have a few devs blocked by this compilation/build step on a repo, any updates on when a new version of this library will be published?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants