Skip to content

Create new archive using ocipkg #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/intel-mkl-pack.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ Cargo.lock
rusty-tags.*

# Generated archives
*.tar.zst
*.tar.zst
*.tar
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ members = [
"intel-mkl-src",
"intel-mkl-sys",
"intel-mkl-tool",
"intel-mkl-pack",
]
15 changes: 15 additions & 0 deletions intel-mkl-pack/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
85 changes: 85 additions & 0 deletions intel-mkl-pack/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<Path>) -> 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::<Result<Vec<_>>>()?;

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
),
}
}
3 changes: 0 additions & 3 deletions intel-mkl-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ license = "MIT"
[dependencies]
anyhow = "1.0.58"
walkdir = "2.3.2"

[dev-dependencies]
paste = "1.0.7"
9 changes: 9 additions & 0 deletions intel-mkl-tool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down