mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 13:48:26 +00:00
Added RunWithoutFile to prepare downloading + GraphQL schema
This commit is contained in:
8
Cargo.lock
generated
8
Cargo.lock
generated
@@ -3135,6 +3135,7 @@ dependencies = [
|
|||||||
"wasmer-compiler-singlepass",
|
"wasmer-compiler-singlepass",
|
||||||
"wasmer-emscripten",
|
"wasmer-emscripten",
|
||||||
"wasmer-object",
|
"wasmer-object",
|
||||||
|
"wasmer-registry",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
"wasmer-vfs",
|
"wasmer-vfs",
|
||||||
"wasmer-vm",
|
"wasmer-vm",
|
||||||
@@ -3335,6 +3336,13 @@ dependencies = [
|
|||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasmer-registry"
|
||||||
|
version = "3.0.0-beta.2"
|
||||||
|
dependencies = [
|
||||||
|
"dirs",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-types"
|
name = "wasmer-types"
|
||||||
version = "3.0.0-beta.2"
|
version = "3.0.0-beta.2"
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ members = [
|
|||||||
"lib/c-api/tests/wasmer-c-api-test-runner",
|
"lib/c-api/tests/wasmer-c-api-test-runner",
|
||||||
"lib/c-api/examples/wasmer-capi-examples-runner",
|
"lib/c-api/examples/wasmer-capi-examples-runner",
|
||||||
"lib/types",
|
"lib/types",
|
||||||
|
"lib/registry",
|
||||||
"tests/wasi-wast",
|
"tests/wasi-wast",
|
||||||
"tests/lib/wast",
|
"tests/lib/wast",
|
||||||
"tests/lib/compiler-test-derive",
|
"tests/lib/compiler-test-derive",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub struct Compile {
|
|||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
|
|
||||||
/// Output file
|
/// Output file
|
||||||
#[clap(name = "OUTPUT PATH", short = 'o', value_parser = clap::value_parser!(std::ffi::OsString)))]
|
#[clap(name = "OUTPUT PATH", short = 'o', value_parser = clap::value_parser!(std::ffi::OsString))]
|
||||||
output: PathBuf,
|
output: PathBuf,
|
||||||
|
|
||||||
/// Compilation Target triple
|
/// Compilation Target triple
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ wasmer-wasi-experimental-io-devices = { version = "=3.0.0-beta.2", path = "../wa
|
|||||||
wasmer-wast = { version = "=3.0.0-beta.2", path = "../../tests/lib/wast", optional = true }
|
wasmer-wast = { version = "=3.0.0-beta.2", path = "../../tests/lib/wast", optional = true }
|
||||||
wasmer-cache = { version = "=3.0.0-beta.2", path = "../cache", optional = true }
|
wasmer-cache = { version = "=3.0.0-beta.2", path = "../cache", optional = true }
|
||||||
wasmer-types = { version = "=3.0.0-beta.2", path = "../types" }
|
wasmer-types = { version = "=3.0.0-beta.2", path = "../types" }
|
||||||
|
wasmer-registry = { version = "=3.0.0-beta.2", path = "../registry" }
|
||||||
wasmer-object = { version = "=3.0.0-beta.2", path = "../object", optional = true }
|
wasmer-object = { version = "=3.0.0-beta.2", path = "../object", optional = true }
|
||||||
wasmer-vfs = { version = "=3.0.0-beta.2", path = "../vfs", default-features = false, features = ["host-fs"] }
|
wasmer-vfs = { version = "=3.0.0-beta.2", path = "../vfs", default-features = false, features = ["host-fs"] }
|
||||||
atty = "0.2"
|
atty = "0.2"
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ use crate::commands::CreateExe;
|
|||||||
use crate::commands::CreateObj;
|
use crate::commands::CreateObj;
|
||||||
#[cfg(feature = "wast")]
|
#[cfg(feature = "wast")]
|
||||||
use crate::commands::Wast;
|
use crate::commands::Wast;
|
||||||
use crate::commands::{Cache, Config, Inspect, Run, SelfUpdate, Validate};
|
use crate::commands::{Cache, Config, Inspect, Run, RunWithoutFile, SelfUpdate, Validate};
|
||||||
use crate::error::PrettyError;
|
use crate::error::PrettyError;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
/// The main function for the Wasmer CLI tool.
|
/// The main function for the Wasmer CLI tool.
|
||||||
pub fn wasmer_main() {
|
pub fn wasmer_main() {
|
||||||
@@ -26,7 +27,6 @@ pub fn wasmer_main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_cli_args() -> Result<(), anyhow::Error> {
|
fn parse_cli_args() -> Result<(), anyhow::Error> {
|
||||||
|
|
||||||
let args = std::env::args().collect::<Vec<_>>();
|
let args = std::env::args().collect::<Vec<_>>();
|
||||||
let binpath = args.get(0).map(|s| s.as_ref()).unwrap_or("");
|
let binpath = args.get(0).map(|s| s.as_ref()).unwrap_or("");
|
||||||
|
|
||||||
@@ -36,42 +36,72 @@ fn parse_cli_args() -> Result<(), anyhow::Error> {
|
|||||||
return Run::from_binfmt_args().execute();
|
return Run::from_binfmt_args().execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
match (args.get(1).map(|s| s.as_str()), args.get(2).map(|s| s.as_str())) {
|
match (
|
||||||
(None, _) |
|
args.get(1).map(|s| s.as_str()),
|
||||||
(Some("help"), _) |
|
args.get(2).map(|s| s.as_str()),
|
||||||
(Some("--help"), _) => return print_help(),
|
) {
|
||||||
|
(None, _) | (Some("help"), _) | (Some("--help"), _) => return print_help(),
|
||||||
|
|
||||||
(Some("-vV"), _) |
|
(Some("-vV"), _)
|
||||||
(Some("version"), Some("--verbose")) |
|
| (Some("version"), Some("--verbose"))
|
||||||
(Some("--version"), Some("--verbose")) => return print_version(false),
|
| (Some("--version"), Some("--verbose")) => return print_version(false),
|
||||||
|
|
||||||
(Some("-v"), _) |
|
(Some("-v"), _) | (Some("-V"), _) | (Some("version"), _) | (Some("--version"), _) => {
|
||||||
(Some("version"), _) |
|
return print_version(false)
|
||||||
(Some("--version"), _) => return print_version(false),
|
}
|
||||||
|
|
||||||
(Some("cache"), Some(_)) |
|
(Some("cache"), _) => Cache::try_parse_from(args.iter())?.execute(),
|
||||||
(Some("compile"), Some(_)) |
|
(Some("compile"), _) => Compile::try_parse_from(args.iter())?.execute(),
|
||||||
(Some("config"), Some(_)) |
|
(Some("config"), _) => Config::try_parse_from(args.iter())?.execute(),
|
||||||
(Some("create-exe"), Some(_)) |
|
(Some("create-exe"), _) => CreateExe::try_parse_from(args.iter())?.execute(),
|
||||||
(Some("inspect"), Some(_)) |
|
(Some("inspect"), _) => Inspect::try_parse_from(args.iter())?.execute(),
|
||||||
(Some("self-update"), _) |
|
(Some("self-update"), _) => SelfUpdate::try_parse_from(args.iter())?.execute(),
|
||||||
(Some("validate"), Some(_)) |
|
(Some("validate"), _) => Validate::try_parse_from(args.iter())?.execute(),
|
||||||
(Some("wast"), Some(_)) |
|
(Some("wast"), _) => Wast::try_parse_from(args.iter())?.execute(),
|
||||||
(Some("binfmt"), Some(_)) => {
|
#[cfg(feature = "binfmt")]
|
||||||
println!("running {:?}", args.get(1));
|
(Some("binfmt"), _) => Binfmt::try_parse_from(args.iter())?.execute(),
|
||||||
return Ok(())
|
(Some("run"), Some(package)) | (Some(package), _) => {
|
||||||
},
|
|
||||||
(Some("run"), Some(_)) |
|
|
||||||
(Some(_), _) => {
|
|
||||||
use clap::Parser;
|
|
||||||
// wasmer run file
|
|
||||||
// wasmer run [package]
|
|
||||||
if let Ok(run) = Run::try_parse() {
|
if let Ok(run) = Run::try_parse() {
|
||||||
return run.execute();
|
return run.execute();
|
||||||
|
} else if let Ok((package, version)) = split_version(package) {
|
||||||
|
if let Ok(o) = wasmer_registry::get_package_local(
|
||||||
|
&package,
|
||||||
|
version.as_ref().map(|s| s.as_str()),
|
||||||
|
) {
|
||||||
|
// Try finding the local package
|
||||||
|
let mut args_without_package = args.clone();
|
||||||
|
args_without_package.remove(1);
|
||||||
|
return RunWithoutFile::try_parse_from(args_without_package.iter())?
|
||||||
|
.into_run_args(o)
|
||||||
|
.execute();
|
||||||
|
} else if let Ok(o) =
|
||||||
|
wasmer_registry::install_package(&package, version.as_ref().map(|s| s.as_str()))
|
||||||
|
{
|
||||||
|
// Try auto-installing the remote package
|
||||||
|
let mut args_without_package = args.clone();
|
||||||
|
args_without_package.remove(1);
|
||||||
|
return RunWithoutFile::try_parse_from(args_without_package.iter())?
|
||||||
|
.into_run_args(o)
|
||||||
|
.execute();
|
||||||
|
} else {
|
||||||
|
// Failed to find the remote package
|
||||||
|
//
|
||||||
|
// TODO: print list of similar packages
|
||||||
|
return print_help();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return print_help();
|
return print_help();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn split_version(s: &str) -> Result<(String, Option<String>), anyhow::Error> {
|
||||||
|
let package_version = s.split("@").collect::<Vec<_>>();
|
||||||
|
match package_version.as_slice() {
|
||||||
|
&[p, v] => Ok((p.trim().to_string(), Some(v.trim().to_string()))),
|
||||||
|
&[p] => Ok((p.trim().to_string(), None)),
|
||||||
|
_ => Err(anyhow!("Invalid package / version: {s:?}")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,83 @@ mod wasi;
|
|||||||
#[cfg(feature = "wasi")]
|
#[cfg(feature = "wasi")]
|
||||||
use wasi::Wasi;
|
use wasi::Wasi;
|
||||||
|
|
||||||
|
/// Same as `wasmer run`, but without the required `path` argument (injected previously)
|
||||||
|
#[derive(Debug, Parser, Clone, Default)]
|
||||||
|
pub struct RunWithoutFile {
|
||||||
|
/// Disable the cache
|
||||||
|
#[cfg(feature = "cache")]
|
||||||
|
#[clap(long = "disable-cache")]
|
||||||
|
disable_cache: bool,
|
||||||
|
|
||||||
|
/// Invoke a specified function
|
||||||
|
#[clap(long = "invoke", short = 'i')]
|
||||||
|
invoke: Option<String>,
|
||||||
|
|
||||||
|
/// The command name is a string that will override the first argument passed
|
||||||
|
/// to the wasm program. This is used in wapm to provide nicer output in
|
||||||
|
/// help commands and error messages of the running wasm program
|
||||||
|
#[clap(long = "command-name", hide = true)]
|
||||||
|
command_name: Option<String>,
|
||||||
|
|
||||||
|
/// A prehashed string, used to speed up start times by avoiding hashing the
|
||||||
|
/// wasm module. If the specified hash is not found, Wasmer will hash the module
|
||||||
|
/// as if no `cache-key` argument was passed.
|
||||||
|
#[cfg(feature = "cache")]
|
||||||
|
#[clap(long = "cache-key", hide = true)]
|
||||||
|
cache_key: Option<String>,
|
||||||
|
|
||||||
|
#[clap(flatten)]
|
||||||
|
store: StoreOptions,
|
||||||
|
|
||||||
|
// TODO: refactor WASI structure to allow shared options with Emscripten
|
||||||
|
#[cfg(feature = "wasi")]
|
||||||
|
#[clap(flatten)]
|
||||||
|
wasi: Wasi,
|
||||||
|
|
||||||
|
/// Enable non-standard experimental IO devices
|
||||||
|
#[cfg(feature = "io-devices")]
|
||||||
|
#[clap(long = "enable-io-devices")]
|
||||||
|
enable_experimental_io_devices: bool,
|
||||||
|
|
||||||
|
/// Enable debug output
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
#[clap(long = "debug", short = 'd')]
|
||||||
|
debug: bool,
|
||||||
|
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
#[clap(short, long, parse(from_occurrences))]
|
||||||
|
verbose: u8,
|
||||||
|
|
||||||
|
/// Application arguments
|
||||||
|
#[clap(value_name = "ARGS")]
|
||||||
|
args: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RunWithoutFile {
|
||||||
|
/// Given a local path, returns the `Run` command (overriding the `--path` argument).
|
||||||
|
pub fn into_run_args(self, pathbuf: PathBuf) -> Run {
|
||||||
|
Run {
|
||||||
|
#[cfg(feature = "cache")]
|
||||||
|
disable_cache: self.disable_cache,
|
||||||
|
path: pathbuf,
|
||||||
|
invoke: self.invoke,
|
||||||
|
command_name: self.command_name,
|
||||||
|
#[cfg(feature = "cache")]
|
||||||
|
cache_key: self.cache_key,
|
||||||
|
store: self.store,
|
||||||
|
#[cfg(feature = "wasi")]
|
||||||
|
wasi: self.wasi,
|
||||||
|
#[cfg(feature = "io-devices")]
|
||||||
|
enable_experimental_io_devices: self.enable_experimental_io_devices,
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
debug: self.debug,
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
verbose: self.verbose,
|
||||||
|
args: self.args,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser, Clone, Default)]
|
#[derive(Debug, Parser, Clone, Default)]
|
||||||
/// The options for the `wasmer run` subcommand
|
/// The options for the `wasmer run` subcommand
|
||||||
pub struct Run {
|
pub struct Run {
|
||||||
|
|||||||
7
lib/registry/Cargo.toml
Normal file
7
lib/registry/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "wasmer-registry"
|
||||||
|
version = "3.0.0-beta.2"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
dirs = "4.0.0"
|
||||||
13
lib/registry/graphql/queries/get_package.graphql
Normal file
13
lib/registry/graphql/queries/get_package.graphql
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
query GetPackageQuery ($name: String!) {
|
||||||
|
package: getPackage(name:$name) {
|
||||||
|
name
|
||||||
|
private
|
||||||
|
lastVersion {
|
||||||
|
version
|
||||||
|
distribution {
|
||||||
|
downloadUrl
|
||||||
|
}
|
||||||
|
manifest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
lib/registry/graphql/queries/get_package_version.graphql
Normal file
12
lib/registry/graphql/queries/get_package_version.graphql
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
query GetPackageVersionQuery ($name: String!, $version: String) {
|
||||||
|
packageVersion: getPackageVersion(name:$name, version:$version) {
|
||||||
|
package {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
version
|
||||||
|
distribution {
|
||||||
|
downloadUrl
|
||||||
|
}
|
||||||
|
manifest
|
||||||
|
}
|
||||||
|
}
|
||||||
5
lib/registry/graphql/queries/login.graphql
Normal file
5
lib/registry/graphql/queries/login.graphql
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
mutation LoginMutation($username: String!, $password: String!) {
|
||||||
|
tokenAuth(input: {username: $username, password: $password}) {
|
||||||
|
refreshToken
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
query TestIfRegistryPresent {
|
||||||
|
__typename
|
||||||
|
}
|
||||||
1401
lib/registry/graphql/schema.graphql
Normal file
1401
lib/registry/graphql/schema.graphql
Normal file
File diff suppressed because it is too large
Load Diff
0
lib/registry/src/commands/install.rs
Normal file
0
lib/registry/src/commands/install.rs
Normal file
0
lib/registry/src/commands/search.rs
Normal file
0
lib/registry/src/commands/search.rs
Normal file
53
lib/registry/src/lib.rs
Normal file
53
lib/registry/src/lib.rs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord)]
|
||||||
|
pub struct PackageDownloadInfo {
|
||||||
|
pub package: String,
|
||||||
|
pub command: String,
|
||||||
|
pub url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_command_local(name: &str) -> Result<PathBuf, String> {
|
||||||
|
Err(format!("unimplemented"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_package_local(name: &str, version: Option<&str>) -> Result<PathBuf, String> {
|
||||||
|
Err(format!("unimplemented"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn query_command_from_registry(name: &str) -> Result<PackageDownloadInfo, String> {
|
||||||
|
Err(format!("unimplemented"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn query_package_from_registry(
|
||||||
|
name: &str,
|
||||||
|
version: Option<&str>,
|
||||||
|
) -> Result<PackageDownloadInfo, String> {
|
||||||
|
Err(format!("unimplemented"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returs the path to the directory where all packages on this computer are being stored
|
||||||
|
pub fn get_global_install_dir(registry_host: &str) -> Option<PathBuf> {
|
||||||
|
Some(
|
||||||
|
dirs::home_dir()?
|
||||||
|
.join(".wasmer")
|
||||||
|
.join("checkouts")
|
||||||
|
.join(registry_host),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn download_and_unpack_targz(url: &str, target_path: &Path) -> Result<PathBuf, String> {
|
||||||
|
Err(format!("unimplemented"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn install_package(name: &str, version: Option<&str>) -> Result<PathBuf, String> {
|
||||||
|
Err(format!("unimplemented"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn test_if_registry_present(url: &str) -> Result<bool, String> {
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_all_available_registries() -> Result<Vec<String>, String> {
|
||||||
|
Ok(Vec::new())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user