@@ -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" ,
@@ -295,14 +297,23 @@ pub fn print_cargo_metadata<T: AsRef<Path>>(includes: &[T]) -> Result<(), Box<dy
295297 ) ;
296298
297299 // A quoted list of all recognized features to be passed to rustc-check-cfg.
298- println ! ( "cargo::metadata=features_check=\" {}\" " , NGX_CONF_FEATURES . join( "\" ,\" " ) ) ;
300+ let values = NGX_CONF_FEATURES . join ( "\" ,\" " ) ;
301+ println ! ( "cargo::metadata=features_check=\" {}\" " , values) ;
302+ println ! ( "cargo::rustc-check-cfg=cfg(ngx_feature, values(\" {}\" ))" , values) ;
303+
299304 // A list of features enabled in the nginx build we're using
300305 println ! ( "cargo::metadata=features={}" , ngx_features. join( "," ) ) ;
306+ for feature in ngx_features {
307+ println ! ( "cargo::rustc-cfg=ngx_feature=\" {}\" " , feature) ;
308+ }
301309
302310 // A quoted list of all recognized operating systems to be passed to rustc-check-cfg.
303- println ! ( "cargo::metadata=os_check=\" {}\" " , NGX_CONF_OS . join( "\" ,\" " ) ) ;
311+ let values = NGX_CONF_OS . join ( "\" ,\" " ) ;
312+ println ! ( "cargo::metadata=os_check=\" {}\" " , values) ;
313+ println ! ( "cargo::rustc-check-cfg=cfg(ngx_os, values(\" {}\" ))" , values) ;
304314 // Current detected operating system
305315 println ! ( "cargo::metadata=os={ngx_os}" ) ;
316+ println ! ( "cargo::rustc-cfg=ngx_os=\" {ngx_os}\" " ) ;
306317
307318 Ok ( ( ) )
308319}
@@ -317,6 +328,22 @@ fn expand_definitions<T: AsRef<Path>>(includes: &[T]) -> Result<Vec<u8>, Box<dyn
317328#include <ngx_config.h>
318329#include <ngx_core.h>
319330
331+ /* C23 or Clang/GCC/MSVC >= 15.3 extension */
332+ #if defined(__has_include)
333+
334+ #if __has_include(<ngx_http.h>)
335+ RUST_CONF_HTTP=1
336+ #endif
337+
338+ #if __has_include(<ngx_stream.h>)
339+ RUST_CONF_STREAM=1
340+ #endif
341+
342+ #else
343+ /* fallback */
344+ RUST_CONF_HTTP=1
345+ #endif
346+
320347RUST_CONF_NGINX_BUILD=NGINX_VER_BUILD
321348RUST_CONF_NGINX_VERSION=NGINX_VER
322349RUST_CONF_NGINX_VERSION_NUMBER=nginx_version
0 commit comments