Skip to content

build: add pkg-config support for locating system libsodium#1273

Open
chenrui333 wants to merge 1 commit into
cjdelisle:masterfrom
chenrui333:build/use-system-libsodium-pkgconfig
Open

build: add pkg-config support for locating system libsodium#1273
chenrui333 wants to merge 1 commit into
cjdelisle:masterfrom
chenrui333:build/use-system-libsodium-pkgconfig

Conversation

@chenrui333

@chenrui333 chenrui333 commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

add pkg-config support for locating system libsodium

Signed-off-by: Rui Chen <rui@chenrui.dev>
Comment thread node_build/make.js
if (process.env.SODIUM_USE_PKG_CONFIG) {
try {
const cflags = ChildProcess
.execSync('pkg-config --cflags-only-I libsodium', { encoding: 'utf8' })

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing this on ubuntu I get nothing:

root@cjd-dev:~# pkg-config --cflags-only-I libsodium

root@cjd-dev:~# 

That's because the headers are found in /usr/include and it removes system imports. It would be better to use --keep-system-cflags as per:

root@cjd-dev:~# pkg-config --cflags-only-I --keep-system-cflags libsodium
-I/usr/include 
root@cjd-dev:~# 

And that should make it work in this case

Comment thread node_build/make.js
throw new Error("Unable to find a path to libsodium headers");
throw new Error(
"Unable to find a path to libsodium headers. " +
"If you have system libsodium installed, try setting SODIUM_USE_PKG_CONFIG=1."

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run this with SODIUM_USE_PKG_CONFIG=1 and system sodium cannot be found, I get this error which is contrary to what should be happening. Per my reading of your code, it should be falling back on the vendored version. We need to investigate why this is happening.

Comment thread node_build/make.js
});
}));
// Try pkg-config first if SODIUM_USE_PKG_CONFIG is set
if (process.env.SODIUM_USE_PKG_CONFIG) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of SODIUM_USE_PKG_CONFIG I would prefer:

  1. CJDNS_FORCE_SODIUM_PKG_CONFIG -> Fail if none found in pkg-config
  2. CJDNS_SKIP_SODIUM_PKG_CONFIG -> Do not try pkg-config, only use vendored version

And if nothing is passed, attempt pkg-config and then fall back to vendored version.

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

Successfully merging this pull request may close these issues.

2 participants