1
1
use std:: env;
2
2
use std:: ffi:: OsString ;
3
3
use std:: fs:: { self , OpenOptions } ;
4
- use std:: io:: Write ;
4
+ use std:: io:: { self , Write } ;
5
5
use std:: path:: { Path , PathBuf } ;
6
6
use std:: process:: Command ;
7
7
@@ -39,13 +39,8 @@ fn main() {
39
39
40
40
let dir = env ! ( "CARGO_MANIFEST_DIR" ) ;
41
41
42
- Command :: new ( "cp" )
43
- . arg ( "--no-preserve=mode,ownership" )
44
- . arg ( "-R" )
45
- . arg ( format ! ( "{dir}/{bindgen_rs_path}" ) )
46
- . arg ( & out_path)
47
- . output ( )
48
- . unwrap ( ) ;
42
+ let full_src_path = Path :: new ( dir) . join ( bindgen_rs_path) ;
43
+ copy_with_cp ( full_src_path, & out_path) . unwrap ( ) ;
49
44
50
45
println ! ( "cargo:lib_dir={out_dir}" ) ;
51
46
@@ -61,6 +56,49 @@ fn main() {
61
56
build_bundled ( & out_dir, & out_path) ;
62
57
}
63
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
62
+ Ok ( ( ) )
63
+ }
64
+
65
+ #[ cfg( target_os = "linux" ) ]
66
+ fn copy_with_cp ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
67
+ let status = Command :: new ( "cp" )
68
+ . arg ( "--no-preserve=mode,ownership" )
69
+ . arg ( "-R" )
70
+ . arg ( src. as_ref ( ) . to_str ( ) . unwrap ( ) )
71
+ . arg ( dst. as_ref ( ) . to_str ( ) . unwrap ( ) )
72
+ . status ( ) ?;
73
+
74
+ if !status. success ( ) {
75
+ Err ( io:: Error :: new (
76
+ io:: ErrorKind :: Other ,
77
+ "Failed to copy using cp" ,
78
+ ) )
79
+ } else {
80
+ Ok ( ( ) )
81
+ }
82
+ }
83
+
84
+ #[ cfg( target_os = "macos" ) ]
85
+ fn copy_with_cp ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
86
+ let status = Command :: new ( "cp" )
87
+ . arg ( "-R" )
88
+ . arg ( src. as_ref ( ) . to_str ( ) . unwrap ( ) )
89
+ . arg ( dst. as_ref ( ) . to_str ( ) . unwrap ( ) )
90
+ . status ( ) ?;
91
+
92
+ if !status. success ( ) {
93
+ Err ( io:: Error :: new (
94
+ io:: ErrorKind :: Other ,
95
+ "Failed to copy using cp" ,
96
+ ) )
97
+ } else {
98
+ Ok ( ( ) )
99
+ }
100
+ }
101
+
64
102
fn make_amalgamation ( ) {
65
103
let flags = [ "-DSQLITE_ENABLE_COLUMN_METADATA=1" ] ;
66
104
0 commit comments