mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 20:58:28 +00:00
Refactor methods to filter tarballs
This commit is contained in:
@@ -402,24 +402,9 @@ impl CreateExe {
|
|||||||
let library = if let Some(v) = cross_subc.library_path.clone() {
|
let library = if let Some(v) = cross_subc.library_path.clone() {
|
||||||
v.canonicalize().unwrap_or(v)
|
v.canonicalize().unwrap_or(v)
|
||||||
} else {
|
} else {
|
||||||
{
|
let (filename, tarball_dir) =
|
||||||
let tarball_dir;
|
if let Some(local_tarball) = cross_subc.tarball.as_ref() {
|
||||||
let filename = if let Some(local_tarball) = cross_subc.tarball.as_ref() {
|
Self::find_filename(local_tarball, &target)
|
||||||
let target_file_path = local_tarball
|
|
||||||
.parent()
|
|
||||||
.and_then(|parent| Some(parent.join(local_tarball.file_stem()?)))
|
|
||||||
.unwrap_or_else(|| local_tarball.clone());
|
|
||||||
|
|
||||||
let target_file_path = target_file_path
|
|
||||||
.parent()
|
|
||||||
.and_then(|parent| Some(parent.join(target_file_path.file_stem()?)))
|
|
||||||
.unwrap_or_else(|| target_file_path.clone());
|
|
||||||
|
|
||||||
let _ = std::fs::create_dir_all(&target_file_path);
|
|
||||||
let files = untar(local_tarball.clone(), target_file_path.clone())?;
|
|
||||||
tarball_dir = target_file_path.canonicalize().unwrap_or(target_file_path);
|
|
||||||
files.iter().find(|f| f.ends_with("libwasmer.a")).cloned().ok_or_else(|| {
|
|
||||||
anyhow::bail!("Could not find libwasmer.a for {} target in the provided tarball path (files = {files:#?})", target)});
|
|
||||||
} else {
|
} else {
|
||||||
// check if the tarball for the target already exists locally
|
// check if the tarball for the target already exists locally
|
||||||
let local_tarball = std::fs::read_dir(get_libwasmer_cache_path()?)?
|
let local_tarball = std::fs::read_dir(get_libwasmer_cache_path()?)?
|
||||||
@@ -432,7 +417,60 @@ impl CreateExe {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter_map(|p| {
|
.filter_map(|p| Self::filter_tarballs(&p, &target))
|
||||||
|
.next();
|
||||||
|
|
||||||
|
if let Some(local_tarball) = local_tarball.as_ref() {
|
||||||
|
Self::find_filename(local_tarball, &target)
|
||||||
|
} else {
|
||||||
|
let release = http_fetch::get_latest_release()?;
|
||||||
|
let tarball = http_fetch::download_release(release, target.clone())?;
|
||||||
|
Self::find_filename(&tarball, &target)
|
||||||
|
}
|
||||||
|
}?;
|
||||||
|
|
||||||
|
tarball_dir.join(&filename)
|
||||||
|
};
|
||||||
|
let ccs = CrossCompileSetup {
|
||||||
|
target,
|
||||||
|
zig_binary_path,
|
||||||
|
library,
|
||||||
|
};
|
||||||
|
Ok(Some(ccs))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_filename(
|
||||||
|
local_tarball: &PathBuf,
|
||||||
|
target: &Triple,
|
||||||
|
) -> Result<(String, PathBuf), anyhow::Error> {
|
||||||
|
let target_file_path = local_tarball
|
||||||
|
.parent()
|
||||||
|
.and_then(|parent| Some(parent.join(local_tarball.file_stem()?)))
|
||||||
|
.unwrap_or_else(|| local_tarball.clone());
|
||||||
|
|
||||||
|
let target_file_path = target_file_path
|
||||||
|
.parent()
|
||||||
|
.and_then(|parent| Some(parent.join(target_file_path.file_stem()?)))
|
||||||
|
.unwrap_or_else(|| target_file_path.clone());
|
||||||
|
|
||||||
|
let _ = std::fs::create_dir_all(&target_file_path);
|
||||||
|
let files = untar(local_tarball.clone(), target_file_path.clone())?;
|
||||||
|
let tarball_dir = target_file_path.canonicalize().unwrap_or(target_file_path);
|
||||||
|
|
||||||
|
let file = files
|
||||||
|
.iter()
|
||||||
|
.find(|f| f.ends_with("libwasmer.a")).cloned()
|
||||||
|
.ok_or_else(|| {
|
||||||
|
anyhow!("Could not find libwasmer.a for {} target in the provided tarball path (files = {files:#?})", target)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok((file, tarball_dir))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn filter_tarballs(p: &PathBuf, target: &Triple) -> Option<PathBuf> {
|
||||||
if let Architecture::Aarch64(_) = target.architecture {
|
if let Architecture::Aarch64(_) = target.architecture {
|
||||||
if !p.file_name()?.to_str()?.contains("aarch64") {
|
if !p.file_name()?.to_str()?.contains("aarch64") {
|
||||||
return None;
|
return None;
|
||||||
@@ -465,68 +503,7 @@ impl CreateExe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(p)
|
Some(p.clone())
|
||||||
})
|
|
||||||
.next();
|
|
||||||
|
|
||||||
if let Some(local_tarball) = local_tarball.as_ref() {
|
|
||||||
let target_file_path = local_tarball
|
|
||||||
.parent()
|
|
||||||
.and_then(|parent| Some(parent.join(local_tarball.file_stem()?)))
|
|
||||||
.unwrap_or_else(|| local_tarball.clone());
|
|
||||||
|
|
||||||
let target_file_path = target_file_path
|
|
||||||
.parent()
|
|
||||||
.and_then(|parent| Some(parent.join(target_file_path.file_stem()?)))
|
|
||||||
.unwrap_or_else(|| target_file_path.clone());
|
|
||||||
|
|
||||||
let _ = std::fs::create_dir_all(&target_file_path);
|
|
||||||
let files = untar(local_tarball.clone(), target_file_path.clone())?;
|
|
||||||
tarball_dir =
|
|
||||||
target_file_path.canonicalize().unwrap_or(target_file_path);
|
|
||||||
files.iter().find(|f| f.ends_with("libwasmer.a")).cloned().ok_or_else(|| {
|
|
||||||
anyhow!("Could not find libwasmer.a for {} target in the provided tarball path (files = {files:#?})", target)})?
|
|
||||||
} else {
|
|
||||||
#[cfg(feature = "http")]
|
|
||||||
{
|
|
||||||
let release = http_fetch::get_latest_release()?;
|
|
||||||
let tarball =
|
|
||||||
http_fetch::download_release(release, target.clone())?;
|
|
||||||
let target_file_path = tarball
|
|
||||||
.parent()
|
|
||||||
.and_then(|parent| Some(parent.join(tarball.file_stem()?)))
|
|
||||||
.unwrap_or_else(|| tarball.clone());
|
|
||||||
|
|
||||||
let target_file_path = target_file_path
|
|
||||||
.parent()
|
|
||||||
.and_then(|parent| {
|
|
||||||
Some(parent.join(target_file_path.file_stem()?))
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|| target_file_path.clone());
|
|
||||||
|
|
||||||
tarball_dir = target_file_path
|
|
||||||
.canonicalize()
|
|
||||||
.unwrap_or_else(|_| target_file_path.clone());
|
|
||||||
let files = untar(tarball, target_file_path)?;
|
|
||||||
files.iter().find(|f| f.ends_with("libwasmer.a")).cloned().ok_or_else(|| {
|
|
||||||
anyhow!("Could not find libwasmer for {} target in the fetched release from Github: you can download it manually and specify its path with the --cross-compilation-library-path LIBRARY_PATH flag. (files = {files:#?}", target)})?
|
|
||||||
}
|
|
||||||
#[cfg(not(feature = "http"))]
|
|
||||||
return Err(anyhow!("This wasmer binary isn't compiled with an HTTP request library (feature flag `http`). To cross-compile, specify the path of the non-native libwasmer or release tarball with the --library-path LIBRARY_PATH or --tarball TARBALL_PATH flag."));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
tarball_dir.join(&filename)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let ccs = CrossCompileSetup {
|
|
||||||
target,
|
|
||||||
zig_binary_path,
|
|
||||||
library,
|
|
||||||
};
|
|
||||||
Ok(Some(ccs))
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_c(
|
fn compile_c(
|
||||||
|
|||||||
Reference in New Issue
Block a user