feat(build): support optional system libnghttp2 linking#9
Merged
Conversation
Add opt-in linking against a system libnghttp2 (discovered via pkg-config) while keeping the bundled static build as the default and fallback. - Declare `links = "nghttp2"` so Cargo enforces a single native-library version and exposes DEP_NGHTTP2_ROOT / DEP_NGHTTP2_INCLUDE to downstream build scripts. - Add a `system` Cargo feature and a LIBNGHTTP2_SYS_USE_PKG_CONFIG env var to opt into system linking; both fall back to the bundled build when no suitable system library is found. - When using the system library, generate bindings against the system headers via pkg-config include paths. - Add a CI job that installs libnghttp2-dev and verifies the binary is dynamically linked against the system library. - Document the linking options in the README. Co-Authored-By: Divy Srivastava <me@littledivy.com>
The lib's own unit-test harness has no tests and references no nghttp2 symbols, so --as-needed drops its DT_NEEDED entry and ldd shows nothing. Check the integration test binary, which actually calls nghttp2. Co-Authored-By: Divy Srivastava <me@littledivy.com>
littledivy
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in support for linking against a system libnghttp2 (discovered via
pkg-config) while keeping the bundled static build as the default andfallback. This is the packaging/linking support requested in #7 and the
native-library metadata requested in #8.
What changed
links = "nghttp2"inCargo.toml— Cargo now enforces a singlenative-library version across the dependency graph and exposes
DEP_NGHTTP2_ROOT/DEP_NGHTTP2_INCLUDEto downstream build scripts.systemCargo feature, orLIBNGHTTP2_SYS_USE_PKG_CONFIG=1environment variable (no sourcechanges needed — handy for distro packagers).
cargo:warningwhen nosuitable system library is found, so the default behavior is unchanged.
headers via the pkg-config include paths (bindgen config is shared between
both paths).
system-linkjob installslibnghttp2-dev, builds with--features system, and asserts vialddthat the test binary isdynamically linked against the system
libnghttp2.so.Verification
Locally (macOS,
brew install pkg-config nghttp2):cargo test→ builds bundled, 16/16 tests pass.LIBNGHTTP2_SYS_USE_PKG_CONFIG=1 cargo testandcargo test --features system→ 16/16 pass;
otool -Lconfirms the binary links/opt/homebrew/opt/libnghttp2/lib/libnghttp2.14.dylib.PKG_CONFIG_LIBDIRpointed at an empty dir)→ warns and falls back to the bundled build; 16/16 pass.
This stays focused on packaging/linking support — no crate redesign.
Closes #7
Closes #8
Closes denoland/divybot#488