@@ -26,6 +26,7 @@ const NGX_CONF_FEATURES: &[&str] = &[
2626 "have_file_aio" ,
2727 "have_kqueue" ,
2828 "have_variadic_macros" ,
29+ "http" ,
2930 "http_cache" ,
3031 "http_dav" ,
3132 "http_gzip" ,
@@ -40,6 +41,7 @@ const NGX_CONF_FEATURES: &[&str] = &[
4041 "pcre2" ,
4142 "quic" ,
4243 "ssl" ,
44+ "stream" ,
4345 "stream_ssl" ,
4446 "stream_upstream_zone" ,
4547 "threads" ,
@@ -328,17 +330,26 @@ pub fn print_cargo_metadata<T: AsRef<Path>>(includes: &[T]) -> Result<(), Box<dy
328330 ) ;
329331
330332 // A quoted list of all recognized features to be passed to rustc-check-cfg.
333+ let values = NGX_CONF_FEATURES . join ( "\" ,\" " ) ;
334+ println ! ( "cargo::metadata=features_check=\" {}\" " , values) ;
331335 println ! (
332- "cargo::metadata=features_check= \" {}\" " ,
333- NGX_CONF_FEATURES . join ( " \" , \" " )
336+ "cargo::rustc-check-cfg=cfg(ngx_feature, values( \" {}\" )) " ,
337+ values
334338 ) ;
339+
335340 // A list of features enabled in the nginx build we're using
336341 println ! ( "cargo::metadata=features={}" , ngx_features. join( "," ) ) ;
342+ for feature in ngx_features {
343+ println ! ( "cargo::rustc-cfg=ngx_feature=\" {}\" " , feature) ;
344+ }
337345
338346 // A quoted list of all recognized operating systems to be passed to rustc-check-cfg.
339- println ! ( "cargo::metadata=os_check=\" {}\" " , NGX_CONF_OS . join( "\" ,\" " ) ) ;
347+ let values = NGX_CONF_OS . join ( "\" ,\" " ) ;
348+ println ! ( "cargo::metadata=os_check=\" {}\" " , values) ;
349+ println ! ( "cargo::rustc-check-cfg=cfg(ngx_os, values(\" {}\" ))" , values) ;
340350 // Current detected operating system
341351 println ! ( "cargo::metadata=os={ngx_os}" ) ;
352+ println ! ( "cargo::rustc-cfg=ngx_os=\" {ngx_os}\" " ) ;
342353
343354 Ok ( ( ) )
344355}
@@ -353,6 +364,22 @@ fn expand_definitions<T: AsRef<Path>>(includes: &[T]) -> Result<Vec<u8>, Box<dyn
353364#include <ngx_config.h>
354365#include <ngx_core.h>
355366
367+ /* C23 or Clang/GCC/MSVC >= 15.3 extension */
368+ #if defined(__has_include)
369+
370+ #if __has_include(<ngx_http.h>)
371+ RUST_CONF_HTTP=1
372+ #endif
373+
374+ #if __has_include(<ngx_stream.h>)
375+ RUST_CONF_STREAM=1
376+ #endif
377+
378+ #else
379+ /* fallback */
380+ RUST_CONF_HTTP=1
381+ #endif
382+
356383RUST_CONF_NGINX_BUILD=NGINX_VER_BUILD
357384RUST_CONF_NGINX_VERSION=NGINX_VER
358385RUST_CONF_NGINX_VERSION_NUMBER=nginx_version
0 commit comments