@@ -53,12 +53,40 @@ fn main() {
5353 // verification (manifest_dir is inside target/package/ in that case).
5454 let project_bins = Path :: new ( & manifest_dir) . join ( "generated-bins" ) ;
5555 if !manifest_dir. contains ( "target/package/" ) {
56- let _ = std:: fs:: create_dir_all ( & project_bins) ;
57- if let Ok ( entries) = std:: fs:: read_dir ( & build_output_dir) {
58- for entry in entries. flatten ( ) {
59- let dest = project_bins. join ( entry. file_name ( ) ) ;
60- let _ = std:: fs:: copy ( entry. path ( ) , dest) ;
56+ // Prefer a symlink to avoid copying large prover binaries on every build.
57+ // If symlink creation fails (e.g. on filesystems without symlink support),
58+ // fall back to copying and surface errors.
59+ #[ cfg( unix) ]
60+ {
61+ use std:: os:: unix:: fs:: symlink;
62+ // Remove any existing dir/file/symlink at destination.
63+ if let Ok ( meta) = std:: fs:: symlink_metadata ( & project_bins) {
64+ if meta. is_dir ( ) {
65+ std:: fs:: remove_dir_all ( & project_bins)
66+ . expect ( "Failed to remove existing generated-bins directory" ) ;
67+ } else {
68+ std:: fs:: remove_file ( & project_bins)
69+ . expect ( "Failed to remove existing generated-bins file/symlink" ) ;
70+ }
6171 }
72+ if let Err ( e) = symlink ( & build_output_dir, & project_bins) {
73+ println ! (
74+ "cargo:warning=[quantus-cli] Failed to symlink generated-bins ({}). Falling back to copy..." ,
75+ e
76+ ) ;
77+ } else {
78+ // Symlink created successfully; we're done.
79+ return ;
80+ }
81+ }
82+
83+ std:: fs:: create_dir_all ( & project_bins) . expect ( "Failed to create generated-bins directory" ) ;
84+ let entries = std:: fs:: read_dir ( & build_output_dir)
85+ . expect ( "Failed to read generated-bins directory in OUT_DIR" ) ;
86+ for entry in entries {
87+ let entry = entry. expect ( "Failed to read generated-bins entry" ) ;
88+ let dest = project_bins. join ( entry. file_name ( ) ) ;
89+ std:: fs:: copy ( entry. path ( ) , dest) . expect ( "Failed to copy generated-bins file" ) ;
6290 }
6391 }
6492}
0 commit comments