flowey_lib_hvlite/
download_lxutil.rsuse flowey::node::prelude::*;
use std::collections::BTreeMap;
#[derive(Serialize, Deserialize)]
pub struct LxutilPackage {
pub lxutil_dll: PathBuf,
pub lxutil_pdb: PathBuf,
pub lxutil_lib: PathBuf,
pub lxutil_h: PathBuf,
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum LxutilArch {
X86_64,
Aarch64,
}
flowey_request! {
pub enum Request {
Version(String),
GetPackage {
arch: LxutilArch,
pkg: WriteVar<LxutilPackage>
}
}
}
new_flow_node!(struct Node);
impl FlowNode for Node {
type Request = Request;
fn imports(ctx: &mut ImportCtx<'_>) {
ctx.import::<flowey_lib_common::install_dist_pkg::Node>();
ctx.import::<flowey_lib_common::download_gh_release::Node>();
}
fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
let mut version = None;
let mut reqs: BTreeMap<LxutilArch, Vec<WriteVar<LxutilPackage>>> = BTreeMap::new();
for req in requests {
match req {
Request::Version(v) => same_across_all_reqs("Version", &mut version, v)?,
Request::GetPackage { arch, pkg } => reqs.entry(arch).or_default().push(pkg),
}
}
let version = version.ok_or(anyhow::anyhow!("Missing essential request: Version"))?;
if reqs.is_empty() {
return Ok(());
}
let extract_zip_deps = flowey_lib_common::_util::extract::extract_zip_if_new_deps(ctx);
for (arch, out_vars) in reqs {
let tag = format!("Microsoft.WSL.LxUtil.{}", version);
let file_name = {
let arch_str = match arch {
LxutilArch::X86_64 => "x64",
LxutilArch::Aarch64 => "AARCH64",
};
format!("Microsoft.WSL.LxUtil.{}.zip", arch_str)
};
let lxutil_zip = ctx.reqv(|v| flowey_lib_common::download_gh_release::Request {
repo_owner: "microsoft".into(),
repo_name: "openvmm-deps".into(),
needs_auth: false,
tag: tag.clone(),
file_name: file_name.clone(),
path: v,
});
ctx.emit_rust_step(format!("unpack {}", file_name), |ctx| {
let extract_zip_deps = extract_zip_deps.clone().claim(ctx);
let out_vars = out_vars.claim(ctx);
let lxutil_zip = lxutil_zip.claim(ctx);
move |rt| {
let lxutil_zip = rt.read(lxutil_zip);
let extract_dir = flowey_lib_common::_util::extract::extract_zip_if_new(
rt,
extract_zip_deps,
&lxutil_zip,
&tag,
)?;
let lxutil_package = LxutilPackage {
lxutil_dll: extract_dir.join("native/bin/lxutil.dll"),
lxutil_pdb: extract_dir.join("native/bin/lxutil.pdb"),
lxutil_lib: extract_dir.join("native/lib/lxutil.lib"),
lxutil_h: extract_dir.join("native/include/lxutil.h"),
};
rt.write_all(out_vars, &lxutil_package);
Ok(())
}
});
}
Ok(())
}
}