Skip to content

feat(sys)!: make HTTP and Stream bindings generation optional#271

Merged
bavshin-f5 merged 4 commits into
nginx:mainfrom
bavshin-f5:conf-features
Apr 3, 2026
Merged

feat(sys)!: make HTTP and Stream bindings generation optional#271
bavshin-f5 merged 4 commits into
nginx:mainfrom
bavshin-f5:conf-features

Conversation

@bavshin-f5

Copy link
Copy Markdown
Member

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.

Also add Mail support and more ngx_feature flags.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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-sys HTTP/Stream modules behind feature && ngx_feature and add optional Mail bindings behind mail.
  • Update bindgen wrapper/build logic to include ngx_http.h/ngx_stream.h/ngx_mail.h only when the corresponding Cargo feature is enabled (and headers are available).
  • Expand detected/exported NGINX feature flags and enable Mail in vendored nginx-src default 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 assumes RUST_CONF_HTTP=1 but does not set RUST_CONF_MAIL or RUST_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 in DEP_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.

Comment thread nginx-sys/build/wrapper.h Outdated
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.
@bavshin-f5 bavshin-f5 merged commit 8cf2777 into nginx:main Apr 3, 2026
15 checks passed
@bavshin-f5 bavshin-f5 deleted the conf-features branch April 3, 2026 18:34
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.

3 participants