@@ -94,12 +94,13 @@ const NGX_LINUX_ADDITIONAL_OPTS: [&str; 3] = [
9494 "--with-cc-opt=-g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC" ,
9595 "--with-ld-opt=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie" ,
9696] ;
97- const ENV_VARS_TRIGGERING_RECOMPILE : [ & str ; 9 ] = [
97+ const ENV_VARS_TRIGGERING_RECOMPILE : [ & str ; 10 ] = [
9898 "DEBUG" ,
9999 "OUT_DIR" ,
100100 "ZLIB_VERSION" ,
101101 "PCRE2_VERSION" ,
102102 "OPENSSL_VERSION" ,
103+ "NGX_OBJS" ,
103104 "NGX_VERSION" ,
104105 "CARGO_CFG_TARGET_OS" ,
105106 "CARGO_MANIFEST_DIR" ,
@@ -111,33 +112,39 @@ const ENV_VARS_TRIGGERING_RECOMPILE: [&str; 9] = [
111112/// extract them, execute autoconf `configure` for NGINX, compile NGINX and finally install
112113/// NGINX in a subdirectory with the project.
113114fn main ( ) -> Result < ( ) , Box < dyn StdError > > {
114- println ! ( "Building NGINX" ) ;
115- // Create .cache directory
116- let cache_dir = make_cache_dir ( ) ?;
117- println ! ( "Cache directory created" ) ;
118- // Import GPG keys used to verify dependency tarballs
119- import_gpg_keys ( & cache_dir) ?;
120- println ! ( "GPG keys imported" ) ;
121- // Ensure GPG directory has the correct permissions
122- ensure_gpg_permissions ( & cache_dir) ?;
123- println ! ( "Verified GPG permissions" ) ;
124- // Configure and Compile NGINX
125- let ( _nginx_install_dir, nginx_src_dir) = compile_nginx ( ) ?;
115+ let nginx_objs_dir = if let Ok ( v) = env:: var ( "NGX_OBJS" ) {
116+ PathBuf :: from ( v) . canonicalize ( ) ?
117+ } else {
118+ println ! ( "Building NGINX" ) ;
119+ // Create .cache directory
120+ let cache_dir = make_cache_dir ( ) ?;
121+ println ! ( "Cache directory created" ) ;
122+ // Import GPG keys used to verify dependency tarballs
123+ import_gpg_keys ( & cache_dir) ?;
124+ println ! ( "GPG keys imported" ) ;
125+ // Ensure GPG directory has the correct permissions
126+ ensure_gpg_permissions ( & cache_dir) ?;
127+ println ! ( "Verified GPG permissions" ) ;
128+ // Configure and Compile NGINX
129+ let ( _nginx_install_dir, nginx_src_dir) = compile_nginx ( ) ?;
130+ nginx_src_dir. join ( "objs" )
131+ } ;
126132 // Hint cargo to rebuild if any of the these environment variables values change
127133 // because they will trigger a recompilation of NGINX with different parameters
128134 for var in ENV_VARS_TRIGGERING_RECOMPILE {
129135 println ! ( "cargo:rerun-if-env-changed={var}" ) ;
130136 }
131137 println ! ( "cargo:rerun-if-changed=build.rs" ) ;
132138 println ! ( "cargo:rerun-if-changed=wrapper.h" ) ;
139+ println ! ( "cargo:rerun-if-changed={}/Makefile" , nginx_objs_dir. to_string_lossy( ) ) ;
133140 // Read autoconf generated makefile for NGINX and generate Rust bindings based on its includes
134- generate_binding ( nginx_src_dir ) ;
141+ generate_binding ( nginx_objs_dir ) ;
135142 Ok ( ( ) )
136143}
137144
138145/// Generates Rust bindings for NGINX
139- fn generate_binding ( nginx_source_dir : PathBuf ) {
140- let autoconf_makefile_path = nginx_source_dir . join ( "objs" ) . join ( "Makefile" ) ;
146+ fn generate_binding ( nginx_objs_dir : PathBuf ) {
147+ let autoconf_makefile_path = nginx_objs_dir . join ( "Makefile" ) ;
141148 let clang_args: Vec < String > = parse_includes_from_makefile ( & autoconf_makefile_path)
142149 . into_iter ( )
143150 . map ( |path| format ! ( "-I{}" , path. to_string_lossy( ) ) )
0 commit comments