1#![cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
2pub fn setup_lib3delight() -> Result<(), Box<dyn std::error::Error>> {
19 #[cfg(feature = "download_lib3delight")]
20 #[allow(unused_variables)]
21 let lib_path = {
22 use std::{
23 fs::File,
24 io::Write,
25 path::{Path, PathBuf},
26 };
27
28 let lib_path = PathBuf::from(&std::env::var("OUT_DIR")?);
29
30 eprintln!("Building against 3Delight 2.9.30");
31
32 #[cfg(target_os = "windows")]
33 let lib = "https://www.dropbox.com/s/9iavkggor0ecc1x/3Delight.dll";
34 #[cfg(target_os = "macos")]
35 let lib = "https://www.dropbox.com/s/7vle92kcqbbyn8o/lib3delight.dylib";
36 #[cfg(target_os = "linux")]
37 let lib = "https://www.dropbox.com/s/wfw6w6p41lqd8ko/lib3delight.so";
38
39 let lib_path = lib_path.join(Path::new(lib).file_name().unwrap());
40
41 eprintln!("lib: {}", lib_path.display());
42
43 if !lib_path.exists() {
44 let lib_data = reqwest::blocking::get(lib.to_owned() + "?dl=1")
46 .ok().ok_or("Failed to download lib3delight")?
47 .bytes()
48 .ok().ok_or("Failed to get data for lib3delight")?;
49
50 File::create(lib_path.clone())?
51 .write_all(&lib_data)?;
52 }
53
54 lib_path.parent().unwrap().to_path_buf()
55 };
56
57 #[cfg(not(feature = "download_lib3delight"))]
58 #[allow(unused_variables)]
59 let lib_path = if let Ok(dl_path) = std::env::var("DELIGHT") {
60 eprintln!("Building against locally installed 3Delight @ {}", &dl_path);
61 let lib_path = std::path::PathBuf::from(dl_path);
62
63 #[cfg(target_os = "windows")]
64 let lib_path = lib_path.join("bin");
65
66 #[cfg(any(target_os = "linux", target_os = "macos"))]
67 let lib_path = lib_path.join("lib");
68
69 lib_path
70 } else {
71 std::path::PathBuf::new()
72 };
73
74 #[cfg(feature = "link_lib3delight")]
75 {
76 if lib_path.exists() {
78 println!("cargo:rustc-link-search={}", lib_path.display());
79 }
80
81 println!("cargo:rustc-link-lib=dylib=3delight");
83 }
84
85 Ok(())
86}