mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 12:48:20 +00:00
Pass filesystem mappings from wapm.toml to --mapdir
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -3858,6 +3858,7 @@ dependencies = [
|
|||||||
"target-lexicon 0.12.4",
|
"target-lexicon 0.12.4",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"unix_mode",
|
"unix_mode",
|
||||||
|
"wapm-toml",
|
||||||
"wasmer",
|
"wasmer",
|
||||||
"wasmer-cache",
|
"wasmer-cache",
|
||||||
"wasmer-compiler",
|
"wasmer-compiler",
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ dirs = { version = "4.0", optional = true }
|
|||||||
serde_json = { version = "1.0", optional = true }
|
serde_json = { version = "1.0", optional = true }
|
||||||
target-lexicon = { version = "0.12", features = ["std"] }
|
target-lexicon = { version = "0.12", features = ["std"] }
|
||||||
prettytable-rs = "0.9.0"
|
prettytable-rs = "0.9.0"
|
||||||
|
wapm-toml = "0.1.1"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
chrono = "0.4.22"
|
chrono = "0.4.22"
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ fn parse_cli_args() -> Result<(), anyhow::Error> {
|
|||||||
let mut args_without_package = args.clone();
|
let mut args_without_package = args.clone();
|
||||||
args_without_package.remove(1);
|
args_without_package.remove(1);
|
||||||
return RunWithoutFile::try_parse_from(args_without_package.iter())?
|
return RunWithoutFile::try_parse_from(args_without_package.iter())?
|
||||||
.into_run_args(package.path)
|
.into_run_args(package.path, Some(package.manifest.clone()))
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,12 +270,12 @@ fn parse_cli_args() -> Result<(), anyhow::Error> {
|
|||||||
sp.close();
|
sp.close();
|
||||||
print!("\r\n");
|
print!("\r\n");
|
||||||
match result {
|
match result {
|
||||||
Ok(o) => {
|
Ok((package, buf)) => {
|
||||||
// Try auto-installing the remote package
|
// Try auto-installing the remote package
|
||||||
let mut args_without_package = args.clone();
|
let mut args_without_package = args.clone();
|
||||||
args_without_package.remove(1);
|
args_without_package.remove(1);
|
||||||
return RunWithoutFile::try_parse_from(args_without_package.iter())?
|
return RunWithoutFile::try_parse_from(args_without_package.iter())?
|
||||||
.into_run_args(o)
|
.into_run_args(buf, Some(package.manifest.clone()))
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
@@ -75,7 +75,30 @@ pub struct RunWithoutFile {
|
|||||||
|
|
||||||
impl RunWithoutFile {
|
impl RunWithoutFile {
|
||||||
/// Given a local path, returns the `Run` command (overriding the `--path` argument).
|
/// Given a local path, returns the `Run` command (overriding the `--path` argument).
|
||||||
pub fn into_run_args(self, pathbuf: PathBuf) -> Run {
|
pub fn into_run_args(mut self, pathbuf: PathBuf, manifest: Option<wapm_toml::Manifest>) -> Run {
|
||||||
|
|
||||||
|
#[cfg(feature = "wasi")]
|
||||||
|
if let Some(fs) = manifest.as_ref().and_then(|m| m.fs.as_ref()) {
|
||||||
|
for (alias, real_dir) in fs.iter() {
|
||||||
|
let real_dir = if let Some(parent) = pathbuf.parent() {
|
||||||
|
parent.join(real_dir)
|
||||||
|
} else {
|
||||||
|
pathbuf.join(real_dir)
|
||||||
|
};
|
||||||
|
if !real_dir.exists() {
|
||||||
|
println!("warning: cannot map {alias:?} to {}: directory does not exist", real_dir.display());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
println!("mapping {alias:?} -> {}", real_dir.display());
|
||||||
|
self.wasi.map_dir(alias, real_dir.clone());
|
||||||
|
|
||||||
|
#[cfg(feature = "wasi")] {
|
||||||
|
println!("setting PYTHONHOME to /{}", real_dir.display());
|
||||||
|
self.wasi.set_env("PYTHONHOME", &format!("{}", real_dir.display()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Run {
|
Run {
|
||||||
#[cfg(feature = "cache")]
|
#[cfg(feature = "cache")]
|
||||||
disable_cache: self.disable_cache,
|
disable_cache: self.disable_cache,
|
||||||
|
|||||||
@@ -52,6 +52,16 @@ pub struct Wasi {
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
impl Wasi {
|
impl Wasi {
|
||||||
|
|
||||||
|
pub fn map_dir(&mut self, alias: &str, target_on_disk: PathBuf) {
|
||||||
|
self.mapped_dirs.push((alias.to_string(), target_on_disk));
|
||||||
|
self.pre_opened_directories.push(std::path::Path::new(alias).to_path_buf());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_env(&mut self, key: &str, value: &str) {
|
||||||
|
self.env_vars.push((key.to_string(), value.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets the WASI version (if any) for the provided module
|
/// Gets the WASI version (if any) for the provided module
|
||||||
pub fn get_versions(module: &Module) -> Option<BTreeSet<WasiVersion>> {
|
pub fn get_versions(module: &Module) -> Option<BTreeSet<WasiVersion>> {
|
||||||
// Get the wasi version in strict mode, so no other imports are
|
// Get the wasi version in strict mode, so no other imports are
|
||||||
|
|||||||
@@ -730,7 +730,7 @@ pub fn download_and_unpack_targz(url: &str, target_path: &Path) -> Result<PathBu
|
|||||||
Ok(target_path.to_path_buf())
|
Ok(target_path.to_path_buf())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn install_package(name: &str, version: Option<&str>) -> Result<PathBuf, String> {
|
pub fn install_package(name: &str, version: Option<&str>) -> Result<(LocalPackage, PathBuf), String> {
|
||||||
let registries = get_all_available_registries()?;
|
let registries = get_all_available_registries()?;
|
||||||
let mut url_of_package = None;
|
let mut url_of_package = None;
|
||||||
let mut error_packages = Vec::new();
|
let mut error_packages = Vec::new();
|
||||||
@@ -817,13 +817,13 @@ pub fn install_package(name: &str, version: Option<&str>) -> Result<PathBuf, Str
|
|||||||
let wapm_toml = toml::from_str::<wapm_toml::Manifest>(&wapm_toml)
|
let wapm_toml = toml::from_str::<wapm_toml::Manifest>(&wapm_toml)
|
||||||
.map_err(|e| format!("Could not parse toml for {name}@{version}: {e}"))?;
|
.map_err(|e| format!("Could not parse toml for {name}@{version}: {e}"))?;
|
||||||
|
|
||||||
let commands = wapm_toml.command.unwrap_or_default();
|
let commands = wapm_toml.command.clone().unwrap_or_default();
|
||||||
let entrypoint_module = commands.first().ok_or(format!(
|
let entrypoint_module = commands.first().ok_or(format!(
|
||||||
"Cannot run {name}@{version}: package has no commands"
|
"Cannot run {name}@{version}: package has no commands"
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
let module_name = entrypoint_module.get_module();
|
let module_name = entrypoint_module.get_module();
|
||||||
let modules = wapm_toml.module.unwrap_or_default();
|
let modules = wapm_toml.module.clone().unwrap_or_default();
|
||||||
let entrypoint_module = modules
|
let entrypoint_module = modules
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|m| m.name == module_name)
|
.filter(|m| m.name == module_name)
|
||||||
@@ -832,7 +832,13 @@ pub fn install_package(name: &str, version: Option<&str>) -> Result<PathBuf, Str
|
|||||||
"Cannot run {name}@{version}: module {module_name} not found in wapm.toml"
|
"Cannot run {name}@{version}: module {module_name} not found in wapm.toml"
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
Ok(target_path.join(&entrypoint_module.source))
|
Ok((LocalPackage {
|
||||||
|
registry: package_info.registry.clone(),
|
||||||
|
name: wapm_toml.package.name.clone(),
|
||||||
|
version: wapm_toml.package.version.to_string(),
|
||||||
|
manifest: wapm_toml,
|
||||||
|
path: target_path.clone(),
|
||||||
|
}, target_path.join(&entrypoint_module.source)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_if_registry_present(registry: &str) -> Result<bool, String> {
|
pub fn test_if_registry_present(registry: &str) -> Result<bool, String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user