Skip to content

Commit 4ae9d3e

Browse files
bors[bot]jcaesar
andauthored
Merge #2135
2135: Distro packaging improvements r=syrusakbary a=jcaesar # Description Having installed wasmer from both gentoo and AUR (packaged by svenstaro, an Arch Maintainer), I was stumped to find that both build wasmer without compilers, not actually allowing me to run any wasm. (The AUR PKGBUILD has since been patched, but the gentoo ebuild maintainer… who knows.) I figured that the obvious improvement would be to deny compilation if not at least one compiler is enabled, but I think more can be done to help packaging. I added * a way to set a default for `WASMER_DIR` at compile time * an install target for the Makefile * a `PACKAGING.md` with some suggestions to distro maintainers Disclaimer: I'm not a package maintainer anywhere, so these might be entirely off the rails. Commit 1 and 2 seem fairly reasonable to me, but for the other two, I'm not so sure. # Review - [ ] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Julius Michaelis <gitter@liftm.de>
2 parents d1bd9ea + a0800cb commit 4ae9d3e

File tree

7 files changed

+85
-6
lines changed

7 files changed

+85
-6
lines changed

Makefile

+40-1
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,13 @@ $(info --------------)
325325
$(info )
326326
$(info )
327327

328-
329328
############
330329
# Building #
331330
############
332331

332+
# Not really "all", just the default target that builds enough so make install will go through
333+
all: build-wasmer build-capi
334+
333335
bench:
334336
cargo bench $(compiler_features)
335337

@@ -659,6 +661,43 @@ endif
659661
tar -C package -zcvf wasmer.tar.gz bin lib include LICENSE ATTRIBUTIONS
660662
mv wasmer.tar.gz dist/
661663

664+
########################
665+
# (Distro-) Installing #
666+
########################
667+
668+
DESTDIR ?= /usr/local
669+
670+
install: install-wasmer install-capi-headers install-capi-lib install-capi-staticlib install-pkgconfig install-misc
671+
672+
install-wasmer:
673+
install -Dm755 target/release/wasmer $(DESTDIR)/bin/wasmer
674+
675+
install-capi-headers:
676+
for header in lib/c-api/*.{h,hh}; do install -Dm644 "$$header" $(DESTDIR)/include/$$(basename $$header); done
677+
install -Dm644 lib/c-api/doc/deprecated/index.md $(DESTDIR)/include/wasmer-README.md
678+
679+
install-capi-lib:
680+
pkgver=$$(target/release/wasmer --version | cut -d\ -f2) && \
681+
shortver="$${pkgver%.*}" && \
682+
majorver="$${shortver%.*}" && \
683+
install -Dm755 target/release/libwasmer_c_api.so "$(DESTDIR)/lib/libwasmer.so.$$pkgver" && \
684+
ln -sf "libwasmer.so.$$pkgver" "$(DESTDIR)/lib/libwasmer.so.$$shortver" && \
685+
ln -sf "libwasmer.so.$$pkgver" "$(DESTDIR)/lib/libwasmer.so.$$majorver" && \
686+
ln -sf "libwasmer.so.$$pkgver" "$(DESTDIR)/lib/libwasmer.so"
687+
688+
install-capi-staticlib:
689+
install -Dm644 target/release/libwasmer_c_api.a "$(DESTDIR)/lib/libwasmer.a"
690+
691+
install-misc:
692+
install -Dm644 LICENSE "$(DESTDIR)"/share/licenses/wasmer/LICENSE
693+
694+
install-pkgconfig:
695+
unset WASMER_DIR # Make sure WASMER_INSTALL_PREFIX is set during build
696+
target/release/wasmer config --pkg-config | install -Dm644 /dev/stdin "$(DESTDIR)"/lib/pkgconfig/wasmer.pc
697+
698+
install-wasmer-headless-minimal:
699+
install -Dm755 target/release/wasmer $(DESTDIR)/bin/wasmer-headless
700+
662701
#################
663702
# Miscellaneous #
664703
#################

PACKAGING.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Wasmer distro packaging notes
2+
3+
* Where possible, do not directly invoke cargo, but use the supplied Makefile
4+
* wasmer has several compiler backends and the Makefile autodetects whether to enable llvm and singlepass.
5+
Set `ENABLE_{CRANELIFT,LLVM,SINGLEPASS}=1` to build the full set or fail trying
6+
* Set `WASMER_CAPI_USE_SYSTEM_LIBFFI=1` to force dynamic linking of libffi on the shared library
7+
* `make install` respects `DESTDIR`, but `prefix` must be configured as e.g. `WASMER_INSTALL_PREFIX=/usr make all`
8+
* In case you must build/install directly with cargo, make sure to enable at least one compiler backend feature
9+
* 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.
10+
* 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`.
11+
Suggestion for splitting:
12+
* `wasmer` and `wasmer-headless`, containing the respective executables
13+
* `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`
14+
* `libwasmer`, containing `libwasmer.so*`
15+
* `libwasmer-dev`, containging the header files and a `.pc` file
16+
* `libwasmer-static`, containing `libwasmer.a`
17+
18+
The wasmer distro packaging story is still in its infancy, so feedback is very welcome.

lib/cli/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ license = "MIT"
1010
readme = "README.md"
1111
edition = "2018"
1212
default-run = "wasmer"
13+
build = "build.rs"
1314

1415
[[bin]]
1516
name = "wasmer"

lib/cli/build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub fn main() {
2+
println!("cargo:rerun-if-changed=build.rs");
3+
println!("cargo:rerun-if-env-changed=WASMER_INSTALL_PREFIX");
4+
}

lib/cli/src/bin/wasmer.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
use wasmer_cli::cli::wasmer_main;
22

3+
#[cfg(not(any(feature = "cranelift", feature = "singlepass", feature = "llvm")))]
4+
compile_error!(
5+
"Either enable at least one compiler, or compile the wasmer-headless binary instead"
6+
);
7+
38
fn main() {
49
wasmer_main();
510
}

lib/cli/src/commands/config.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,16 @@ impl Config {
4545
}
4646
fn inner_execute(&self) -> Result<()> {
4747
let key = "WASMER_DIR";
48-
let wasmer_dir = env::var(key).context(format!(
49-
"failed to retrieve the {} environment variables",
50-
key
51-
))?;
48+
let wasmer_dir = env::var(key)
49+
.or_else(|e| {
50+
option_env!("WASMER_INSTALL_PREFIX")
51+
.map(str::to_string)
52+
.ok_or(e)
53+
})
54+
.context(format!(
55+
"failed to retrieve the {} environment variables",
56+
key
57+
))?;
5258

5359
let prefix = PathBuf::from(wasmer_dir);
5460

lib/cli/src/commands/create_exe.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,13 @@ fn generate_header(header_file_src: &[u8]) -> anyhow::Result<()> {
155155

156156
fn get_wasmer_dir() -> anyhow::Result<PathBuf> {
157157
Ok(PathBuf::from(
158-
env::var("WASMER_DIR").context("Trying to read env var `WASMER_DIR`")?,
158+
env::var("WASMER_DIR")
159+
.or_else(|e| {
160+
option_env!("WASMER_INSTALL_PREFIX")
161+
.map(str::to_string)
162+
.ok_or(e)
163+
})
164+
.context("Trying to read env var `WASMER_DIR`")?,
159165
))
160166
}
161167

0 commit comments

Comments
 (0)