From 8041f03bc4f11bb9f98f20205f3e42743b1b77ca Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Mon, 22 Feb 2021 13:24:09 +0900 Subject: [PATCH 1/8] wasmer-cli: refuse to build if not at least one compiler is enabled --- lib/cli/src/bin/wasmer.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/cli/src/bin/wasmer.rs b/lib/cli/src/bin/wasmer.rs index ccd9aa9bf80..8f781e1f8cd 100644 --- a/lib/cli/src/bin/wasmer.rs +++ b/lib/cli/src/bin/wasmer.rs @@ -1,5 +1,10 @@ use wasmer_cli::cli::wasmer_main; +#[cfg(not(any(feature = "cranelift", feature = "singlepass", feature = "llvm")))] +compile_error!( + "Either enable at least one compiler, or compile the wasmer-headless binary instead" +); + fn main() { wasmer_main(); } From 80ec06ffab9d7af017a5a5490d153a2230f9374a Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Mon, 22 Feb 2021 13:27:00 +0900 Subject: [PATCH 2/8] Allow preconfiguring WASMER_DIR at build time --- lib/cli/Cargo.toml | 1 + lib/cli/build.rs | 4 ++++ lib/cli/src/commands/config.rs | 14 ++++++++++---- lib/cli/src/commands/create_exe.rs | 8 +++++++- 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 lib/cli/build.rs diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 5d9b8beffe0..4e0916adcf8 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -10,6 +10,7 @@ license = "MIT" readme = "README.md" edition = "2018" default-run = "wasmer" +build = "build.rs" [[bin]] name = "wasmer" diff --git a/lib/cli/build.rs b/lib/cli/build.rs new file mode 100644 index 00000000000..36fe64763ed --- /dev/null +++ b/lib/cli/build.rs @@ -0,0 +1,4 @@ +pub fn main() { + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-env-changed=WASMER_INSTALL_PREFIX"); +} diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 84c25c088ec..0550f8e6f8c 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -45,10 +45,16 @@ impl Config { } fn inner_execute(&self) -> Result<()> { let key = "WASMER_DIR"; - let wasmer_dir = env::var(key).context(format!( - "failed to retrieve the {} environment variables", - key - ))?; + let wasmer_dir = env::var(key) + .or_else(|e| { + option_env!("WASMER_INSTALL_PREFIX") + .map(str::to_string) + .ok_or(e) + }) + .context(format!( + "failed to retrieve the {} environment variables", + key + ))?; let prefix = PathBuf::from(wasmer_dir); diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index fbc6a8aa18d..7a70bd7fc56 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -155,7 +155,13 @@ fn generate_header(header_file_src: &[u8]) -> anyhow::Result<()> { fn get_wasmer_dir() -> anyhow::Result { Ok(PathBuf::from( - env::var("WASMER_DIR").context("Trying to read env var `WASMER_DIR`")?, + env::var("WASMER_DIR") + .or_else(|e| { + option_env!("WASMER_INSTALL_PREFIX") + .map(str::to_string) + .ok_or(e) + }) + .context("Trying to read env var `WASMER_DIR`")?, )) } From a9537c91b7b8a2109f47bb562aeba9a9f34c770f Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Mon, 22 Feb 2021 13:30:26 +0900 Subject: [PATCH 3/8] Makefile: add install target --- Makefile | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ae7874fbd1f..ef80e65714f 100644 --- a/Makefile +++ b/Makefile @@ -323,11 +323,13 @@ $(info --------------) $(info ) $(info ) - ############ # Building # ############ +# Not really "all", just the default target that builds enough so make install will go through +all: build-wasmer build-capi + bench: cargo bench $(compiler_features) @@ -657,6 +659,43 @@ endif tar -C package -zcvf wasmer.tar.gz bin lib include LICENSE ATTRIBUTIONS mv wasmer.tar.gz dist/ +######################## +# (Distro-) Installing # +######################## + +DESTDIR ?= /usr/local + +install: install-wasmer install-capi-headers install-capi-lib install-capi-staticlib install-pkgconfig install-misc + +install-wasmer: + install -Dm755 target/release/wasmer $(DESTDIR)/bin/wasmer + +install-capi-headers: + for header in lib/c-api/*.{h,hh}; do install -Dm644 "$$header" $(DESTDIR)/include/$$(basename $$header); done + install -Dm644 lib/c-api/doc/deprecated/index.md $(DESTDIR)/include/wasmer-README.md + +install-capi-lib: + pkgver=$$(target/release/wasmer --version | cut -d\ -f2) && \ + shortver="$${pkgver%.*}" && \ + majorver="$${shortver%.*}" && \ + install -Dm755 target/release/libwasmer_c_api.so "$(DESTDIR)/lib/libwasmer.so.$$pkgver" && \ + ln -sf "libwasmer.so.$$pkgver" "$(DESTDIR)/lib/libwasmer.so.$$shortver" && \ + ln -sf "libwasmer.so.$$pkgver" "$(DESTDIR)/lib/libwasmer.so.$$majorver" && \ + ln -sf "libwasmer.so.$$pkgver" "$(DESTDIR)/lib/libwasmer.so" + +install-capi-staticlib: + install -Dm644 target/release/libwasmer_c_api.a "$(DESTDIR)/lib/libwasmer.a" + +install-misc: + install -Dm644 LICENSE "$(DESTDIR)"/share/licenses/wasmer/LICENSE + +install-pkgconfig: + unset WASMER_DIR # Make sure WASMER_INSTALL_PREFIX is set during build + target/release/wasmer config --pkg-config | install -Dm644 /dev/stdin "$(DESTDIR)"/lib/pkgconfig/wasmer.pc + +install-wasmer-headless-minimal: + install -Dm755 target/release/wasmer $(DESTDIR)/bin/wasmer-headless + ################# # Miscellaneous # ################# From a0800cb0142459bb47553106e1d196c1b1809824 Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Mon, 22 Feb 2021 13:31:11 +0900 Subject: [PATCH 4/8] Document some suggestions for distro packaging --- PACKAGING.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 PACKAGING.md diff --git a/PACKAGING.md b/PACKAGING.md new file mode 100644 index 00000000000..cc45fe60a25 --- /dev/null +++ b/PACKAGING.md @@ -0,0 +1,18 @@ +## Wasmer distro packaging notes + +* Where possible, do not directly invoke cargo, but use the supplied Makefile + * wasmer has several compiler backends and the Makefile autodetects whether to enable llvm and singlepass. + Set `ENABLE_{CRANELIFT,LLVM,SINGLEPASS}=1` to build the full set or fail trying + * Set `WASMER_CAPI_USE_SYSTEM_LIBFFI=1` to force dynamic linking of libffi on the shared library + * `make install` respects `DESTDIR`, but `prefix` must be configured as e.g. `WASMER_INSTALL_PREFIX=/usr make all` +* In case you must build/install directly with cargo, make sure to enable at least one compiler backend feature + * Beware that compiling with `cargo build --workspace/--all --features ...` will not enable features on the subcrates in the workspace and result in a headless wasmer binary that can not run wasm files directly. +* If you split the package into several subpackages, beware that the create-exe command of wasmer requires `libwasmer.a` to be installed at `$WASMER_INSTALL_PREFIX/lib/libwasmer.a`. + Suggestion for splitting: + * `wasmer` and `wasmer-headless`, containing the respective executables + * `wasmer-headless` contains a subset of `wasmer`'s functionality and should only be packaged when splitting - it must be built explicitly with `make build-wasmer-headless-minimal insteall-wasmer-headless-minimal` + * `libwasmer`, containing `libwasmer.so*` + * `libwasmer-dev`, containging the header files and a `.pc` file + * `libwasmer-static`, containing `libwasmer.a` + +The wasmer distro packaging story is still in its infancy, so feedback is very welcome. From 59b55449967e925e4c0d0c0b7edf7a60824ba779 Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Thu, 25 Feb 2021 18:10:03 +0900 Subject: [PATCH 5/8] Fix 8041f03bc: enable compilers during tests, make sure make test-packages lint-packages passes --- Makefile | 4 ++-- lib/cli/src/commands/create_exe.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ef80e65714f..33e68a1b012 100644 --- a/Makefile +++ b/Makefile @@ -495,7 +495,7 @@ test-packages: cargo test -p wasmer-engine-native --release --no-default-features cargo test -p wasmer-engine-jit --release --no-default-features cargo test -p wasmer-compiler --release - cargo test -p wasmer-cli --release + cargo test --manifest-path lib/cli/Cargo.toml $(compiler_features) --release cargo test -p wasmer-cache --release cargo test -p wasmer-engine --release cargo test -p wasmer-derive --release @@ -717,7 +717,7 @@ lint-packages: RUSTFLAGS=${RUSTFLAGS} cargo clippy -p wasmer-compiler RUSTFLAGS=${RUSTFLAGS} cargo clippy -p wasmer-compiler-cranelift RUSTFLAGS=${RUSTFLAGS} cargo clippy -p wasmer-compiler-singlepass - RUSTFLAGS=${RUSTFLAGS} cargo clippy -p wasmer-cli + RUSTFLAGS=${RUSTFLAGS} cargo clippy --manifest-path lib/cli/Cargo.toml $(compiler_features) RUSTFLAGS=${RUSTFLAGS} cargo clippy -p wasmer-cache RUSTFLAGS=${RUSTFLAGS} cargo clippy -p wasmer-engine diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 7a70bd7fc56..a7b316d4868 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -148,7 +148,7 @@ fn generate_header(header_file_src: &[u8]) -> anyhow::Result<()> { .open(&header_file_path)?; use std::io::Write; - header.write(header_file_src)?; + header.write_all(header_file_src)?; Ok(()) } From 637351cfc8ea613b87b6017bbb50d4ff3402a63e Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 25 Feb 2021 17:59:51 +0900 Subject: [PATCH 6/8] Fix a0800cb01 typos --- PACKAGING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PACKAGING.md b/PACKAGING.md index cc45fe60a25..896fd815a1f 100644 --- a/PACKAGING.md +++ b/PACKAGING.md @@ -10,9 +10,9 @@ * If you split the package into several subpackages, beware that the create-exe command of wasmer requires `libwasmer.a` to be installed at `$WASMER_INSTALL_PREFIX/lib/libwasmer.a`. Suggestion for splitting: * `wasmer` and `wasmer-headless`, containing the respective executables - * `wasmer-headless` contains a subset of `wasmer`'s functionality and should only be packaged when splitting - it must be built explicitly with `make build-wasmer-headless-minimal insteall-wasmer-headless-minimal` + * `wasmer-headless` contains a subset of `wasmer`'s functionality and should only be packaged when splitting - it must be built explicitly with `make build-wasmer-headless-minimal install-wasmer-headless-minimal` * `libwasmer`, containing `libwasmer.so*` - * `libwasmer-dev`, containging the header files and a `.pc` file + * `libwasmer-dev`, containing the header files and a `.pc` file * `libwasmer-static`, containing `libwasmer.a` The wasmer distro packaging story is still in its infancy, so feedback is very welcome. From 53c4d4fb256700f4f70a29782647d69077b221d5 Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Thu, 25 Feb 2021 18:09:01 +0900 Subject: [PATCH 7/8] Fix a9537c91b: install wasmer-headless --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 33e68a1b012..e4aaf2aa487 100644 --- a/Makefile +++ b/Makefile @@ -323,6 +323,7 @@ $(info --------------) $(info ) $(info ) + ############ # Building # ############ @@ -672,8 +673,9 @@ install-wasmer: install-capi-headers: for header in lib/c-api/*.{h,hh}; do install -Dm644 "$$header" $(DESTDIR)/include/$$(basename $$header); done - install -Dm644 lib/c-api/doc/deprecated/index.md $(DESTDIR)/include/wasmer-README.md + install -Dm644 lib/c-api/README.md $(DESTDIR)/include/wasmer-README.md +# Currently implemented for linux only. TODO install-capi-lib: pkgver=$$(target/release/wasmer --version | cut -d\ -f2) && \ shortver="$${pkgver%.*}" && \ @@ -694,7 +696,7 @@ install-pkgconfig: target/release/wasmer config --pkg-config | install -Dm644 /dev/stdin "$(DESTDIR)"/lib/pkgconfig/wasmer.pc install-wasmer-headless-minimal: - install -Dm755 target/release/wasmer $(DESTDIR)/bin/wasmer-headless + install -Dm755 target/release/wasmer-headless $(DESTDIR)/bin/wasmer-headless ################# # Miscellaneous # From 1cd42cefafeaf4c87c67154bdf35e794414362c9 Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Thu, 25 Feb 2021 18:12:21 +0900 Subject: [PATCH 8/8] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf6de271053..7e989d33936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - [#2123](https://github.com/wasmerio/wasmer/pull/2123) Use `ENABLE_{{compiler_name}}=(0|1)` to resp. force to disable or enable a compiler when running the `Makefile`, e.g. `ENABLE_LLVM=1 make build-wasmer`. - [#2123](https://github.com/wasmerio/wasmer/pull/2123) `libwasmer` comes with all available compilers per target instead of Cranelift only. - [#2118](https://github.com/wasmerio/wasmer/pull/2118) Add an unstable non-standard C API to query available engines and compilers. +- [#2135](https://github.com/wasmerio/wasmer/pull/2135) [Documentation](./PACKAGING.md) for linux distribution maintainers ### Changed - [#2113](https://github.com/wasmerio/wasmer/pull/2113) Bump minimum supported Rust version to 1.49