Skip to content

Commit ad20eac

Browse files
committed
Library::print_cargo_metadata
1 parent 47f20b9 commit ad20eac

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

intel-mkl-src/build.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
use anyhow::{bail, Result};
2626
use intel_mkl_tool::*;
27-
use std::{str::FromStr};
27+
use std::str::FromStr;
2828

2929
#[cfg(feature = "mkl-static-lp64-iomp")]
3030
const MKL_CONFIG: &str = "mkl-static-lp64-iomp";
@@ -45,26 +45,9 @@ const MKL_CONFIG: &str = "mkl-dynamic-ilp64-seq";
4545

4646
fn main() -> Result<()> {
4747
let cfg = Config::from_str(MKL_CONFIG).unwrap();
48-
49-
// already exists on system
50-
if let Ok(entry) = Entry::from_config(cfg) {
51-
entry.print_cargo_metadata();
48+
if let Ok(lib) = Library::new(cfg) {
49+
lib.print_cargo_metadata()?;
5250
return Ok(());
5351
}
54-
55-
// download if not found
56-
#[cfg(feature = "download")]
57-
{
58-
let path = PathBuf::from(env::var("OUT_DIR").unwrap());
59-
println!(
60-
r#"cargo:warning="Download Intel MKL archive into {}""#,
61-
path.display()
62-
);
63-
cfg.download(path)?;
64-
let entry = Entry::from_config(cfg).unwrap(); // must found
65-
entry.print_cargo_metadata();
66-
return Ok(());
67-
}
68-
69-
bail!("No MKL found, and download flag is off.");
52+
bail!("No MKL found");
7053
}

intel-mkl-tool/src/entry.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,37 @@ impl Library {
235235
_ => bail!("Invalid mkl_version.h"),
236236
}
237237
}
238+
239+
/// Print `cargo:rustc-link-*` metadata to stdout
240+
pub fn print_cargo_metadata(&self) -> Result<()> {
241+
match self {
242+
Library::PkgConfig { config, .. } => {
243+
pkg_config::probe_library(&config.to_string())?;
244+
}
245+
Library::Directory {
246+
config,
247+
library_dir,
248+
iomp5_dir,
249+
..
250+
} => {
251+
println!("cargo:rustc-link-search={}", library_dir.display());
252+
if let Some(iomp5_dir) = iomp5_dir {
253+
println!("cargo:rustc-link-search={}", iomp5_dir.display());
254+
}
255+
for lib in config.libs() {
256+
match config.link {
257+
LinkType::Static => {
258+
println!("cargo:rustc-link-lib=static={}", lib);
259+
}
260+
LinkType::Dynamic => {
261+
println!("cargo:rustc-link-lib=dylib={}", lib);
262+
}
263+
}
264+
}
265+
}
266+
}
267+
Ok(())
268+
}
238269
}
239270

240271
#[derive(Debug, Deref)]

0 commit comments

Comments
 (0)