@@ -56,31 +56,41 @@ fn main() {
56
56
build_bundled ( & out_dir, & out_path) ;
57
57
}
58
58
59
- #[ cfg( target_os = "windows" ) ]
60
- fn copy_with_cp ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
61
- fs:: copy ( src, dst) ?; // do a regular file copy on Windows
59
+ fn copy_dir_all ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
60
+ let dst = dst. as_ref ( ) ;
61
+ fs:: create_dir_all ( dst) ?;
62
+ for entry in fs:: read_dir ( src) ? {
63
+ let entry = entry?;
64
+ let ty = entry. file_type ( ) ?;
65
+ if ty. is_dir ( ) {
66
+ copy_dir_all ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
67
+ } else {
68
+ fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
69
+ }
70
+ }
62
71
Ok ( ( ) )
63
72
}
64
73
65
74
/// This ensures that in sandboxed environments, such as Nix, permissions from other sources don't
66
75
/// propagate into OUT_DIR. If not present, when trying to rewrite a file, a `Permission denied`
67
76
/// error will occur.
68
- fn copy_with_cp ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
77
+ fn copy_with_cp ( from : impl AsRef < Path > , to : impl AsRef < Path > ) -> io:: Result < ( ) > {
69
78
let status = Command :: new ( "cp" )
70
79
. arg ( "--no-preserve=mode,ownership" )
71
80
. arg ( "-R" )
72
- . arg ( src . as_ref ( ) . to_str ( ) . unwrap ( ) )
73
- . arg ( dst . as_ref ( ) . to_str ( ) . unwrap ( ) )
81
+ . arg ( from . as_ref ( ) . to_str ( ) . unwrap ( ) )
82
+ . arg ( to . as_ref ( ) . to_str ( ) . unwrap ( ) )
74
83
. status ( ) ?;
75
84
76
- if !status. success ( ) {
77
- Err ( io:: Error :: new (
78
- io:: ErrorKind :: Other ,
79
- "Failed to copy using cp" ,
80
- ) )
81
- } else {
82
- Ok ( ( ) )
85
+ if status. success ( ) {
86
+ return Ok ( ( ) ) ;
83
87
}
88
+
89
+ return match fs:: copy ( from. as_ref ( ) , to. as_ref ( ) ) {
90
+ Err ( err) if err. kind ( ) == io:: ErrorKind :: InvalidInput => copy_dir_all ( from, to) ,
91
+ Ok ( _) => Ok ( ( ) ) ,
92
+ Err ( err) => Err ( err) ,
93
+ } ;
84
94
}
85
95
86
96
fn make_amalgamation ( ) {
@@ -97,6 +107,7 @@ fn make_amalgamation() {
97
107
. env ( "CFLAGS" , flags. join ( " " ) )
98
108
. output ( )
99
109
. unwrap ( ) ;
110
+
100
111
Command :: new ( "make" )
101
112
. current_dir ( SQLITE_DIR )
102
113
. output ( )
@@ -107,6 +118,7 @@ fn make_amalgamation() {
107
118
( BUNDLED_DIR . as_ref ( ) as & Path ) . join ( "src/sqlite3.c" ) ,
108
119
)
109
120
. unwrap ( ) ;
121
+
110
122
copy_with_cp (
111
123
( SQLITE_DIR . as_ref ( ) as & Path ) . join ( "sqlite3.h" ) ,
112
124
( BUNDLED_DIR . as_ref ( ) as & Path ) . join ( "src/sqlite3.h" ) ,
@@ -298,32 +310,31 @@ fn build_multiple_ciphers(target: &str, out_path: &Path) {
298
310
} else {
299
311
"bundled/bindings/bindgen.rs"
300
312
} ;
313
+
301
314
if std:: env:: var ( "LIBSQL_DEV" ) . is_ok ( ) {
302
315
let header = HeaderLocation :: FromPath ( format ! ( "{BUNDLED_DIR}/src/sqlite3.h" ) ) ;
303
316
bindings:: write_to_out_dir ( header, bindgen_rs_path. as_ref ( ) ) ;
304
317
}
318
+
305
319
let dir = env ! ( "CARGO_MANIFEST_DIR" ) ;
306
320
copy_with_cp ( format ! ( "{dir}/{bindgen_rs_path}" ) , out_path) . unwrap ( ) ;
307
321
322
+ let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
323
+
308
324
copy_with_cp (
309
- ( BUNDLED_DIR . as_ref ( ) as & Path )
310
- . join ( "src" )
311
- . join ( "sqlite3.c" ) ,
312
- ( BUNDLED_DIR . as_ref ( ) as & Path )
313
- . join ( "SQLite3MultipleCiphers" )
314
- . join ( "src" )
315
- . join ( "sqlite3.c" ) ,
325
+ dbg ! ( format!( "{BUNDLED_DIR}/SQLite3MultipleCiphers" ) ) ,
326
+ format ! ( "{out_dir}/sqlite3mc" ) ,
316
327
)
317
328
. unwrap ( ) ;
318
329
319
- let bundled_dir = env:: current_dir ( )
320
- . unwrap ( )
321
- . join ( BUNDLED_DIR )
322
- . join ( "SQLite3MultipleCiphers" ) ;
323
- let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
330
+ copy_with_cp (
331
+ PathBuf :: from ( BUNDLED_DIR ) . join ( "src" ) . join ( "sqlite3.c" ) ,
332
+ format ! ( "{out_dir}/sqlite3mc/src/sqlite3.c" ) ,
333
+ )
334
+ . unwrap ( ) ;
335
+
336
+ let bundled_dir = format ! ( "{out_dir}/sqlite3mc" ) ;
324
337
let sqlite3mc_build_dir = env:: current_dir ( ) . unwrap ( ) . join ( out_dir) . join ( "sqlite3mc" ) ;
325
- let _ = fs:: remove_dir_all ( sqlite3mc_build_dir. clone ( ) ) ;
326
- fs:: create_dir_all ( sqlite3mc_build_dir. clone ( ) ) . unwrap ( ) ;
327
338
328
339
let mut cmake_opts: Vec < & str > = vec ! [ ] ;
329
340
0 commit comments