@@ -40,6 +40,7 @@ fn main() {
4040 "OUT_DIR" ,
4141 "RUSTY_V8_ARCHIVE" ,
4242 "RUSTY_V8_MIRROR" ,
43+ "RUSTY_V8_REUSE_PREBUILT" ,
4344 "RUSTY_V8_SRC_BINDING_PATH" ,
4445 "SCCACHE" ,
4546 "V8_FORCE_DEBUG" ,
@@ -717,7 +718,20 @@ fn download_static_lib_binaries() {
717718 fs:: create_dir_all ( & dir) . unwrap ( ) ;
718719 println ! ( "cargo:rustc-link-search={}" , dir. display( ) ) ;
719720
720- download_file ( & url, & static_lib_path ( ) ) ;
721+ let lib_path = static_lib_path ( ) ;
722+
723+ // If RUSTY_V8_REUSE_PREBUILT is set and the library already exists,
724+ // skip the download. This is useful when only Rust code changed but
725+ // V8 itself hasn't changed (e.g., version bump without V8 update).
726+ if env:: var ( "RUSTY_V8_REUSE_PREBUILT" ) . is_ok ( ) && lib_path. exists ( ) {
727+ println ! (
728+ "cargo:warning=Reusing existing prebuilt V8 library at {}" ,
729+ lib_path. display( )
730+ ) ;
731+ return ;
732+ }
733+
734+ download_file ( & url, & lib_path) ;
721735}
722736
723737fn decompress_to_writer < R , W > ( input : & mut R , output : & mut W ) -> io:: Result < ( ) >
@@ -855,6 +869,37 @@ fn print_prebuilt_src_binding_path() {
855869
856870 let src_binding_path = get_dirs ( ) . root . join ( "gen" ) . join ( name. clone ( ) ) ;
857871
872+ // If RUSTY_V8_REUSE_PREBUILT is set, look for any existing binding file
873+ // in the gen directory (ignoring version in path).
874+ if env:: var ( "RUSTY_V8_REUSE_PREBUILT" ) . is_ok ( ) {
875+ let gen_dir = get_dirs ( ) . root . join ( "gen" ) ;
876+
877+ if let Ok ( entries) = fs:: read_dir ( & gen_dir) {
878+ for entry in entries. flatten ( ) {
879+ let path = entry. path ( ) ;
880+
881+ if let Some ( filename) = path. file_name ( ) . and_then ( |f| f. to_str ( ) ) {
882+ // Match pattern: src_binding{features}_{profile}_{target}.rs
883+ if filename. starts_with ( "src_binding" )
884+ && filename. ends_with ( ".rs" )
885+ && filename. contains ( & format ! ( "_{profile}_" ) )
886+ && filename. contains ( & target)
887+ {
888+ println ! (
889+ "cargo:warning=Reusing existing binding file at {}" ,
890+ path. display( )
891+ ) ;
892+ println ! (
893+ "cargo:rustc-env=RUSTY_V8_SRC_BINDING_PATH={}" ,
894+ path. display( )
895+ ) ;
896+ return ;
897+ }
898+ }
899+ }
900+ }
901+ }
902+
858903 if let Ok ( base) = env:: var ( "RUSTY_V8_MIRROR" ) {
859904 let version = env:: var ( "CARGO_PKG_VERSION" ) . unwrap ( ) ;
860905 let url = format ! ( "{base}/v{version}/{name}" ) ;
0 commit comments