diff --git a/.github/workflows/intel-mkl-pack.yml b/.github/workflows/intel-mkl-pack.yml new file mode 100644 index 00000000..49359f83 --- /dev/null +++ b/.github/workflows/intel-mkl-pack.yml @@ -0,0 +1,19 @@ +name: intel-mkl-pack + +on: + push: + branches: + - master + pull_request: {} + +jobs: + linux: + runs-on: ubuntu-22.04 + container: + image: ghcr.io/rust-math/intel-mkl-src/mkl-rust:1.56.0-1 + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/cargo@v1 + with: + command: run + args: --manifest-path=intel-mkl-pack/Cargo.toml --release diff --git a/.gitignore b/.gitignore index 5e139de1..5b99a8ac 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ Cargo.lock rusty-tags.* # Generated archives -*.tar.zst \ No newline at end of file +*.tar.zst +*.tar diff --git a/Cargo.toml b/Cargo.toml index 8cbf4614..f328d627 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,5 @@ members = [ "intel-mkl-src", "intel-mkl-sys", "intel-mkl-tool", + "intel-mkl-pack", ] diff --git a/intel-mkl-pack/Cargo.toml b/intel-mkl-pack/Cargo.toml new file mode 100644 index 00000000..0ec7366e --- /dev/null +++ b/intel-mkl-pack/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "intel-mkl-pack" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies.intel-mkl-tool] +path = "../intel-mkl-tool" + +[dependencies] +anyhow = "1.0.60" +oci-spec = "0.5.7" +ocipkg = "0.1.2" +colored = "2.0.0" diff --git a/intel-mkl-pack/src/main.rs b/intel-mkl-pack/src/main.rs new file mode 100644 index 00000000..c24ce7bf --- /dev/null +++ b/intel-mkl-pack/src/main.rs @@ -0,0 +1,85 @@ +//! Create container of MKL library, found by intel-mkl-tool + +use anyhow::{bail, Result}; +use colored::Colorize; +use intel_mkl_tool::{Config, Library, LinkType, STATIC_EXTENSION}; +use oci_spec::image::Platform; +use ocipkg::{image::Builder, ImageName}; +use std::{fs, path::Path, time::Instant}; + +const REGISTRY: &str = "ghcr.io/rust-math/intel-mkl-src"; + +fn main() -> Result<()> { + let run_id: u64 = std::env::var("GITHUB_RUN_ID") + .unwrap_or_else(|_| "0".to_string()) // fallback value for local testing + .parse()?; + for cfg in Config::possibles() { + let lib = Library::new(cfg)?; + let (year, _, update) = lib.version()?; + let name = ImageName::parse(&format!( + "{}/{}:{}.{}-{}", + REGISTRY, cfg, year, update, run_id + ))?; + let output = format!("{}.tar", cfg); + + eprintln!("{:>12} {}", "Packaging".green().bold(), name); + let timer = Instant::now(); + pack(cfg, &name, &output)?; + eprintln!( + "{:>12} {} ({:.2}s)", + "Created".green().bold(), + output, + timer.elapsed().as_secs_f32() + ); + } + Ok(()) +} + +/// Create oci-archive +pub fn pack(cfg: Config, name: &ImageName, output: impl AsRef) -> Result<()> { + let lib = Library::new(cfg)?; + + let libs = cfg + .libs() + .into_iter() + .chain(cfg.additional_libs().into_iter()) + .map(|name| { + let path = if name == "iomp5" { + lib.iomp5_dir + .as_ref() + .unwrap() + .join(as_library_filename(cfg.link, &name)) + } else { + lib.library_dir.join(as_library_filename(cfg.link, &name)) + }; + if !path.exists() { + bail!("Required library not found: {}", path.display()); + } + Ok(path) + }) + .collect::>>()?; + + let mut f = fs::File::create(output)?; + let mut builder = Builder::new(&mut f); + builder.append_files(&libs)?; + builder.set_platform(&Platform::default()); + builder.set_name(name); + Ok(()) +} + +fn as_library_filename(link: LinkType, name: &str) -> String { + match link { + LinkType::Static => format!( + "{}{}.{}", + std::env::consts::DLL_PREFIX, + name, + STATIC_EXTENSION + ), + LinkType::Dynamic => format!( + "{}{}.{}", + std::env::consts::DLL_PREFIX, + name, + std::env::consts::DLL_EXTENSION + ), + } +} diff --git a/intel-mkl-tool/Cargo.toml b/intel-mkl-tool/Cargo.toml index 6ca8cd25..a74d7d29 100644 --- a/intel-mkl-tool/Cargo.toml +++ b/intel-mkl-tool/Cargo.toml @@ -13,6 +13,3 @@ license = "MIT" [dependencies] anyhow = "1.0.58" walkdir = "2.3.2" - -[dev-dependencies] -paste = "1.0.7" diff --git a/intel-mkl-tool/src/lib.rs b/intel-mkl-tool/src/lib.rs index c1701e03..c44bbbc2 100644 --- a/intel-mkl-tool/src/lib.rs +++ b/intel-mkl-tool/src/lib.rs @@ -1,3 +1,12 @@ +//! Helper crate of `build.rs` in intel-mkl-src crate. +//! +//! This crate is responsible for setup Intel MKL library +//! usable from Rust crate. +//! +//! - Find library from system. +//! - Download library as a container from OCI registry. +//! + mod config; mod entry;