Move the cli into it’s own library

This commit is contained in:
Syrus
2020-07-22 21:32:45 -07:00
parent ad58fea8ae
commit 8cab73e34f
29 changed files with 253 additions and 71 deletions

92
Cargo.lock generated
View File

@@ -2126,42 +2126,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "wasmer-bin"
version = "1.0.0-alpha.1"
dependencies = [
"anyhow",
"atty",
"blake3",
"build-deps",
"bytesize",
"cfg-if",
"colored",
"criterion",
"distance",
"glob",
"lazy_static",
"rustc_version",
"structopt",
"tempfile",
"test-generator",
"wasm-common",
"wasmer",
"wasmer-cache",
"wasmer-compiler",
"wasmer-compiler-cranelift",
"wasmer-compiler-llvm",
"wasmer-compiler-singlepass",
"wasmer-emscripten",
"wasmer-engine",
"wasmer-engine-dummy",
"wasmer-engine-jit",
"wasmer-engine-native",
"wasmer-wasi",
"wasmer-wasi-experimental-io-devices",
"wasmer-wast",
]
[[package]]
name = "wasmer-c-api"
version = "1.0.0-alpha.1"
@@ -2197,6 +2161,33 @@ dependencies = [
"wasmer",
]
[[package]]
name = "wasmer-cli"
version = "1.0.0-alpha.1"
dependencies = [
"anyhow",
"atty",
"bytesize",
"cfg-if",
"colored",
"distance",
"structopt",
"wasm-common",
"wasmer",
"wasmer-cache",
"wasmer-compiler",
"wasmer-compiler-cranelift",
"wasmer-compiler-llvm",
"wasmer-compiler-singlepass",
"wasmer-emscripten",
"wasmer-engine",
"wasmer-engine-jit",
"wasmer-engine-native",
"wasmer-wasi",
"wasmer-wasi-experimental-io-devices",
"wasmer-wast",
]
[[package]]
name = "wasmer-compiler"
version = "1.0.0-alpha.1"
@@ -2425,6 +2416,35 @@ dependencies = [
"wast 17.0.0",
]
[[package]]
name = "wasmer-workspace"
version = "1.0.0-alpha.1"
dependencies = [
"anyhow",
"blake3",
"build-deps",
"cfg-if",
"criterion",
"glob",
"lazy_static",
"rustc_version",
"tempfile",
"test-generator",
"wasm-common",
"wasmer",
"wasmer-cache",
"wasmer-compiler",
"wasmer-compiler-cranelift",
"wasmer-compiler-llvm",
"wasmer-compiler-singlepass",
"wasmer-engine",
"wasmer-engine-dummy",
"wasmer-engine-jit",
"wasmer-engine-native",
"wasmer-wasi",
"wasmer-wast",
]
[[package]]
name = "wasmparser"
version = "0.57.0"

View File

