Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d91f0ad

Browse files
authoredAug 10, 2022
Merge pull request #84 from rust-math/ocipkg
Create new archive using ocipkg
2 parents e7ad247 + 6f00407 commit d91f0ad

File tree

7 files changed

+131
-4
lines changed

7 files changed

+131
-4
lines changed
 

‎.github/workflows/intel-mkl-pack.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: intel-mkl-pack
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request: {}
8+
9+
jobs:
10+
linux:
11+
runs-on: ubuntu-22.04
12+
container:
13+
image: ghcr.io/rust-math/intel-mkl-src/mkl-rust:1.56.0-1
14+
steps:
15+
- uses: actions/checkout@v1
16+
- uses: actions-rs/cargo@v1
17+
with:
18+
command: run
19+
args: --manifest-path=intel-mkl-pack/Cargo.toml --release

‎.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ Cargo.lock
1313
rusty-tags.*
1414

1515
# Generated archives
16-
*.tar.zst
16+
*.tar.zst
17+
*.tar

‎Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ members = [
33
"intel-mkl-src",
44
"intel-mkl-sys",
55
"intel-mkl-tool",
6+
"intel-mkl-pack",
67
]

‎intel-mkl-pack/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "intel-mkl-pack"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies.intel-mkl-tool]
9+
path = "../intel-mkl-tool"
10+
11+
[dependencies]
12+
anyhow = "1.0.60"
13+
oci-spec = "0.5.7"
14+
ocipkg = "0.1.2"
15+
colored = "2.0.0"

‎intel-mkl-pack/src/main.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
}

‎intel-mkl-tool/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,3 @@ license = "MIT"
1313
[dependencies]
1414
anyhow = "1.0.58"
1515
walkdir = "2.3.2"
16-
17-
[dev-dependencies]
18-
paste = "1.0.7"

‎intel-mkl-tool/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
//! Helper crate of `build.rs` in intel-mkl-src crate.
2+
//!
3+
//! This crate is responsible for setup Intel MKL library
4+
//! usable from Rust crate.
5+
//!
6+
//! - Find library from system.
7+
//! - Download library as a container from OCI registry.
8+
//!
9+
110
mod config;
211
mod entry;
312

0 commit comments

Comments
 (0)
Please sign in to comment.