feat(sys)!: make HTTP and Stream bindings generation optional#271
Merged
Conversation
Generate bindings for ngx_http.h and ngx_stream.h only when requested via corresponding feature flags and supported in the build of NGINX. (HTTP is still enabled in the default feature set.) This allows following previously impossible scenarios: - building Core modules without HTTP dependency. - building Stream modules for NGINX configured with --without-http.
There was a problem hiding this comment.
Pull request overview
This PR makes generation and exposure of NGINX subsystem bindings (HTTP/Stream/Mail) conditional on both Cargo feature flags and the capabilities enabled in the target NGINX build, enabling builds that omit HTTP while still supporting Stream or Core-only modules.
Changes:
- Gate
nginx-sysHTTP/Stream modules behindfeature && ngx_featureand add optional Mail bindings behindmail. - Update bindgen wrapper/build logic to include
ngx_http.h/ngx_stream.h/ngx_mail.honly when the corresponding Cargo feature is enabled (and headers are available). - Expand detected/exported NGINX feature flags and enable Mail in vendored
nginx-srcdefault configure arguments.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/lib.rs |
Gate high-level ngx::http module on ngx_feature="http". |
nginx-sys/src/mail.rs |
Add Mail conf ctx field offset constants. |
nginx-sys/src/lib.rs |
Conditionally compile/re-export http/mail/stream modules using Cargo features + ngx_feature. |
nginx-sys/README.md |
Document new http (default), mail, stream feature flags and behavior. |
nginx-sys/Cargo.toml |
Define http default feature plus mail/stream features. |
nginx-sys/build/wrapper.h |
Feature-gate inclusion of module headers during bindgen. |
nginx-sys/build/main.rs |
Add more exported ngx_feature flags and define NGX_RS_FEATURE_* bindgen macros based on Cargo features. |
nginx-src/src/lib.rs |
Enable Mail modules in the default vendored configure args. |
examples/Cargo.toml |
Switch examples back to default nginx-sys features (HTTP enabled). |
Comments suppressed due to low confidence (1)
nginx-sys/build/main.rs:447
- In
expand_definitions(), the#else /* fallback */branch assumesRUST_CONF_HTTP=1but does not setRUST_CONF_MAILorRUST_CONF_STREAM. This becomes inconsistent now that Mail/Stream support is feature-detected via__has_include: on toolchains lacking__has_include, Mail/Stream will never be reported inDEP_NGINX_FEATURES, and HTTP may be reported even when headers aren’t available. Consider either (1) implementing a more accurate fallback for all three headers, or (2) removing the fallback and requiring__has_include(since the wrapper comment already assumes bindgen/libclang support).
/* C23 or Clang/GCC/MSVC >= 15.3 extension */
#if defined(__has_include)
#if __has_include(<ngx_http.h>)
RUST_CONF_HTTP=1
#endif
#if __has_include(<ngx_mail.h>)
RUST_CONF_MAIL=1
#endif
#if __has_include(<ngx_stream.h>)
RUST_CONF_STREAM=1
#endif
#else
/* fallback */
RUST_CONF_HTTP=1
#endif
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ensh63
approved these changes
Apr 3, 2026
The earliest version of libclang supported by bindgen is 9.0. "__has_include" was added many years before that (2.7.0?) and should be always available. Note the lack of a similar change in expand_definitions. We cannot make the same assumption about the system default CC.
ensh63
approved these changes
Apr 3, 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.
Generate bindings for ngx_http.h and ngx_stream.h only when requested via corresponding feature flags and supported in the build of NGINX. (HTTP is still enabled in the default feature set.)
This allows following previously impossible scenarios:
Also add Mail support and more ngx_feature flags.