|
| 1 | +//! Create container of MKL library, found by intel-mkl-tool |
| 2 | +
|
| 3 | +use anyhow::{bail, Result}; |
| 4 | +use colored::Colorize; |
| 5 | +use intel_mkl_tool::{Config, Library, LinkType, STATIC_EXTENSION}; |
| 6 | +use oci_spec::image::Platform; |
| 7 | +use ocipkg::{image::Builder, ImageName}; |
| 8 | +use std::{fs, path::Path, time::Instant}; |
| 9 | + |
| 10 | +const REGISTRY: &str = "ghcr.io/rust-math/intel-mkl-src"; |
| 11 | + |
| 12 | +fn main() -> Result<()> { |
| 13 | + let run_id: u64 = std::env::var("GITHUB_RUN_ID") |
| 14 | + .unwrap_or_else(|_| "0".to_string()) // fallback value for local testing |
| 15 | + .parse()?; |
| 16 | + for cfg in Config::possibles() { |
| 17 | + let lib = Library::new(cfg)?; |
| 18 | + let (year, _, update) = lib.version()?; |
| 19 | + let name = ImageName::parse(&format!( |
| 20 | + "{}/{}:{}.{}-{}", |
| 21 | + REGISTRY, cfg, year, update, run_id |
| 22 | + ))?; |
| 23 | + let output = format!("{}.tar", cfg); |
| 24 | + |
| 25 | + eprintln!("{:>12} {}", "Packaging".green().bold(), name); |
| 26 | + let timer = Instant::now(); |
| 27 | + pack(cfg, &name, &output)?; |
| 28 | + eprintln!( |
| 29 | + "{:>12} {} ({:.2}s)", |
| 30 | + "Created".green().bold(), |
| 31 | + output, |
| 32 | + timer.elapsed().as_secs_f32() |
| 33 | + ); |
| 34 | + } |
| 35 | + Ok(()) |
| 36 | +} |
| 37 | + |
| 38 | +/// Create oci-archive |
| 39 | +pub fn pack(cfg: Config, name: &ImageName, output: impl AsRef<Path>) -> Result<()> { |
| 40 | + let lib = Library::new(cfg)?; |
| 41 | + |
| 42 | + let libs = cfg |
| 43 | + .libs() |
| 44 | + .into_iter() |
| 45 | + .chain(cfg.additional_libs().into_iter()) |
| 46 | + .map(|name| { |
| 47 | + let path = if name == "iomp5" { |
| 48 | + lib.iomp5_dir |
| 49 | + .as_ref() |
| 50 | + .unwrap() |
| 51 | + .join(as_library_filename(cfg.link, &name)) |
| 52 | + } else { |
| 53 | + lib.library_dir.join(as_library_filename(cfg.link, &name)) |
| 54 | + }; |
| 55 | + if !path.exists() { |
| 56 | + bail!("Required library not found: {}", path.display()); |
| 57 | + } |
| 58 | + Ok(path) |
| 59 | + }) |
| 60 | + .collect::<Result<Vec<_>>>()?; |
| 61 | + |
| 62 | + let mut f = fs::File::create(output)?; |
| 63 | + let mut builder = Builder::new(&mut f); |
| 64 | + builder.append_files(&libs)?; |
| 65 | + builder.set_platform(&Platform::default()); |
| 66 | + builder.set_name(name); |
| 67 | + Ok(()) |
| 68 | +} |
| 69 | + |
| 70 | +fn as_library_filename(link: LinkType, name: &str) -> String { |
| 71 | + match link { |
| 72 | + LinkType::Static => format!( |
| 73 | + "{}{}.{}", |
| 74 | + std::env::consts::DLL_PREFIX, |
| 75 | + name, |
| 76 | + STATIC_EXTENSION |
| 77 | + ), |
| 78 | + LinkType::Dynamic => format!( |
| 79 | + "{}{}.{}", |
| 80 | + std::env::consts::DLL_PREFIX, |
| 81 | + name, |
| 82 | + std::env::consts::DLL_EXTENSION |
| 83 | + ), |
| 84 | + } |
| 85 | +} |
0 commit comments