| |
1 use build_print::info; |
| |
2 use conda_build::pkgconfig_conda; |
| |
3 use itertools::Itertools; |
| |
4 use std::env; |
| |
5 |
| |
6 fn main() -> Result<(), anyhow::Error> { |
| |
7 if let Some(conda_root) = pkgconfig_conda()? { |
| |
8 info!( |
| |
9 "Directing pkg-config to look for fenics-dolfinx within the Conda environment {}.", |
| |
10 conda_root.display() |
| |
11 ); |
| |
12 } |
| |
13 |
| |
14 println!("cargo:rerun-if-changed=build.rs"); |
| |
15 |
| |
16 let mut pkg = pkg_config::Config::new(); |
| |
17 locate_dolfinx(&mut pkg) |
| |
18 } |
| |
19 |
| |
20 fn locate_dolfinx(pkg: &mut pkg_config::Config) -> Result<(), anyhow::Error> { |
| |
21 let lib = pkg.probe("dolfinx").or_else(|e| { |
| |
22 // Debian/Ubuntu has separate real and complex dolfinx. |
| |
23 info!("Could not find dolfinx, trying dolfinx_real (as the library is named if installed through a Debian/Ubuntu package)."); |
| |
24 // If that's also not found, return original error instead of Debian/Ubuntu-specic error. |
| |
25 pkg.probe("dolfinx_real").map_err(|_| e) |
| |
26 })?; |
| |
27 |
| |
28 // We also need fmt for linking to work. |
| |
29 pkg.probe("fmt")?; |
| |
30 |
| |
31 let cleaned_paths = lib.include_paths.iter().unique().collect::<Vec<_>>(); |
| |
32 let includes = env::join_paths(cleaned_paths)?.into_string().unwrap(); |
| |
33 println!("cargo:include={}", includes); |
| |
34 |
| |
35 println!( |
| |
36 "cargo:ldflags={}", |
| |
37 env::join_paths(lib.ld_args.iter().map(|s| s.join(",")))? |
| |
38 .into_string() |
| |
39 .unwrap() |
| |
40 ); |
| |
41 |
| |
42 // let cleaned_rpaths = lib.link_paths.iter().unique().collect::<Vec<_>>(); |
| |
43 // let rpaths = env::join_paths(cleaned_rpaths)?.into_string().unwrap(); |
| |
44 // println!("cargo:rpath={}", rpaths); |
| |
45 |
| |
46 // for lp in lib.link_paths.iter().unique() { |
| |
47 // println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lp.display()); |
| |
48 // } |
| |
49 |
| |
50 Ok(()) |
| |
51 } |