From 88b4093646f60e680dc3fa3be9877c2ad77257a0 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 12 Jan 2021 13:07:07 -0800 Subject: [PATCH 1/4] Add packaging of headless wasmer to CI --- .github/workflows/main.yaml | 22 ++++++++++++++++++++++ Makefile | 18 ++++++++++++++++-- Xargo.toml | 2 ++ lib/cli/Cargo.toml | 2 ++ lib/cli/src/bin/wasmer.rs | 19 +++++++++++++++++-- lib/cli/src/commands.rs | 5 ++++- 6 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 Xargo.toml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index be03ee03f62..3b273a37d44 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -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 diff --git a/Makefile b/Makefile index ae9a8a1c6c4..e9d9fc77484 100644 --- a/Makefile +++ b/Makefile @@ -54,6 +54,7 @@ endif # Using filter as a logical OR # https://stackoverflow.com/questions/7656425/makefile-ifeq-logical-or use_system_ffi = +cross_compiling_to_mac_aarch64 = ifneq (,$(filter $(ARCH),aarch64 arm64)) test_compilers_engines += cranelift-jit ifneq (, $(findstring llvm,$(compilers))) @@ -62,6 +63,7 @@ ifneq (,$(filter $(ARCH),aarch64 arm64)) # if we are in macos arm64, we use the system libffi for the capi ifeq ($(UNAME_S), Darwin) use_system_ffi = yes + cross_compiling_to_mac_aarch64 = yes endif endif @@ -121,7 +123,7 @@ build-wasmer-debug: 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 ;\ + xargo build -v --target $$HOST_TARGET --release --manifest-path=lib/cli/Cargo.toml --no-default-features --features headless-minimal ;\ strip target/$$HOST_TARGET/release/wasmer WAPM_VERSION = master # v0.5.0 @@ -326,6 +328,18 @@ ifeq ($(UNAME_S), Darwin) endif endif +package-minimal-headless-wasmer: +ifdef cross_compiling_to_mac_aarch64 + if [ -f "target/aarch64-apple-darwin/release/wasmer" ]; then \ + cp target/aarch64-apple-darwin/release/wasmer package/bin/wasmer-headless ;\ + fi +else + HOST_TARGET=$$(rustup show | grep 'Default host: ' | cut -d':' -f2 | tr -d ' ') ;\ + if [ -f "target/$$HOST_TARGET/release/wasmer" ]; then \ + cp target/$$HOST_TARGET/release/wasmer package/bin/wasmer-headless ;\ + fi +endif + package-wasmer: mkdir -p "package/bin" ifeq ($(OS), Windows_NT) @@ -369,7 +383,7 @@ package-docs: build-docs build-docs-capi echo '' > package/docs/index.html echo '' > 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 diff --git a/Xargo.toml b/Xargo.toml new file mode 100644 index 00000000000..01cf5eb2f4f --- /dev/null +++ b/Xargo.toml @@ -0,0 +1,2 @@ +[dependencies] +std = {default-features=false, features=["panic_immediate_abort"]} diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index f8614795e57..bb98a574769 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -107,3 +107,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"] diff --git a/lib/cli/src/bin/wasmer.rs b/lib/cli/src/bin/wasmer.rs index e0e51ed2d5b..79ff745e28a 100644 --- a/lib/cli/src/bin/wasmer.rs +++ b/lib/cli/src/bin/wasmer.rs @@ -1,15 +1,28 @@ use anyhow::Result; +#[cfg(feature = "compile")] +use wasmer_cli::commands::Compile; #[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::commands::{Cache, 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)] +#[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 @@ -25,6 +38,7 @@ enum WasmerCLIOptions { Validate(Validate), /// Compile a WebAssembly binary + #[cfg(feature = "compiler")] #[structopt(name = "compile")] Compile(Compile), @@ -59,6 +73,7 @@ impl WasmerCLIOptions { 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(), diff --git a/lib/cli/src/commands.rs b/lib/cli/src/commands.rs index 7107150ccf4..f3791ef61e2 100644 --- a/lib/cli/src/commands.rs +++ b/lib/cli/src/commands.rs @@ -1,5 +1,6 @@ //! The commands available in the Wasmer binary. mod cache; +#[cfg(feature = "compile")] mod compile; mod config; #[cfg(all(feature = "object-file", feature = "compiler"))] @@ -11,8 +12,10 @@ mod validate; #[cfg(feature = "wast")] mod wast; +#[cfg(feature = "compile")] +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::*}; From ba52b4553ecbb3dc189028facbf2c29b722da345 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 12 Jan 2021 13:10:11 -0800 Subject: [PATCH 2/4] Fix typo feature "compile" -> "compiler" --- lib/cli/src/bin/wasmer.rs | 2 +- lib/cli/src/commands.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cli/src/bin/wasmer.rs b/lib/cli/src/bin/wasmer.rs index 79ff745e28a..fe227411819 100644 --- a/lib/cli/src/bin/wasmer.rs +++ b/lib/cli/src/bin/wasmer.rs @@ -1,5 +1,5 @@ use anyhow::Result; -#[cfg(feature = "compile")] +#[cfg(feature = "compiler")] use wasmer_cli::commands::Compile; #[cfg(all(feature = "object-file", feature = "compiler"))] use wasmer_cli::commands::CreateExe; diff --git a/lib/cli/src/commands.rs b/lib/cli/src/commands.rs index f3791ef61e2..5e80631d7e0 100644 --- a/lib/cli/src/commands.rs +++ b/lib/cli/src/commands.rs @@ -1,6 +1,6 @@ //! The commands available in the Wasmer binary. mod cache; -#[cfg(feature = "compile")] +#[cfg(feature = "compiler")] mod compile; mod config; #[cfg(all(feature = "object-file", feature = "compiler"))] @@ -12,7 +12,7 @@ mod validate; #[cfg(feature = "wast")] mod wast; -#[cfg(feature = "compile")] +#[cfg(feature = "compiler")] pub use compile::*; #[cfg(all(feature = "object-file", feature = "compiler"))] pub use create_exe::*; From ecc15b5c8c264a4e1d9af137218479bb1f92225a Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 12 Jan 2021 13:24:15 -0800 Subject: [PATCH 3/4] Ensure `panic=abort` is always true when building with xargo --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e9d9fc77484..325d9efea9c 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,7 @@ build-wasmer-debug: 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 headless-minimal ;\ + RUSTFLAGS="-C panic=abort" xargo build -v --target $$HOST_TARGET --release --manifest-path=lib/cli/Cargo.toml --no-default-features --features headless-minimal ;\ strip target/$$HOST_TARGET/release/wasmer WAPM_VERSION = master # v0.5.0 From f0c7f5bc437a61c37fd22222addc53b3efe7988b Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 12 Jan 2021 13:32:05 -0800 Subject: [PATCH 4/4] Temporarily unconditionally build headless wasmer --- .github/workflows/main.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 3b273a37d44..fb21b1f56b7 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -198,7 +198,7 @@ jobs: target: ${{ matrix.target }} override: true components: "rust-src" - if: needs.setup.outputs.DOING_RELEASE == '1' + #if: needs.setup.outputs.DOING_RELEASE == '1' - name: Build Minimal Wasmer Headless run: | echo "\n[profile.release] @@ -212,7 +212,7 @@ incremental = false codegen-units = 1 rpath = false" >> Cargo.toml make build-wasmer-headless-minimal - if: needs.setup.outputs.DOING_RELEASE == '1' + #if: needs.setup.outputs.DOING_RELEASE == '1' - name: Copy target binaries run: | mkdir -p target/release