@@ -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" ,
@@ -336,17 +338,26 @@ pub fn print_cargo_metadata<T: AsRef<Path>>(includes: &[T]) -> Result<(), Box<dy
336338 ) ;
337339
338340 // A quoted list of all recognized features to be passed to rustc-check-cfg.
341+ let values = NGX_CONF_FEATURES . join ( "\" ,\" " ) ;
342+ println ! ( "cargo::metadata=features_check=\" {}\" " , values) ;
339343 println ! (
340- "cargo::metadata=features_check= \" {}\" " ,
341- NGX_CONF_FEATURES . join ( " \" , \" " )
344+ "cargo::rustc-check-cfg=cfg(ngx_feature, values( \" {}\" )) " ,
345+ values
342346 ) ;
347+
343348 // A list of features enabled in the nginx build we're using
344349 println ! ( "cargo::metadata=features={}" , ngx_features. join( "," ) ) ;
350+ for feature in ngx_features {
351+ println ! ( "cargo::rustc-cfg=ngx_feature=\" {}\" " , feature) ;
352+ }
345353
346354 // A quoted list of all recognized operating systems to be passed to rustc-check-cfg.
347- println ! ( "cargo::metadata=os_check=\" {}\" " , NGX_CONF_OS . join( "\" ,\" " ) ) ;
355+ let values = NGX_CONF_OS . join ( "\" ,\" " ) ;
356+ println ! ( "cargo::metadata=os_check=\" {}\" " , values) ;
357+ println ! ( "cargo::rustc-check-cfg=cfg(ngx_os, values(\" {}\" ))" , values) ;
348358 // Current detected operating system
349359 println ! ( "cargo::metadata=os={ngx_os}" ) ;
360+ println ! ( "cargo::rustc-cfg=ngx_os=\" {ngx_os}\" " ) ;
350361
351362 Ok ( ( ) )
352363}
@@ -361,6 +372,22 @@ fn expand_definitions<T: AsRef<Path>>(includes: &[T]) -> Result<Vec<u8>, Box<dyn
361372#include <ngx_config.h>
362373#include <ngx_core.h>
363374
375+ /* C23 or Clang/GCC/MSVC >= 15.3 extension */
376+ #if defined(__has_include)
377+
378+ #if __has_include(<ngx_http.h>)
379+ RUST_CONF_HTTP=1
380+ #endif
381+
382+ #if __has_include(<ngx_stream.h>)
383+ RUST_CONF_STREAM=1
384+ #endif
385+
386+ #else
387+ /* fallback */
388+ RUST_CONF_HTTP=1
389+ #endif
390+
364391RUST_CONF_NGINX_BUILD=NGINX_VER_BUILD
365392RUST_CONF_NGINX_VERSION=NGINX_VER
366393RUST_CONF_NGINX_VERSION_NUMBER=nginx_version
0 commit comments