@@ -1,12 +1,12 @@
[package]
name = "wasmer-bin"
name = "wasmer-workspace"
version = "1.0.0-alpha.1"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
authors = ["Wasmer Engineering Team <engineering@wasmer.io>"]
repository = "https://github.com/wasmerio/wasmer"
description = "High-Performance WebAssembly Framework"
description = "Wasmer workspace"
license = "MIT"
include = [
"src/**/*",
"tests/**/*",
"Cargo.lock",
"Cargo.toml",
"LICENSE",
@@ -15,43 +15,44 @@ include = [
]
readme = "README.md"
edition = "2018"
default-run = "wasmer"
publish = false
autoexamples = false
[[bin]]
name = "wasmer"
path = "src/bin/wasmer.rs"
doc = false
[dependencies]
wasmer = { version = "1.0.0-alpha.1", path = "lib/api", default-features = false }
wasmer-compiler = { version = "1.0.0-alpha.1", path = "lib/compiler" }
wasmer-compiler-cranelift = { version = "1.0.0-alpha.1", path = "lib/compiler-cranelift", optional = true }
wasmer-compiler-singlepass = { version = "1.0.0-alpha.1", path = "lib/compiler-singlepass", optional = true }
wasmer-compiler-llvm = { version = "1.0.0-alpha.1", path = "lib/compiler-llvm", optional = true }
wasmer-emscripten = { version = "1.0.0-alpha.1", path = "lib/emscripten", optional = true }
wasmer-engine = { version = "1.0.0-alpha.1", path = "lib/engine" }
wasmer-engine-jit = { version = "1.0.0-alpha.1", path = "lib/engine-jit", optional = true }
wasmer-engine-native = { version = "1.0.0-alpha.1", path = "lib/engine-native", optional = true }
wasmer-wasi = { version = "1.0.0-alpha.1", path = "lib/wasi", optional = true }
wasmer-wasi-experimental-io-devices = { version = "1.0.0-alpha.1", path = "lib/wasi-experimental-io-devices", optional = true }
wasmer-wast = { version = "1.0.0-alpha.1", path = "tests/lib/wast", optional = true }
wasmer-cache = { version = "1.0.0-alpha.1", path = "lib/cache", optional = true }
wasm-common = { version = "1.0.0-alpha.1", path = "lib/wasm-common" }
atty = "0.2"
colored = "1.9"
anyhow = "1.0"
structopt = { version = "0.3", features = ["suggestions"] }
# For the function names autosuggestion
distance = "0.4"
# For the inspect subcommand
bytesize = "1.0"
cfg-if = "0.1"
[workspace]
members = [
"lib/api",
"lib/cache",
"lib/c-api",
"lib/cli",
"lib/compiler",
"lib/compiler-cranelift",
"lib/compiler-singlepass",
"lib/compiler-llvm",
"lib/emscripten",
"lib/engine",
"lib/engine-jit",
"lib/engine-native",
"lib/object",
"lib/vm",
"lib/wasi",
"lib/wasi-experimental-io-devices",
"lib/wasm-common",
"tests/lib/wast",
]
exclude = [
"lib/deprecated",
@@ -82,7 +83,7 @@ default = [
"native",
"cache",
"wasi",
"emscripten",
# "emscripten",
]
engine = []
jit = [
@@ -96,17 +97,13 @@ native = [
cache = ["wasmer-cache"]
wast = ["wasmer-wast"]
wasi = ["wasmer-wasi"]
emscripten = ["wasmer-emscripten"]
# emscripten = ["wasmer-emscripten"]
wat = ["wasmer/wat"]
compiler = [
"wasmer-compiler/translator",
"wasmer-engine-jit/compiler",
"wasmer-engine-native/compiler"
]
experimental-io-devices = [
"wasmer-wasi-experimental-io-devices",
"wasi"
]
singlepass = [
"wasmer-compiler-singlepass",
"compiler",
@@ -131,9 +128,6 @@ test-llvm = [
"llvm",
]
# [profile.release]
# lto = "fat"
[[bench]]
name = "static_and_dynamic_functions"
harness = false

View File

@@ -55,7 +55,7 @@ bench:
cargo bench $(compiler_features)
build-wasmer:
cargo build --release $(compiler_features)
cargo build --release --manifest-path lib/cli/Cargo.toml $(compiler_features)
WAPM_VERSION = v0.5.0
build-wapm:
@@ -191,8 +191,8 @@ package: package-wapm package-wasmer package-capi
cp ATTRIBUTIONS.md package/ATTRIBUTIONS
mkdir -p dist
ifeq ($(OS), Windows_NT)
iscc src/windows-installer/wasmer.iss
cp src/windows-installer/WasmerInstaller.exe dist/wasmer-windows.exe
iscc scripts/windows-installer/wasmer.iss
cp scripts/windows-installer/WasmerInstaller.exe dist/wasmer-windows.exe
else
cp LICENSE package/LICENSE
cp ATTRIBUTIONS.md package/ATTRIBUTIONS

97
lib/cli/Cargo.toml Normal file
View File

@@ -0,0 +1,97 @@
[package]
name = "wasmer-cli"
version = "1.0.0-alpha.1"
authors = ["Wasmer Engineering Team <engineering@wasmer.io>"]
repository = "https://github.com/wasmerio/wasmer"
description = "Wasmer CLI"
license = "MIT"
include = [
"src/**/*",
"Cargo.lock",
"Cargo.toml",
"LICENSE",
"Makefile",
"/README.md"
]
readme = "README.md"
edition = "2018"
default-run = "wasmer"
[[bin]]
name = "wasmer"
path = "src/bin/wasmer.rs"
doc = false
[dependencies]
wasmer = { version = "1.0.0-alpha.1", path = "../api", default-features = false }
wasmer-compiler = { version = "1.0.0-alpha.1", path = "../compiler" }
wasmer-compiler-cranelift = { version = "1.0.0-alpha.1", path = "../compiler-cranelift", optional = true }
wasmer-compiler-singlepass = { version = "1.0.0-alpha.1", path = "../compiler-singlepass", optional = true }
wasmer-compiler-llvm = { version = "1.0.0-alpha.1", path = "../compiler-llvm", optional = true }
wasmer-emscripten = { version = "1.0.0-alpha.1", path = "../emscripten", optional = true }
wasmer-engine = { version = "1.0.0-alpha.1", path = "../engine" }
wasmer-engine-jit = { version = "1.0.0-alpha.1", path = "../engine-jit", optional = true }
wasmer-engine-native = { version = "1.0.0-alpha.1", path = "../engine-native", optional = true }
wasmer-wasi = { version = "1.0.0-alpha.1", path = "../wasi", optional = true }
wasmer-wasi-experimental-io-devices = { version = "1.0.0-alpha.1", path = "../wasi-experimental-io-devices", optional = true }
wasmer-wast = { version = "1.0.0-alpha.1", path = "../../tests/lib/wast", optional = true }
wasmer-cache = { version = "1.0.0-alpha.1", path = "../cache", optional = true }
wasm-common = { version = "1.0.0-alpha.1", path = "../wasm-common" }
atty = "0.2"
colored = "1.9"
anyhow = "1.0"
structopt = { version = "0.3", features = ["suggestions"] }
# For the function names autosuggestion
distance = "0.4"
# For the inspect subcommand
bytesize = "1.0"
cfg-if = "0.1"
[features]
# Don't add the compiler features in default, please add them on the Makefile
# since we might want to autoconfigure them depending on the availability on the host.
default = [
"wat",
"wast",
"jit",
"native",
"cache",
"wasi",
"emscripten",
]
engine = []
jit = [
"wasmer-engine-jit",
"engine",
]
native = [
"wasmer-engine-native",
"engine",
]
cache = ["wasmer-cache"]
wast = ["wasmer-wast"]
wasi = ["wasmer-wasi"]
emscripten = ["wasmer-emscripten"]
wat = ["wasmer/wat"]
compiler = [
"wasmer-compiler/translator",
"wasmer-engine-jit/compiler",
"wasmer-engine-native/compiler"
]
experimental-io-devices = [
"wasmer-wasi-experimental-io-devices",
"wasi"
]
singlepass = [
"wasmer-compiler-singlepass",
"compiler",
]
cranelift = [
"wasmer-compiler-cranelift",
"compiler",
]
llvm = [
"wasmer-compiler-llvm",
"compiler",
]

71
lib/cli/README.md Normal file
View File

@@ -0,0 +1,71 @@
# Wasmer CLI
This crate is the Wasmer CLI.
The recommended way to install Wasmer is via your shell [following the instructions in our repo](https://github.com/wasmerio/wasmer-reborn#1-install-wasmer).
You can install it also via Cargo:
```bash
cargo install wasmer-cli
```
Or by running it inside the codebase:
```bash
cargo build --release
```
> Note: installing Wasmer via Cargo (or manual install) will not install
> the WAPM cli. If you want to use them together, please use the default shell installer.
## Features
The Wasmer supports the following features:
* `wat` (default): support for executing WebAssembly text files.
* `wast`(default): support for running wast test files.
* `jit` (default): support for the [JIT engine].
* `native` (default): support for the [Native engine].
* `cache` (default): support or automatically caching compiled artifacts.
* `wasi` (default): support for [WASI].
* `emscripten` (default): support for [Emscripten].
* `singlepass`: support for the [Singlepass compiler].
* `cranelift`: support for the [Cranelift compiler].
* `llvm`: support for the [LLVM compiler].
[JIT Engine]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/engine-jit/
[Native Engine]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/engine-native/
[WASI]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/wasi/
[Emscripten]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/emscripten/
[Singlepass compiler]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/compiler-singlepass/
[Cranelift compiler]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/compiler-cranelift/
[LLVM compiler]: https://github.com/wasmerio/wasmer-reborn/tree/master/lib/compiler-llvm/
## CLI commands
Once you have Wasmer installed, you can start executing WebAssembly files easily:
Get the current Wasmer version:
```bash
wasmer -V
```
Execute a WebAssembly file:
```bash
wasmer run myfile.wasm
```
Compile a WebAssembly file:
```bash
wasmer compile myfile.wasm -o myfile.so --native
```
Run a compiled WebAssembly file (fastest):
```bash
wasmer run myfile.so
```

View File

@@ -1,8 +1,8 @@
use anyhow::Result;
#[cfg(feature = "wast")]
use wasmer_bin::commands::Wast;
use wasmer_bin::commands::{Cache, Compile, Config, Inspect, Run, SelfUpdate, Validate};
use wasmer_bin::error::PrettyError;
use wasmer_cli::commands::Wast;
use wasmer_cli::commands::{Cache, Compile, Config, Inspect, Run, SelfUpdate, Validate};
use wasmer_cli::error::PrettyError;
use structopt::{clap::ErrorKind, StructOpt};

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB