11use std:: env;
22use std:: ffi:: OsString ;
33use std:: fs:: { self , OpenOptions } ;
4- use std:: io:: Write ;
4+ use std:: io:: { self , Write } ;
55use std:: path:: { Path , PathBuf } ;
66use std:: process:: Command ;
77
@@ -39,13 +39,8 @@ fn main() {
3939
4040 let dir = env ! ( "CARGO_MANIFEST_DIR" ) ;
4141
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 ( ) ;
4944
5045 println ! ( "cargo:lib_dir={out_dir}" ) ;
5146
@@ -61,6 +56,49 @@ fn main() {
6156 build_bundled ( & out_dir, & out_path) ;
6257}
6358
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+
64102fn make_amalgamation ( ) {
65103 let flags = [ "-DSQLITE_ENABLE_COLUMN_METADATA=1" ] ;
66104
0 commit comments