| 
									
										
										
										
											2019-03-02 08:58:17 -08:00
										 |  |  | use std::env;
 | 
					
						
							|  |  |  | use std::fs;
 | 
					
						
							|  |  |  | use std::path::Path;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | fn main() {
 | 
					
						
							|  |  |  |     println!("cargo:rerun-if-changed=build.rs");
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-17 09:48:26 -07:00
										 |  |  |     if env::var("CARGO_FEATURE_CUDA").is_ok() {
 | 
					
						
							|  |  |  |         println!("cargo:rustc-cfg=cuda");
 | 
					
						
							| 
									
										
										
										
											2019-03-02 08:58:17 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-17 09:48:26 -07:00
										 |  |  |         let perf_libs_dir = {
 | 
					
						
							|  |  |  |             let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
 | 
					
						
							|  |  |  |             let mut path = Path::new(&manifest_dir);
 | 
					
						
							|  |  |  |             path = path.parent().unwrap();
 | 
					
						
							| 
									
										
										
										
											2019-06-18 08:24:41 -07:00
										 |  |  |             let mut path = path.join(Path::new("target/perf-libs"));
 | 
					
						
							|  |  |  |             path.push(
 | 
					
						
							|  |  |  |                 env::var("SOLANA_PERF_LIBS_CUDA")
 | 
					
						
							|  |  |  |                     .unwrap_or_else(|err| panic!("SOLANA_PERF_LIBS_CUDA not defined: {}", err)),
 | 
					
						
							|  |  |  |             );
 | 
					
						
							|  |  |  |             path
 | 
					
						
							| 
									
										
										
										
											2019-06-17 09:48:26 -07:00
										 |  |  |         };
 | 
					
						
							|  |  |  |         let perf_libs_dir = perf_libs_dir.to_str().unwrap();
 | 
					
						
							| 
									
										
										
										
											2019-03-02 08:58:17 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 08:51:20 -07:00
										 |  |  |         // Ensure `perf_libs_dir` exists.  It's been observed that
 | 
					
						
							|  |  |  |         // a cargo:rerun-if-changed= directive with a non-existent
 | 
					
						
							|  |  |  |         // directory triggers a rebuild on every |cargo build| invocation
 | 
					
						
							|  |  |  |         fs::create_dir_all(&perf_libs_dir).unwrap_or_else(|err| {
 | 
					
						
							|  |  |  |             if err.kind() != std::io::ErrorKind::AlreadyExists {
 | 
					
						
							|  |  |  |                 panic!("Unable to create {}: {:?}", perf_libs_dir, err);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |         });
 | 
					
						
							| 
									
										
										
										
											2019-03-02 08:58:17 -08:00
										 |  |  |         println!("cargo:rerun-if-changed={}", perf_libs_dir);
 | 
					
						
							|  |  |  |         println!("cargo:rustc-link-search=native={}", perf_libs_dir);
 | 
					
						
							| 
									
										
										
										
											2019-06-18 08:24:41 -07:00
										 |  |  |         if cfg!(windows) {
 | 
					
						
							|  |  |  |             println!("cargo:rerun-if-changed={}/libcuda-crypt.dll", perf_libs_dir);
 | 
					
						
							|  |  |  |         } else if cfg!(target_os = "macos") {
 | 
					
						
							|  |  |  |             println!(
 | 
					
						
							|  |  |  |                 "cargo:rerun-if-changed={}/libcuda-crypt.dylib",
 | 
					
						
							|  |  |  |                 perf_libs_dir
 | 
					
						
							|  |  |  |             );
 | 
					
						
							|  |  |  |         } else {
 | 
					
						
							|  |  |  |             println!("cargo:rerun-if-changed={}/libcuda-crypt.so", perf_libs_dir);
 | 
					
						
							|  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2019-03-02 08:58:17 -08:00
										 |  |  |     }
 | 
					
						
							|  |  |  | }
 |