@@ -12,6 +12,7 @@ use std::env;
1212use std:: fs;
1313use std:: fs:: OpenOptions ;
1414use std:: io:: { ErrorKind , Read } ;
15+ use std:: path:: Path ;
1516use std:: path:: PathBuf ;
1617use std:: process:: Command ;
1718
@@ -95,7 +96,7 @@ fn run(cmd: &mut Command, program: &str) {
9596 }
9697}
9798
98- fn read_file ( file_name : & std:: path:: PathBuf ) -> String {
99+ fn read_file ( file_name : & std:: path:: Path ) -> String {
99100 let file_path = file_name. to_str ( ) . unwrap ( ) ;
100101 let options = OpenOptions :: new ( )
101102 . read ( true )
@@ -115,7 +116,7 @@ fn read_file(file_name: &std::path::PathBuf) -> String {
115116 }
116117}
117118
118- fn read_conf ( conf_file : & std:: path:: PathBuf ) -> Config {
119+ fn read_conf ( conf_file : & std:: path:: Path ) -> Config {
119120 let raw_conf = read_file ( conf_file) ;
120121 let decoded: Config = serde_json:: from_str ( & raw_conf) . unwrap ( ) ;
121122 decoded
@@ -198,7 +199,7 @@ fn prep_cmake_options(conf: &Config) -> Vec<String> {
198199}
199200
200201#[ cfg( windows) ]
201- fn run_cmake_command ( conf : & Config , build_dir : & std:: path:: PathBuf ) {
202+ fn run_cmake_command ( conf : & Config , build_dir : & std:: path:: Path ) {
202203 let _ = fs:: create_dir ( & build_dir) ;
203204
204205 let options = prep_cmake_options ( conf) ;
@@ -243,7 +244,7 @@ fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) {
243244}
244245
245246#[ cfg( not( windows) ) ]
246- fn run_cmake_command ( conf : & Config , build_dir : & std:: path:: PathBuf ) {
247+ fn run_cmake_command ( conf : & Config , build_dir : & std:: path:: Path ) {
247248 let _ = fs:: create_dir ( & build_dir) ;
248249
249250 let options = prep_cmake_options ( conf) ;
@@ -282,7 +283,7 @@ fn backend_exists(name: &str) -> bool {
282283 file_exists ( & win_backend) || file_exists ( & osx_backend) || file_exists ( & linux_backend)
283284}
284285
285- fn blob_backends ( conf : & Config , build_dir : & std:: path:: PathBuf ) -> ( Vec < String > , Vec < String > ) {
286+ fn blob_backends ( conf : & Config , build_dir : & std:: path:: Path ) -> ( Vec < String > , Vec < String > ) {
286287 let mut backend_dirs: Vec < String > = Vec :: new ( ) ;
287288 let mut backends: Vec < String > = Vec :: new ( ) ;
288289
@@ -338,7 +339,7 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
338339 let mut ocl_lib_exists = false ;
339340
340341 for backend_dir in backend_dirs. iter ( ) {
341- let lib_dir = PathBuf :: from ( backend_dir) ;
342+ let lib_dir = Path :: new ( backend_dir) ;
342343
343344 let culib_name = if cfg ! ( windows) {
344345 WIN_CUDA_LIB
@@ -429,7 +430,14 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
429430
430431fn main ( ) {
431432 // Setup pathing
432- let src = PathBuf :: from ( & env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
433+ let cargo_manifest_dir = match env:: var ( "CARGO_MANIFEST_DIR" ) {
434+ Ok ( dir_path) => dir_path,
435+ Err ( error) => panic ! (
436+ "CARGO_MANIFEST_DIR environment variable is not available: {}" ,
437+ error
438+ ) ,
439+ } ;
440+ let src = Path :: new ( & cargo_manifest_dir) ;
433441 let conf_file = src. join ( "build.conf" ) ;
434442 let conf = read_conf ( & conf_file) ;
435443
0 commit comments