From adb7c59b5fe5e98d9ef7b4fbddc55117124d6140 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 11:58:10 +0100 Subject: [PATCH 01/16] feat(makefile) Simplify conditions with `IS_*` bool variables. This patch removes the `UNAME_S` and `ARCH` variables. It replaces them with `IS_WINDOWS, `IS_LINUX`, `IS_DARWIN, `IS_AMD64`, and `IS_AARCH64` variables. It makes the code easier to read and simpler to maintain. This patch also documents the large matrix of platform x architecture x compiler x engine x lib support. --- Makefile | 150 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 119 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 74411b603c1..c537d3425e9 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,101 @@ -# uname only works in *Unix like systems -ifneq ($(OS), Windows_NT) - ARCH := $(shell uname -m) - UNAME_S := $(shell uname -s) - LIBC ?= $(shell ldd 2>&1 | grep -o musl | head -n1) +SHELL=/bin/bash + +# |----------|--------------|------------|-------------|------------|------------| +# | Platform | Architecture | Compiler | Engine | libc | Supported? | +# |----------|--------------|------------|-------------|------------|------------| +# | Linux | amd64 | Cranelift | JIT | glibc | yes | +# | | | | | musl | no | +# | | | | Native | glibc | yes | +# | | | | | musl | no | +# | | | | Object File | glibc | yes | +# | | | | | musl | no | +# | | | | | | | +# | | | LLVM | JIT | glibc | yes | +# | | | | Native | glibc | yes | +# | | | | Object File | glibc | yes | +# | | | | | | | +# | | | Singlepass | JIT | glibc | yes | +# | | | | Native | glibc | yes | +# | | | | Object File | glibc | yes | +# | | | | | | | +# | | aarch64 | Cranelift | JIT | glibc | yes | +# | | | | Native | glibc | yes | +# | | | | Object File | glibc | yes | +# | | | | | | | +# | | | LLVM | JIT | glibc | no | +# | | | | Native | glibc | yes | +# | | | | Object File | glibc | yes | +# | | | | | | | +# | | | Singlepass | JIT | glibc | no | +# | | | | Native | glibc | no | +# | | | | Object File | glibc | no | +#-|----------|--------------|------------|-------------|------------|------------| +# | Darwin | amd64 | Cranelift | JIT | glibc | yes | +# | | | | Native | glibc | yes | +# | | | | Object File | glibc | yes | +# | | | | | | | +# | | | LLVM | JIT | glibc | yes | +# | | | | Native | glibc | yes | +# | | | | Object File | glibc | yes | +# | | | | | | | +# | | | Singlepass | JIT | glibc | yes | +# | | | | Native | glibc | yes | +# | | | | Object File | glibc | yes | +# | | | | | | | +# | | aarch64 | Cranelift | JIT | glibc | yes | +# | | | | Native | glibc | yes | +# | | | | Object File | glibc | yes | +# | | | | | | | +# | | | LLVM | JIT | glibc | no | +# | | | | Native | glibc | yes | +# | | | | Object File | glibc | yes | +# | | | | | | | +# | | | Singlepass | JIT | glibc | no | +# | | | | Native | glibc | no | +# | | | | Object File | glibc | no | +#-|----------|--------------|------------|-------------|------------|------------| +# | Windows | amd64 | Cranelift | JIT | glibc | yes | +# | | | | Native | glibc | yes | +# | | | | Object File | glibc | yes | +# | | | | | | | +# | | | LLVM | JIT | glibc | no | +# | | | | Native | glibc | no | +# | | | | Object File | glibc | no | +# | | | | | | | +# | | | Singlepass | JIT | glibc | yes | +# | | | | Native | glibc | yes | +# | | | | Object File | glibc | yes | + + +IS_DARWIN := 0 +IS_LINUX := 0 +IS_WINDOWS := 0 +IS_AMD64 := 0 +IS_AARCH64 := 0 +LIBC ?= + +# Test Windows apart because it doesn't support `uname -s`. +ifeq ($(OS), Windows_NT) + # We can assume it will likely be in amd64. + IS_AMD64 := 1 + IS_WINDOWS := 1 else - # We can assume, if in windows it will likely be in x86_64 - ARCH := x86_64 - UNAME_S := - LIBC ?= + # Platform + if ($(shell uname -s), Darwin) + IS_DARWIN := 1 + else + IS_LINUX := 1 + endif + + # Architecture + if ($(shell uname -m), x86_64) + IS_AMD64 := 1 + else + IS_AARCH64 := 1 + endif + + # Libc + LIBC ?= $(shell ldd 2>&1 | grep -o musl | head -n1) endif # Which compilers we build. These have dependencies that may not be on the system. @@ -36,16 +124,18 @@ else endif endif -ifeq ($(ARCH), x86_64) +ifeq ($(IS_AMD64), 1) test_compilers_engines += cranelift-jit - # LLVM could be enabled if not in Windows - ifneq ($(OS), Windows_NT) + + ifeq ($(IS_WINDOWS), 0) + # Singlepass is available on Linux and macOS only. + compilers += singlepass + + # `cranelift-native` ifneq ($(LIBC), musl) # Native engine doesn't work on Windows and musl yet. test_compilers_engines += cranelift-native endif - # Singlepass doesn't work yet on Windows. - compilers += singlepass # Singlepass doesn't work with the native engine. test_compilers_engines += singlepass-jit ifneq (, $(findstring llvm,$(compilers))) @@ -59,17 +149,14 @@ ifeq ($(ARCH), x86_64) endif endif -# If it's an aarch64/arm64 chip -# Using filter as a logical OR -# https://stackoverflow.com/questions/7656425/makefile-ifeq-logical-or use_system_ffi = -ifneq (,$(filter $(ARCH),aarch64 arm64)) +ifeq ($(IS_AARCH64), 1) test_compilers_engines += cranelift-jit ifneq (, $(findstring llvm,$(compilers))) test_compilers_engines += llvm-native endif # if we are in macos arm64, we use the system libffi for the capi - ifeq ($(UNAME_S), Darwin) + ifeq ($(IS_DARWIN), 1) use_system_ffi = yes endif endif @@ -87,7 +174,7 @@ endif compilers := $(filter-out ,$(compilers)) test_compilers_engines := $(filter-out ,$(test_compilers_engines)) -ifneq ($(OS), Windows_NT) +ifeq ($(IS_WINDOWS), 0) bold := $(shell tput bold 2>/dev/null || echo -n '') green := $(shell tput setaf 2 2>/dev/null || echo -n '') reset := $(shell tput sgr0 2>/dev/null || echo -n '') @@ -107,6 +194,7 @@ $(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)) +$(info C API default features: $(bold)$(green)${capi_default_features}$(reset)) ############ @@ -136,10 +224,10 @@ build-wasmer-debug: # rpath = false build-wasmer-headless-minimal: RUSTFLAGS="-C panic=abort" xargo build --target $(HOST_TARGET) --release --manifest-path=lib/cli/Cargo.toml --no-default-features --features headless-minimal --bin wasmer-headless -ifeq ($(UNAME_S), Darwin) +ifeq ($(IS_DARWIN), 1) strip -u target/$(HOST_TARGET)/release/wasmer-headless else -ifeq ($(OS), Windows_NT) +ifeq ($(IS_WINDOWS), 1) strip --strip-unneeded target/$(HOST_TARGET)/release/wasmer-headless.exe else strip --strip-unneeded target/$(HOST_TARGET)/release/wasmer-headless @@ -151,7 +239,7 @@ get-wapm: [ -d "wapm-cli" ] || git clone --branch $(WAPM_VERSION) https://github.com/wasmerio/wapm-cli.git build-wapm: get-wapm -ifeq ($(UNAME_S), Darwin) +ifeq ($(IS_DARWIN), 1) # We build it without bundling sqlite, as is included by default in macos cargo build --release --manifest-path wapm-cli/Cargo.toml --no-default-features --features "packagesigning telemetry update-notifications" else @@ -333,7 +421,7 @@ test-integration: package-wapm: mkdir -p "package/bin" -ifneq ($(OS), Windows_NT) +ifeq ($(IS_WINDOWS), 0) if [ -d "wapm-cli" ]; then \ cp wapm-cli/target/release/wapm package/bin/ ;\ echo "#!/bin/bash\nwapm execute \"\$$@\"" > package/bin/wax ;\ @@ -343,13 +431,13 @@ else if [ -d "wapm-cli" ]; then \ cp wapm-cli/target/release/wapm package/bin/ ;\ fi -ifeq ($(UNAME_S), Darwin) +ifeq ($(IS_DARWIN), 1) codesign -s - package/bin/wapm endif endif package-minimal-headless-wasmer: -ifeq ($(OS), Windows_NT) +ifeq ($(IS_WINDOWS), 1) if [ -f "target/$(HOST_TARGET)/release/wasmer-headless.exe" ]; then \ cp target/$(HOST_TARGET)/release/wasmer-headless.exe package/bin ;\ fi @@ -361,11 +449,11 @@ endif package-wasmer: mkdir -p "package/bin" -ifeq ($(OS), Windows_NT) +ifeq ($(IS_WINDOWS), 1) cp target/release/wasmer.exe package/bin/ else cp target/release/wasmer package/bin/ -ifeq ($(UNAME_S), Darwin) +ifeq ($(IS_DARWIN), 1) codesign -s - package/bin/wasmer endif endif @@ -377,11 +465,11 @@ package-capi: cp lib/c-api/wasmer_wasm.h* package/include cp lib/c-api/wasm.h* package/include cp lib/c-api/README.md package/include/README.md -ifeq ($(OS), Windows_NT) +ifeq ($(IS_WINDOWS), 1) cp target/release/wasmer_c_api.dll package/lib/wasmer.dll cp target/release/wasmer_c_api.lib package/lib/wasmer.lib else -ifeq ($(UNAME_S), Darwin) +ifeq ($(IS_DARWIN), 1) # For some reason in macOS arm64 there are issues if we copy constantly in the install_name_tool util rm -f package/lib/libwasmer.dylib cp target/release/libwasmer_c_api.dylib package/lib/libwasmer.dylib @@ -411,7 +499,7 @@ distribution: package cp LICENSE package/LICENSE cp ATTRIBUTIONS.md package/ATTRIBUTIONS mkdir -p dist -ifeq ($(OS), Windows_NT) +ifeq ($(IS_WINDOWS), 1) iscc scripts/windows-installer/wasmer.iss cp scripts/windows-installer/WasmerInstaller.exe dist/ endif From 659bdb076277624a57118ccfa8b54f282516d89b Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 12:12:20 +0100 Subject: [PATCH 02/16] fix(makefile) If LLVM 10 and 11 are available, do not duplicate the `llvm` value inside `compilers`. This patch removes a possible duplication of the `llvm` value insode the `compilers` variable if both LLVM 10 and 11 are available. This patch also checks for LLVM 11 before LLVM 10. --- Makefile | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index c537d3425e9..1ffb582b9e6 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,13 @@ SHELL=/bin/bash # | | | | Object File | glibc | yes | +##### +# +# Define the “Platform” and “Architecture” columns of the matrix. +# +##### + + IS_DARWIN := 0 IS_LINUX := 0 IS_WINDOWS := 0 @@ -98,29 +105,39 @@ else LIBC ?= $(shell ldd 2>&1 | grep -o musl | head -n1) endif + +##### +# +# Define the “Compiler” column of the matrix. +# +##### + + # Which compilers we build. These have dependencies that may not be on the system. compilers := cranelift -# In the form "$(compiler)-$(engine)" which compiler+engine combinations to test +# Compilers to test again. +# +# In the form "$(compiler)-$(engine)" which `compiler` and `engine` combinations to test # in `make test`. test_compilers_engines := -# Autodetect LLVM from llvm-config +# Autodetect LLVM from `llvm-config` ifneq (, $(shell which llvm-config 2>/dev/null)) LLVM_VERSION := $(shell llvm-config --version) + # If findstring is not empty, then it have found the value - ifneq (, $(findstring 10,$(LLVM_VERSION))) - compilers += llvm - endif ifneq (, $(findstring 11,$(LLVM_VERSION))) compilers += llvm - endif -else - ifneq (, $(shell which llvm-config-10 2>/dev/null)) + else ifneq (, $(findstring 10,$(LLVM_VERSION))) compilers += llvm endif +# Autodetect LLVM from `llvm-config-`. +else ifneq (, $(shell which llvm-config-11 2>/dev/null)) compilers += llvm + else ifneq (, $(shell which llvm-config-10 2>/dev/null)) + compilers += llvm endif endif From 7b38752effea3dd4c8136cc7e11739d79a788e24 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 13:08:43 +0100 Subject: [PATCH 03/16] feat(makefile) Centralize the `compilers` decision in the same place. --- Makefile | 63 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 1ffb582b9e6..36eff34d2ca 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,13 @@ SHELL=/bin/bash + +##### +# +# The Matrix +# +##### + + # |----------|--------------|------------|-------------|------------|------------| # | Platform | Architecture | Compiler | Engine | libc | Supported? | # |----------|--------------|------------|-------------|------------|------------| @@ -62,9 +70,10 @@ SHELL=/bin/bash # | | | | Native | glibc | no | # | | | | Object File | glibc | no | # | | | | | | | -# | | | Singlepass | JIT | glibc | yes | -# | | | | Native | glibc | yes | -# | | | | Object File | glibc | yes | +# | | | Singlepass | JIT | glibc | no | +# | | | | Native | glibc | no | +# | | | | Object File | glibc | no | +# |----------|--------------|------------|-------------|------------|------------| ##### @@ -88,14 +97,14 @@ ifeq ($(OS), Windows_NT) IS_WINDOWS := 1 else # Platform - if ($(shell uname -s), Darwin) + ifeq ($(shell uname -s), Darwin) IS_DARWIN := 1 else IS_LINUX := 1 endif # Architecture - if ($(shell uname -m), x86_64) + ifeq ($(shell uname -m), x86_64) IS_AMD64 := 1 else IS_AARCH64 := 1 @@ -112,15 +121,18 @@ endif # ##### - # Which compilers we build. These have dependencies that may not be on the system. -compilers := cranelift +compilers := -# Compilers to test again. -# -# In the form "$(compiler)-$(engine)" which `compiler` and `engine` combinations to test -# in `make test`. -test_compilers_engines := +## +# Cranelift +## + +compilers += cranelift + +## +# LLVM +## # Autodetect LLVM from `llvm-config` ifneq (, $(shell which llvm-config 2>/dev/null)) @@ -141,13 +153,34 @@ else endif endif +## +# Singlepass +## + +ifeq ($(IS_WINDOWS), 0) + ifeq ($(IS_AMD64), 1) + compilers += singlepass + endif +endif + + + +##### +# +# Define the “Engine” column of the matrix. +# +##### + +# Compilers and engines to test again. +# +# In the form "$(compiler)-$(engine)" which `compiler` and `engine` combinations to test +# in `make test`. +test_compilers_engines := + ifeq ($(IS_AMD64), 1) test_compilers_engines += cranelift-jit ifeq ($(IS_WINDOWS), 0) - # Singlepass is available on Linux and macOS only. - compilers += singlepass - # `cranelift-native` ifneq ($(LIBC), musl) # Native engine doesn't work on Windows and musl yet. From 006c653e8aaf5cbacc4606b58f285be74ffbfea2 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 13:15:00 +0100 Subject: [PATCH 04/16] chore(makefile) Rename `test_compilers_engines` to `compilers_engines`. --- Makefile | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 36eff34d2ca..3d3fdc36c0d 100644 --- a/Makefile +++ b/Makefile @@ -171,29 +171,27 @@ endif # ##### -# Compilers and engines to test again. -# -# In the form "$(compiler)-$(engine)" which `compiler` and `engine` combinations to test -# in `make test`. -test_compilers_engines := +# The engine is part of a pair of kind (compiler, engine). All the +# pairs are stored in the `compilers_engines` variable. +compilers_engines := ifeq ($(IS_AMD64), 1) - test_compilers_engines += cranelift-jit + compilers_engines += cranelift-jit ifeq ($(IS_WINDOWS), 0) # `cranelift-native` ifneq ($(LIBC), musl) # Native engine doesn't work on Windows and musl yet. - test_compilers_engines += cranelift-native + compilers_engines += cranelift-native endif # Singlepass doesn't work with the native engine. - test_compilers_engines += singlepass-jit + compilers_engines += singlepass-jit ifneq (, $(findstring llvm,$(compilers))) - test_compilers_engines += llvm-jit + compilers_engines += llvm-jit ifneq ($(LIBC), musl) # Native engine doesn't work on musl yet. - test_compilers_engines += llvm-native + compilers_engines += llvm-native endif endif endif @@ -201,9 +199,9 @@ endif use_system_ffi = ifeq ($(IS_AARCH64), 1) - test_compilers_engines += cranelift-jit + compilers_engines += cranelift-jit ifneq (, $(findstring llvm,$(compilers))) - test_compilers_engines += llvm-native + compilers_engines += llvm-native endif # if we are in macos arm64, we use the system libffi for the capi ifeq ($(IS_DARWIN), 1) @@ -222,7 +220,7 @@ ifdef use_system_ffi endif compilers := $(filter-out ,$(compilers)) -test_compilers_engines := $(filter-out ,$(test_compilers_engines)) +compilers_engines := $(filter-out ,$(compilers_engines)) ifeq ($(IS_WINDOWS), 0) bold := $(shell tput bold 2>/dev/null || echo -n '') @@ -243,7 +241,7 @@ endif $(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)) +$(info Available compilers + engines for test: $(bold)$(green)${compilers_engines}$(reset)) $(info C API default features: $(bold)$(green)${capi_default_features}$(reset)) @@ -400,11 +398,11 @@ test-llvm-native: test-llvm-jit: cargo test --release $(compiler_features) --features "test-llvm test-jit" -test-singlepass: $(foreach singlepass_engine,$(filter singlepass-%,$(test_compilers_engines)),test-$(singlepass_engine)) +test-singlepass: $(foreach singlepass_engine,$(filter singlepass-%,$(compilers_engines)),test-$(singlepass_engine)) -test-cranelift: $(foreach cranelift_engine,$(filter cranelift-%,$(test_compilers_engines)),test-$(cranelift_engine)) +test-cranelift: $(foreach cranelift_engine,$(filter cranelift-%,$(compilers_engines)),test-$(cranelift_engine)) -test-llvm: $(foreach llvm_engine,$(filter llvm-%,$(test_compilers_engines)),test-$(llvm_engine)) +test-llvm: $(foreach llvm_engine,$(filter llvm-%,$(compilers_engines)),test-$(llvm_engine)) test-packages: cargo test -p wasmer --release From 67a1dfeba86ce507c681f2d1b00a520c32fe97fc Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 13:28:38 +0100 Subject: [PATCH 05/16] feat(makefile) Handle the `cranelift-*` pairs in a single place. --- Makefile | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 3d3fdc36c0d..ad4266138b5 100644 --- a/Makefile +++ b/Makefile @@ -15,64 +15,48 @@ SHELL=/bin/bash # | | | | | musl | no | # | | | | Native | glibc | yes | # | | | | | musl | no | -# | | | | Object File | glibc | yes | -# | | | | | musl | no | # | | | | | | | # | | | LLVM | JIT | glibc | yes | # | | | | Native | glibc | yes | -# | | | | Object File | glibc | yes | # | | | | | | | # | | | Singlepass | JIT | glibc | yes | # | | | | Native | glibc | yes | -# | | | | Object File | glibc | yes | # | | | | | | | # | | aarch64 | Cranelift | JIT | glibc | yes | -# | | | | Native | glibc | yes | -# | | | | Object File | glibc | yes | +# | | | | Native | glibc | no | # | | | | | | | # | | | LLVM | JIT | glibc | no | # | | | | Native | glibc | yes | -# | | | | Object File | glibc | yes | # | | | | | | | # | | | Singlepass | JIT | glibc | no | # | | | | Native | glibc | no | -# | | | | Object File | glibc | no | #-|----------|--------------|------------|-------------|------------|------------| # | Darwin | amd64 | Cranelift | JIT | glibc | yes | # | | | | Native | glibc | yes | -# | | | | Object File | glibc | yes | # | | | | | | | # | | | LLVM | JIT | glibc | yes | # | | | | Native | glibc | yes | -# | | | | Object File | glibc | yes | # | | | | | | | # | | | Singlepass | JIT | glibc | yes | # | | | | Native | glibc | yes | -# | | | | Object File | glibc | yes | # | | | | | | | # | | aarch64 | Cranelift | JIT | glibc | yes | -# | | | | Native | glibc | yes | -# | | | | Object File | glibc | yes | +# | | | | Native | glibc | no | # | | | | | | | # | | | LLVM | JIT | glibc | no | # | | | | Native | glibc | yes | -# | | | | Object File | glibc | yes | # | | | | | | | # | | | Singlepass | JIT | glibc | no | # | | | | Native | glibc | no | -# | | | | Object File | glibc | no | #-|----------|--------------|------------|-------------|------------|------------| # | Windows | amd64 | Cranelift | JIT | glibc | yes | -# | | | | Native | glibc | yes | -# | | | | Object File | glibc | yes | +# | | | | Native | glibc | no | # | | | | | | | # | | | LLVM | JIT | glibc | no | # | | | | Native | glibc | no | -# | | | | Object File | glibc | no | # | | | | | | | # | | | Singlepass | JIT | glibc | no | # | | | | Native | glibc | no | -# | | | | Object File | glibc | no | # |----------|--------------|------------|-------------|------------|------------| @@ -175,15 +159,24 @@ endif # pairs are stored in the `compilers_engines` variable. compilers_engines := -ifeq ($(IS_AMD64), 1) - compilers_engines += cranelift-jit +## +# The Cranelift case. +## - ifeq ($(IS_WINDOWS), 0) - # `cranelift-native` - ifneq ($(LIBC), musl) - # Native engine doesn't work on Windows and musl yet. +compilers_engines += cranelift-jit + +ifeq ($(IS_WINDOWS), 0) + ifeq ($(IS_AMD64), 1) + ifneq ($(LIBC, musl)) compilers_engines += cranelift-native endif + endif +endif + + + +ifeq ($(IS_AMD64), 1) + ifeq ($(IS_WINDOWS), 0) # Singlepass doesn't work with the native engine. compilers_engines += singlepass-jit ifneq (, $(findstring llvm,$(compilers))) @@ -199,7 +192,6 @@ endif use_system_ffi = ifeq ($(IS_AARCH64), 1) - compilers_engines += cranelift-jit ifneq (, $(findstring llvm,$(compilers))) compilers_engines += llvm-native endif From f3c729d5158eb63cae5facac9fd7a09dec4fb3ea Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 13:43:37 +0100 Subject: [PATCH 06/16] feat(makefile) Handle the `llvm-*` pairs in a single place. --- Makefile | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index ad4266138b5..01f1284e02f 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ SHELL=/bin/bash # | | | | Native | glibc | yes | # | | | | | | | # | | | Singlepass | JIT | glibc | yes | -# | | | | Native | glibc | yes | +# | | | | Native | glibc | no | # | | | | | | | # | | aarch64 | Cranelift | JIT | glibc | yes | # | | | | Native | glibc | no | @@ -173,28 +173,33 @@ ifeq ($(IS_WINDOWS), 0) endif endif +## +# The LLVM case. +## + +# If `compilers` contains `llvm`. +ifneq (, $(findstring llvm,$(compilers))) + ifeq ($(IS_WINDOWS), 0) + ifeq ($(IS_AMD64), 1) + compilers_engines += llvm-jit + compilers_engines += llvm-native + else ifeq ($(IS_AARCH64), 1) + compilers_engines += llvm-native + endif + endif +endif + ifeq ($(IS_AMD64), 1) ifeq ($(IS_WINDOWS), 0) # Singlepass doesn't work with the native engine. compilers_engines += singlepass-jit - ifneq (, $(findstring llvm,$(compilers))) - compilers_engines += llvm-jit - - ifneq ($(LIBC), musl) - # Native engine doesn't work on musl yet. - compilers_engines += llvm-native - endif - endif endif endif use_system_ffi = ifeq ($(IS_AARCH64), 1) - ifneq (, $(findstring llvm,$(compilers))) - compilers_engines += llvm-native - endif # if we are in macos arm64, we use the system libffi for the capi ifeq ($(IS_DARWIN), 1) use_system_ffi = yes From 1054e516643a8626baab6be7c8069dae62d6072e Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 13:51:21 +0100 Subject: [PATCH 07/16] feat(makefile) Handle the `singlepass-*` pairs in a single place. --- Makefile | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 01f1284e02f..310895a26aa 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ SHELL=/bin/bash # | | | | Native | glibc | yes | # | | | | | | | # | | | Singlepass | JIT | glibc | yes | -# | | | | Native | glibc | yes | +# | | | | Native | glibc | no | # | | | | | | | # | | aarch64 | Cranelift | JIT | glibc | yes | # | | | | Native | glibc | no | @@ -189,15 +189,20 @@ ifneq (, $(findstring llvm,$(compilers))) endif endif +## +# The Singlepass case. +## - -ifeq ($(IS_AMD64), 1) +# If `compilers` contains `singlepass`. +ifneq (, $(findstring singlepass,$(compilers))) ifeq ($(IS_WINDOWS), 0) - # Singlepass doesn't work with the native engine. - compilers_engines += singlepass-jit + if ($(IS_AMD64), 1) + compilers_engines += singlepass-jit + endif endif endif + use_system_ffi = ifeq ($(IS_AARCH64), 1) # if we are in macos arm64, we use the system libffi for the capi From ba3fdf11c4f4a729cbe526899fb33ae9d9cdc179 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 13:55:24 +0100 Subject: [PATCH 08/16] feaf(makefile) Add the `HAS_` variables. --- Makefile | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 310895a26aa..914341feda5 100644 --- a/Makefile +++ b/Makefile @@ -105,6 +105,10 @@ endif # ##### +HAS_CRANELIFT := 0 +HAS_LLVM := 0 +HAS_SINGLEPASS := 0 + # Which compilers we build. These have dependencies that may not be on the system. compilers := @@ -113,6 +117,7 @@ compilers := ## compilers += cranelift +HAS_CRANELIFT := 1 ## # LLVM @@ -137,6 +142,10 @@ else endif endif +ifneq (, $(findstring llvm,$(compilers))) + HAS_LLVM := 1 +endif + ## # Singlepass ## @@ -147,6 +156,10 @@ ifeq ($(IS_WINDOWS), 0) endif endif +ifneq (, $(findstring singlepass,$(compilers))) + HAS_SINGLEPASS := 1 +endif + ##### @@ -163,12 +176,14 @@ compilers_engines := # The Cranelift case. ## -compilers_engines += cranelift-jit +ifeq ($(HAS_CRANELIFT, 1)) + compilers_engines += cranelift-jit -ifeq ($(IS_WINDOWS), 0) - ifeq ($(IS_AMD64), 1) - ifneq ($(LIBC, musl)) - compilers_engines += cranelift-native + ifeq ($(IS_WINDOWS), 0) + ifeq ($(IS_AMD64), 1) + ifneq ($(LIBC, musl)) + compilers_engines += cranelift-native + endif endif endif endif @@ -177,8 +192,7 @@ endif # The LLVM case. ## -# If `compilers` contains `llvm`. -ifneq (, $(findstring llvm,$(compilers))) +ifeq ($(HAS_LLVM), 1) ifeq ($(IS_WINDOWS), 0) ifeq ($(IS_AMD64), 1) compilers_engines += llvm-jit @@ -193,8 +207,7 @@ endif # The Singlepass case. ## -# If `compilers` contains `singlepass`. -ifneq (, $(findstring singlepass,$(compilers))) +ifeq ($(HAS_SINGLEPASS), 1) ifeq ($(IS_WINDOWS), 0) if ($(IS_AMD64), 1) compilers_engines += singlepass-jit From 06d543ae34396f6c2921df05c9dd7d629681daf9 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 13:58:57 +0100 Subject: [PATCH 09/16] fix(makefile) Fix syntax error. --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 914341feda5..63e93339bf2 100644 --- a/Makefile +++ b/Makefile @@ -176,7 +176,7 @@ compilers_engines := # The Cranelift case. ## -ifeq ($(HAS_CRANELIFT, 1)) +ifeq ($(HAS_CRANELIFT), 1) compilers_engines += cranelift-jit ifeq ($(IS_WINDOWS), 0) @@ -209,7 +209,7 @@ endif ifeq ($(HAS_SINGLEPASS), 1) ifeq ($(IS_WINDOWS), 0) - if ($(IS_AMD64), 1) + ifeq ($(IS_AMD64), 1) compilers_engines += singlepass-jit endif endif @@ -436,7 +436,7 @@ test-packages: # The test-capi rules depend on the build-capi rules to build the .a files to # link the tests against. cargo test doesn't know that the tests will be running -test-capi: $(foreach compiler_engine,$(test_compilers_engines),test-capi-$(compiler_engine)) +test-capi: $(foreach compiler_engine,$(compilers_engines),test-capi-$(compiler_engine)) test-capi-singlepass-jit: build-capi-singlepass-jit test-capi-tests cargo test --manifest-path lib/c-api/Cargo.toml --release \ From 660dababdc68debd396567b66c0431655405b493 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 14:15:15 +0100 Subject: [PATCH 10/16] feat(makefile) Remove `filter-out`, and clean up `capi_default_features`. --- Makefile | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 63e93339bf2..f3ee1ca6239 100644 --- a/Makefile +++ b/Makefile @@ -105,6 +105,7 @@ endif # ##### + HAS_CRANELIFT := 0 HAS_LLVM := 0 HAS_SINGLEPASS := 0 @@ -161,13 +162,13 @@ ifneq (, $(findstring singlepass,$(compilers))) endif - ##### # # Define the “Engine” column of the matrix. # ##### + # The engine is part of a pair of kind (compiler, engine). All the # pairs are stored in the `compilers_engines` variable. compilers_engines := @@ -216,26 +217,49 @@ ifeq ($(HAS_SINGLEPASS), 1) endif -use_system_ffi = -ifeq ($(IS_AARCH64), 1) - # if we are in macos arm64, we use the system libffi for the capi - ifeq ($(IS_DARWIN), 1) - use_system_ffi = yes +##### +# +# Miscellaneous. +# +##### + +# The `libffi` library doesn't support Darwin/aarch64. In this +# particular case, we need to use the `libffi` version provided by the +# system itself. +# +# See . + +use_system_ffi := + +ifeq ($(IS_DARWIN), 1) + ifeq ($(IS_AARCH64, 1)) + use_system_ffi = 1 endif endif -# if the user has set the `WASMER_CAPI_USE_SYSTEM_LIBFFI` var to 1 also -# use the system libffi. +# If the user has set the `WASMER_CAPI_USE_SYSTEM_LIBFFI` environment +# variable to 1, then also use the system `libffi`. ifeq ($(WASMER_CAPI_USE_SYSTEM_LIBFFI), 1) - use_system_ffi = yes + use_system_ffi = 1 endif -ifdef use_system_ffi +##### +# +# C API default features. +# +##### + + +ifeq ($(use_system_ffi), 1) capi_default_features := --features system-libffi endif -compilers := $(filter-out ,$(compilers)) -compilers_engines := $(filter-out ,$(compilers_engines)) + +##### +# +# There we go! +# +##### ifeq ($(IS_WINDOWS), 0) bold := $(shell tput bold 2>/dev/null || echo -n '') From 95dcb04c79a92476219a9b63f8c207cb0878291a Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 14:18:00 +0100 Subject: [PATCH 11/16] feat(makefile) Define a single place to compute Cargo features. --- Makefile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index f3ee1ca6239..5071e1f9bbd 100644 --- a/Makefile +++ b/Makefile @@ -232,7 +232,7 @@ endif use_system_ffi := ifeq ($(IS_DARWIN), 1) - ifeq ($(IS_AARCH64, 1)) + ifeq ($(IS_AARCH64), 1) use_system_ffi = 1 endif endif @@ -245,19 +245,23 @@ endif ##### # -# C API default features. +# Cargo features. # ##### - +# Define the default Cargo features for the `wasmer-c-api` crate. ifeq ($(use_system_ffi), 1) capi_default_features := --features system-libffi endif +# Define the default Cargo features for all crates. +compiler_features_spaced := $(foreach compiler,$(compilers),$(compiler)) +compiler_features := --features "$(compiler_features_spaced)" + ##### # -# There we go! +# Display information. # ##### @@ -267,14 +271,10 @@ ifeq ($(IS_WINDOWS), 0) reset := $(shell tput sgr0 2>/dev/null || echo -n '') 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 ' ') ifneq (, $(LIBC)) -$(info C standard library: $(bold)$(green)$(LIBC)$(reset)) + $(info C standard library: $(bold)$(green)$(LIBC)$(reset)) endif $(info Host target: $(bold)$(green)$(HOST_TARGET)$(reset)) From 67217690798182343e7904206c03985b597ef264 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 14:32:56 +0100 Subject: [PATCH 12/16] feat(makefile) Use comma to separate Cargo features in `compiler_features`. --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5071e1f9bbd..42841cd81b7 100644 --- a/Makefile +++ b/Makefile @@ -254,9 +254,12 @@ ifeq ($(use_system_ffi), 1) capi_default_features := --features system-libffi endif +# Small trick to define a space and a comma. +space := $() $() +comma := , + # Define the default Cargo features for all crates. -compiler_features_spaced := $(foreach compiler,$(compilers),$(compiler)) -compiler_features := --features "$(compiler_features_spaced)" +compiler_features := --features $(subst $(space),$(comma),$(strip $(compilers))) ##### From 62c7889f3a1f6dd6abf160cca381e4650a12d222 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 14:35:03 +0100 Subject: [PATCH 13/16] feat(makefile) Remove extra spaces in `compilers` and `compilers_engines`. --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 42841cd81b7..c3a83a9a8bd 100644 --- a/Makefile +++ b/Makefile @@ -161,6 +161,9 @@ ifneq (, $(findstring singlepass,$(compilers))) HAS_SINGLEPASS := 1 endif +# Clean the `compilers` variable. +compilers := $(strip $(compilers)) + ##### # @@ -216,6 +219,9 @@ ifeq ($(HAS_SINGLEPASS), 1) endif endif +# Clean the `compilers_engines` variable. +compilers_engines := $(strip $(compilers_engines)) + ##### # @@ -259,7 +265,7 @@ space := $() $() comma := , # Define the default Cargo features for all crates. -compiler_features := --features $(subst $(space),$(comma),$(strip $(compilers))) +compiler_features := --features $(subst $(space),$(comma),$(compilers)) ##### From 387a753316903fb69a62a0a301fd419e546db52c Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 14:57:06 +0100 Subject: [PATCH 14/16] feat(makefile) `build-capi` includes all available compilers. --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c3a83a9a8bd..59c95b0fd6b 100644 --- a/Makefile +++ b/Makefile @@ -349,8 +349,9 @@ build-docs-capi: cd lib/c-api/doc/deprecated/ && doxygen doxyfile cargo doc --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,jit,object-file,native,cranelift,wasi $(capi_default_features) -# We use cranelift as the default backend for the capi for now -build-capi: build-capi-cranelift +build-capi: + cargo build --manifest-path lib/c-api/Cargo.toml --release \ + --no-default-features --features deprecated,wat,jit,native,object-file,wasi $(capi_default_features) $(compiler_features) build-capi-singlepass: cargo build --manifest-path lib/c-api/Cargo.toml --release \ From f846a0d84bce4058283d0e53fff79091f6e83af8 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 14:57:38 +0100 Subject: [PATCH 15/16] feat(makefile) Explain `test-capi` and introduce `test-capi-all`. --- Makefile | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 59c95b0fd6b..ee40e5b4973 100644 --- a/Makefile +++ b/Makefile @@ -468,9 +468,26 @@ test-packages: cargo test -p wasmer-derive --release -# The test-capi rules depend on the build-capi rules to build the .a files to -# link the tests against. cargo test doesn't know that the tests will be running -test-capi: $(foreach compiler_engine,$(compilers_engines),test-capi-$(compiler_engine)) +# We want to run all the tests for all available compilers. The C API +# and the tests rely on the fact that one and only one default +# compiler will be selected at compile-time. Therefore, if we want to +# test exhaustively for all available compilers, we need to build and +# to test the C API with a different compiler each time. +# +# That's exactly what `test-capi` does: it runs `test-capi-*` rules +# that, prior to testing, builds the C API with `build-capi-*` sibling +# rules. Why? Because the tests need a static library (`.a` files) to +# link the tests against; `cargo test` doesn't generate such library, +# only `cargo build`. +# +# Finally, `test-capi` calls `test-capi-all` that runs the tests for +# the library built with `build-capi`, which is the one we will +# deliver to the users. +test-capi: $(foreach compiler_engine,$(compilers_engines),test-capi-$(compiler_engine)) test-capi-all + +test-capi-all: build-capi + cargo test --manifest-path lib/c-api/Cargo.toml --release \ + --no-default-features --features deprecated,wat,jit,native,object-file,wasi $(capi_default_features) $(compiler_features) -- --nocapture test-capi-singlepass-jit: build-capi-singlepass-jit test-capi-tests cargo test --manifest-path lib/c-api/Cargo.toml --release \ From d7779943a5484d26b51a83c146406e3446ae783d Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Feb 2021 15:06:54 +0100 Subject: [PATCH 16/16] doc(changelog) Add #2123. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d5d983f7c3..c0395a881de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ## **[Unreleased]** ### Added +- [#2123](https://github.com/wasmerio/wasmer/pull/2123) `libwasmer` comes with all available compilers per targets 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. ### Changed