diff --git a/nginx-sys/build/main.rs b/nginx-sys/build/main.rs index a60be7f..b287c1c 100644 --- a/nginx-sys/build/main.rs +++ b/nginx-sys/build/main.rs @@ -26,6 +26,7 @@ const NGX_CONF_FEATURES: &[&str] = &[ "have_file_aio", "have_kqueue", "have_variadic_macros", + "http", "http_cache", "http_dav", "http_gzip", @@ -40,6 +41,7 @@ const NGX_CONF_FEATURES: &[&str] = &[ "pcre2", "quic", "ssl", + "stream", "stream_ssl", "stream_upstream_zone", "threads", @@ -328,17 +330,26 @@ pub fn print_cargo_metadata>(includes: &[T]) -> Result<(), Box>(includes: &[T]) -> Result, Box #include +/* C23 or Clang/GCC/MSVC >= 15.3 extension */ +#if defined(__has_include) + +#if __has_include() +RUST_CONF_HTTP=1 +#endif + +#if __has_include() +RUST_CONF_STREAM=1 +#endif + +#else +/* fallback */ +RUST_CONF_HTTP=1 +#endif + RUST_CONF_NGINX_BUILD=NGINX_VER_BUILD RUST_CONF_NGINX_VERSION=NGINX_VER RUST_CONF_NGINX_VERSION_NUMBER=nginx_version diff --git a/nginx-sys/build/wrapper.h b/nginx-sys/build/wrapper.h index daaf38d..c333744 100644 --- a/nginx-sys/build/wrapper.h +++ b/nginx-sys/build/wrapper.h @@ -1,8 +1,23 @@ -#include -#include #include #include +/* __has_include was a compiler-specific extension until C23, + * but it's safe to assume that bindgen supports it via libclang. + */ +#if defined(__has_include) + +#if __has_include() +#include +#endif + +#if __has_include() +#include +#endif + +#else +#include +#endif + const char *NGX_RS_MODULE_SIGNATURE = NGX_MODULE_SIGNATURE; // `--prefix=` results in not emitting the declaration diff --git a/nginx-sys/src/http.rs b/nginx-sys/src/http.rs new file mode 100644 index 0000000..435cc79 --- /dev/null +++ b/nginx-sys/src/http.rs @@ -0,0 +1,18 @@ +use core::mem::offset_of; + +use crate::bindings::ngx_http_conf_ctx_t; + +/// The offset of the `main_conf` field in the `ngx_http_conf_ctx_t` struct. +/// +/// This is used to access the main configuration context for an HTTP module. +pub const NGX_HTTP_MAIN_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, main_conf); + +/// The offset of the `srv_conf` field in the `ngx_http_conf_ctx_t` struct. +/// +/// This is used to access the server configuration context for an HTTP module. +pub const NGX_HTTP_SRV_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, srv_conf); + +/// The offset of the `loc_conf` field in the `ngx_http_conf_ctx_t` struct. +/// +/// This is used to access the location configuration context for an HTTP module. +pub const NGX_HTTP_LOC_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, loc_conf); diff --git a/nginx-sys/src/lib.rs b/nginx-sys/src/lib.rs index ce9064b..8088ea7 100644 --- a/nginx-sys/src/lib.rs +++ b/nginx-sys/src/lib.rs @@ -3,10 +3,13 @@ #![no_std] mod event; +#[cfg(ngx_feature = "http")] +mod http; mod queue; +#[cfg(ngx_feature = "stream")] +mod stream; use core::fmt; -use core::mem::offset_of; use core::ptr::{self, copy_nonoverlapping}; use core::slice; @@ -25,22 +28,11 @@ mod bindings { #[doc(no_inline)] pub use bindings::*; pub use event::*; +#[cfg(ngx_feature = "http")] +pub use http::*; pub use queue::*; - -/// The offset of the `main_conf` field in the `ngx_http_conf_ctx_t` struct. -/// -/// This is used to access the main configuration context for an HTTP module. -pub const NGX_HTTP_MAIN_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, main_conf); - -/// The offset of the `srv_conf` field in the `ngx_http_conf_ctx_t` struct. -/// -/// This is used to access the server configuration context for an HTTP module. -pub const NGX_HTTP_SRV_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, srv_conf); - -/// The offset of the `loc_conf` field in the `ngx_http_conf_ctx_t` struct. -/// -/// This is used to access the location configuration context for an HTTP module. -pub const NGX_HTTP_LOC_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, loc_conf); +#[cfg(ngx_feature = "stream")] +pub use stream::*; /// Convert a byte slice to a raw pointer (`*mut u_char`) allocated in the given nginx memory pool. /// diff --git a/nginx-sys/src/stream.rs b/nginx-sys/src/stream.rs new file mode 100644 index 0000000..6288fd4 --- /dev/null +++ b/nginx-sys/src/stream.rs @@ -0,0 +1,13 @@ +use core::mem::offset_of; + +use crate::bindings::ngx_stream_conf_ctx_t; + +/// The offset of the `main_conf` field in the `ngx_stream_conf_ctx_t` struct. +/// +/// This is used to access the main configuration context for a STREAM module. +pub const NGX_STREAM_MAIN_CONF_OFFSET: usize = offset_of!(ngx_stream_conf_ctx_t, main_conf); + +/// The offset of the `srv_conf` field in the `ngx_stream_conf_ctx_t` struct. +/// +/// This is used to access the server configuration context for a STREAM module. +pub const NGX_STREAM_SRV_CONF_OFFSET: usize = offset_of!(ngx_stream_conf_ctx_t, srv_conf);