Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add packaging of headless wasmer to CI #2010

Merged
merged 16 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,28 @@ jobs:
run: |
make build-wapm
if: needs.setup.outputs.DOING_RELEASE == '1'
- name: Install Nightly Rust for Headless
uses: actions-rs/toolchain@v1
with:
toolchain: 'nightly-2020-12-22'
target: ${{ matrix.target }}
override: true
components: "rust-src"
if: needs.setup.outputs.DOING_RELEASE == '1'
- name: Build Minimal Wasmer Headless
run: |
echo "\n[profile.release]
opt-level = 'z'
debug = false
debug-assertions = false
overflow-checks = false
lto = true
panic = 'abort'
incremental = false
codegen-units = 1
rpath = false" >> Cargo.toml
make build-wasmer-headless-minimal
if: needs.setup.outputs.DOING_RELEASE == '1'
- name: Copy target binaries
run: |
mkdir -p target/release
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This release includes a breaking change in the API (changing the trait `enumset:
This change is unlikely to affect any users of `wasmer`, but if it does please change uses of the `enumset` crate to the `wasmer_enumset` crate where possible.

### Added
- [#2010](https://github.com/wasmerio/wasmer/pull/2010) A new, experimental, minified build of `wasmer` called `wasmer-headless` will now be included with releases. `wasmer-headless` is the `wasmer` VM without any compilers attached, so it can only run precompiled Wasm modules.
- [#2005](https://github.com/wasmerio/wasmer/pull/2005) Added the arguments `alias` and `optional` to `WasmerEnv` derive's `export` attribute.

### Changed
Expand Down
24 changes: 17 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ endif
compiler_features_spaced := $(foreach compiler,$(compilers),$(compiler))
compiler_features := --features "$(compiler_features_spaced)"

HOST_TARGET=$(shell rustup show | grep 'Default host: ' | cut -d':' -f2 | tr -d ' ')

$(info Host target: $(bold)$(green)$(HOST_TARGET)$(reset))
$(info Available compilers: $(bold)$(green)${compilers}$(reset))
$(info Compilers features: $(bold)$(green)${compiler_features}$(reset))
$(info Available compilers + engines for test: $(bold)$(green)${test_compilers_engines}$(reset))
Expand All @@ -101,10 +104,10 @@ bench:
cargo bench $(compiler_features)

build-wasmer:
cargo build --release --manifest-path lib/cli/Cargo.toml $(compiler_features)
cargo build --release --manifest-path lib/cli/Cargo.toml $(compiler_features) --bin wasmer

build-wasmer-debug:
cargo build --manifest-path lib/cli/Cargo.toml $(compiler_features)
cargo build --manifest-path lib/cli/Cargo.toml $(compiler_features) --bin wasmer

# For best results ensure the release profile looks like the following
# in Cargo.toml:
Expand All @@ -119,10 +122,12 @@ build-wasmer-debug:
# codegen-units = 1
# rpath = false
build-wasmer-headless-minimal:
HOST_TARGET=$$(rustup show | grep 'Default host: ' | cut -d':' -f2 | tr -d ' ') ;\
echo $$HOST_TARGET ;\
xargo build -v --target $$HOST_TARGET --release --manifest-path=lib/cli/Cargo.toml --no-default-features --features disable-all-logging,native,wasi ;\
strip target/$$HOST_TARGET/release/wasmer
RUSTFLAGS="-C panic=abort" xargo build -v --target $(HOST_TARGET) --release --manifest-path=lib/cli/Cargo.toml --no-default-features --features headless-minimal --bin wasmer-headless
ifeq ($(UNAME_S), Darwin)
strip -u target/$(HOST_TARGET)/release/wasmer-headless
else
strip --strip-unneeded target/$(HOST_TARGET)/release/wasmer-headless
endif

WAPM_VERSION = master # v0.5.0
get-wapm:
Expand Down Expand Up @@ -326,6 +331,11 @@ ifeq ($(UNAME_S), Darwin)
endif
endif

package-minimal-headless-wasmer:
if [ -f "target/$(HOST_TARGET)/release/wasmer-headless" ]; then \
cp target/$(HOST_TARGET)/release/wasmer-headless package/bin ;\
fi

package-wasmer:
mkdir -p "package/bin"
ifeq ($(OS), Windows_NT)
Expand Down Expand Up @@ -369,7 +379,7 @@ package-docs: build-docs build-docs-capi
echo '<!-- Build $(SOURCE_VERSION) --><meta http-equiv="refresh" content="0; url=rust/wasmer_vm/index.html">' > package/docs/index.html
echo '<!-- Build $(SOURCE_VERSION) --><meta http-equiv="refresh" content="0; url=wasmer_vm/index.html">' > package/docs/crates/index.html

package: package-wapm package-wasmer package-capi
package: package-wapm package-wasmer package-minimal-headless-wasmer package-capi

distribution: package
cp LICENSE package/LICENSE
Expand Down
2 changes: 2 additions & 0 deletions Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[dependencies]
std = {default-features=false, features=["panic_immediate_abort"]}
8 changes: 8 additions & 0 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ name = "wasmer"
path = "src/bin/wasmer.rs"
doc = false

[[bin]]
name = "wasmer-headless"
path = "src/bin/wasmer_headless.rs"
doc = false
required-features = ["headless"]

[dependencies]
wasmer = { version = "1.0.1", path = "../api", default-features = false }
wasmer-compiler = { version = "1.0.1", path = "../compiler" }
Expand Down Expand Up @@ -107,3 +113,5 @@ llvm = [
]
debug = ["fern", "log", "wasmer-wasi/logging"]
disable-all-logging = ["wasmer-wasi/disable-all-logging"]
headless = []
headless-minimal = ["headless", "disable-all-logging", "wasi", "native", "jit"]
100 changes: 2 additions & 98 deletions lib/cli/src/bin/wasmer.rs
Original file line number Diff line number Diff line change
@@ -1,101 +1,5 @@
use anyhow::Result;
#[cfg(all(feature = "object-file", feature = "compiler"))]
use wasmer_cli::commands::CreateExe;
#[cfg(feature = "wast")]
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};

#[derive(Debug, StructOpt)]
#[structopt(name = "wasmer", about = "WebAssembly standalone runtime.", author)]
/// The options for the wasmer Command Line Interface
enum WasmerCLIOptions {
/// Run a WebAssembly file. Formats accepted: wasm, wat
#[structopt(name = "run")]
Run(Run),

/// Wasmer cache
#[structopt(name = "cache")]
Cache(Cache),

/// Validate a WebAssembly binary
#[structopt(name = "validate")]
Validate(Validate),

/// Compile a WebAssembly binary
#[structopt(name = "compile")]
Compile(Compile),

/// Compile a WebAssembly binary into a native executable
#[cfg(all(feature = "object-file", feature = "compiler"))]
#[structopt(name = "create-exe")]
CreateExe(CreateExe),

/// Get various configuration information needed
/// to compile programs which use Wasmer
#[structopt(name = "config")]
Config(Config),

/// Update wasmer to the latest version
#[structopt(name = "self-update")]
SelfUpdate(SelfUpdate),

/// Inspect a WebAssembly file
#[structopt(name = "inspect")]
Inspect(Inspect),

/// Run spec testsuite
#[cfg(feature = "wast")]
#[structopt(name = "wast")]
Wast(Wast),
}

impl WasmerCLIOptions {
fn execute(&self) -> Result<()> {
match self {
Self::Run(options) => options.execute(),
Self::SelfUpdate(options) => options.execute(),
Self::Cache(cache) => cache.execute(),
Self::Validate(validate) => validate.execute(),
Self::Compile(compile) => compile.execute(),
#[cfg(all(feature = "object-file", feature = "compiler"))]
Self::CreateExe(create_exe) => create_exe.execute(),
Self::Config(config) => config.execute(),
Self::Inspect(inspect) => inspect.execute(),
#[cfg(feature = "wast")]
Self::Wast(wast) => wast.execute(),
}
}
}
use wasmer_cli::cli::wasmer_main;

fn main() {
// We allow windows to print properly colors
#[cfg(windows)]
colored::control::set_virtual_terminal(true).unwrap();

// We try to run wasmer with the normal arguments.
// Eg. `wasmer <SUBCOMMAND>`
// In case that fails, we fallback trying the Run subcommand directly.
// Eg. `wasmer myfile.wasm --dir=.`
let args = std::env::args().collect::<Vec<_>>();
let command = args.get(1);
let options = match command.unwrap_or(&"".to_string()).as_ref() {
"cache" | "compile" | "config" | "create-exe" | "help" | "inspect" | "run"
| "self-update" | "validate" | "wast" => WasmerCLIOptions::from_args(),
_ => {
WasmerCLIOptions::from_iter_safe(args.iter()).unwrap_or_else(|e| {
match e.kind {
// This fixes a issue that:
// 1. Shows the version twice when doing `wasmer -V`
// 2. Shows the run help (instead of normal help) when doing `wasmer --help`
ErrorKind::VersionDisplayed | ErrorKind::HelpDisplayed => e.exit(),
_ => WasmerCLIOptions::Run(Run::from_args()),
}
})
}
};

PrettyError::report(options.execute());
wasmer_main();
}
5 changes: 5 additions & 0 deletions lib/cli/src/bin/wasmer_headless.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use wasmer_cli::cli::wasmer_main;

fn main() {
wasmer_main();
}
119 changes: 119 additions & 0 deletions lib/cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//! The logic for the Wasmer CLI tool.
#[cfg(feature = "compiler")]
use crate::commands::Compile;
#[cfg(all(feature = "object-file", feature = "compiler"))]
use crate::commands::CreateExe;
#[cfg(feature = "wast")]
use crate::commands::Wast;
use crate::commands::{Cache, Config, Inspect, Run, SelfUpdate, Validate};
use crate::error::PrettyError;
use anyhow::Result;

use structopt::{clap::ErrorKind, StructOpt};

#[derive(Debug, StructOpt)]
#[cfg_attr(
not(feature = "headless"),
structopt(name = "wasmer", about = "WebAssembly standalone runtime.", author)
)]
#[cfg_attr(
feature = "headless",
structopt(
name = "wasmer-headless",
about = "Headless WebAssembly standalone runtime.",
author
)
)]
/// The options for the wasmer Command Line Interface
enum WasmerCLIOptions {
/// Run a WebAssembly file. Formats accepted: wasm, wat
#[structopt(name = "run")]
Run(Run),

/// Wasmer cache
#[structopt(name = "cache")]
Cache(Cache),

/// Validate a WebAssembly binary
#[structopt(name = "validate")]
Validate(Validate),

/// Compile a WebAssembly binary
#[cfg(feature = "compiler")]
#[structopt(name = "compile")]
Compile(Compile),

/// Compile a WebAssembly binary into a native executable
#[cfg(all(feature = "object-file", feature = "compiler"))]
#[structopt(name = "create-exe")]
CreateExe(CreateExe),

/// Get various configuration information needed
/// to compile programs which use Wasmer
#[structopt(name = "config")]
Config(Config),

/// Update wasmer to the latest version
#[structopt(name = "self-update")]
SelfUpdate(SelfUpdate),

/// Inspect a WebAssembly file
#[structopt(name = "inspect")]
Inspect(Inspect),

/// Run spec testsuite
#[cfg(feature = "wast")]
#[structopt(name = "wast")]
Wast(Wast),
}

impl WasmerCLIOptions {
fn execute(&self) -> Result<()> {
match self {
Self::Run(options) => options.execute(),
Self::SelfUpdate(options) => options.execute(),
Self::Cache(cache) => cache.execute(),
Self::Validate(validate) => validate.execute(),
#[cfg(feature = "compiler")]
Self::Compile(compile) => compile.execute(),
#[cfg(all(feature = "object-file", feature = "compiler"))]
Self::CreateExe(create_exe) => create_exe.execute(),
Self::Config(config) => config.execute(),
Self::Inspect(inspect) => inspect.execute(),
#[cfg(feature = "wast")]
Self::Wast(wast) => wast.execute(),
}
}
}

/// The main function for the Wasmer CLI tool.
pub fn wasmer_main() {
// We allow windows to print properly colors
#[cfg(windows)]
colored::control::set_virtual_terminal(true).unwrap();

// We try to run wasmer with the normal arguments.
// Eg. `wasmer <SUBCOMMAND>`
// In case that fails, we fallback trying the Run subcommand directly.
// Eg. `wasmer myfile.wasm --dir=.`
let args = std::env::args().collect::<Vec<_>>();
let command = args.get(1);
let options = match command.unwrap_or(&"".to_string()).as_ref() {
"cache" | "compile" | "config" | "create-exe" | "help" | "inspect" | "run"
| "self-update" | "validate" | "wast" => WasmerCLIOptions::from_args(),
_ => {
WasmerCLIOptions::from_iter_safe(args.iter()).unwrap_or_else(|e| {
match e.kind {
// This fixes a issue that:
// 1. Shows the version twice when doing `wasmer -V`
// 2. Shows the run help (instead of normal help) when doing `wasmer --help`
ErrorKind::VersionDisplayed | ErrorKind::HelpDisplayed => e.exit(),
_ => WasmerCLIOptions::Run(Run::from_args()),
}
})
}
};

PrettyError::report(options.execute());
}
5 changes: 4 additions & 1 deletion lib/cli/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! The commands available in the Wasmer binary.
mod cache;
#[cfg(feature = "compiler")]
mod compile;
mod config;
#[cfg(all(feature = "object-file", feature = "compiler"))]
Expand All @@ -11,8 +12,10 @@ mod validate;
#[cfg(feature = "wast")]
mod wast;

#[cfg(feature = "compiler")]
pub use compile::*;
#[cfg(all(feature = "object-file", feature = "compiler"))]
pub use create_exe::*;
#[cfg(feature = "wast")]
pub use wast::*;
pub use {cache::*, compile::*, config::*, inspect::*, run::*, self_update::*, validate::*};
pub use {cache::*, config::*, inspect::*, run::*, self_update::*, validate::*};
1 change: 1 addition & 0 deletions lib/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod common;
#[macro_use]
pub mod error;
pub mod c_gen;
pub mod cli;
#[cfg(feature = "debug")]
pub mod logging;
pub mod store;
Expand Down