Skip to content

feat(build): support optional system libnghttp2 linking#9

Merged
littledivy merged 2 commits into
mainfrom
orch/divybot-488
Jun 5, 2026
Merged

feat(build): support optional system libnghttp2 linking#9
littledivy merged 2 commits into
mainfrom
orch/divybot-488

Conversation

@divybot

@divybot divybot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds opt-in support for linking against a system libnghttp2 (discovered via
pkg-config) while keeping the bundled static build as the default and
fallback
. This is the packaging/linking support requested in #7 and the
native-library metadata requested in #8.

What changed

  • links = "nghttp2" in Cargo.toml — Cargo now enforces a single
    native-library version across the dependency graph and exposes
    DEP_NGHTTP2_ROOT / DEP_NGHTTP2_INCLUDE to downstream build scripts.
  • Opt-in system linking, two equivalent triggers:
    • a system Cargo feature, or
    • the LIBNGHTTP2_SYS_USE_PKG_CONFIG=1 environment variable (no source
      changes needed — handy for distro packagers).
  • Both paths fall back to the bundled build with a cargo:warning when no
    suitable system library is found, so the default behavior is unchanged.
  • When the system library is used, bindings are regenerated against the system
    headers via the pkg-config include paths (bindgen config is shared between
    both paths).
  • CI: new system-link job installs libnghttp2-dev, builds with
    --features system, and asserts via ldd that the test binary is
    dynamically linked against the system libnghttp2.so.
  • README documents the linking options.

Verification

Locally (macOS, brew install pkg-config nghttp2):

  • Default cargo test → builds bundled, 16/16 tests pass.
  • LIBNGHTTP2_SYS_USE_PKG_CONFIG=1 cargo test and cargo test --features system
    → 16/16 pass; otool -L confirms the binary links
    /opt/homebrew/opt/libnghttp2/lib/libnghttp2.14.dylib.
  • System requested but unavailable (PKG_CONFIG_LIBDIR pointed 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

divybot and others added 2 commits June 5, 2026 14:38
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 littledivy merged commit b5e8133 into main Jun 5, 2026
8 checks passed
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.

Add links = "nghttp2" to Cargo.toml Add support for linking against system libnghttp2

2 participants