From 4a58338acb22430919be4b041423714fc25f39ef Mon Sep 17 00:00:00 2001 From: jubianchi Date: Wed, 6 Jan 2021 21:21:03 +0100 Subject: [PATCH] chore: Build Wasmer on musl Closes #1482 Closes #1766 --- .github/workflows/main.yaml | 37 +++++++++++++++++++++------- Makefile | 31 +++++++++++++++++------ examples/engine_cross_compilation.rs | 3 ++- examples/engine_headless.rs | 2 +- examples/engine_native.rs | 2 +- tests/compilers/traps.rs | 8 +++++- 6 files changed, 62 insertions(+), 21 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c9295b377d2..8d3e5d1fd5d 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -38,7 +38,6 @@ jobs: strategy: fail-fast: false matrix: - build: [linux-x64, macos-x64, macos-arm64, windows-x64, linux-aarch64] include: - build: linux-x64 os: ubuntu-18.04 @@ -47,6 +46,13 @@ jobs: artifact_name: 'wasmer-linux-amd64' cross_compilation_artifact_name: 'cross_compiled_from_linux' run_integration_tests: true + - build: linux-musl-x64 + os: ubuntu-18.04 + rust: 1.48 + target: x86_64-unknown-linux-musl + artifact_name: 'wasmer-linux-musl-amd64' + cross_compilation_artifact_name: 'cross_compiled_from_linux' + run_integration_tests: false - build: macos-x64 os: macos-latest rust: 1.48 @@ -80,11 +86,16 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up libstdc++ on Linux + if: matrix.build == 'linux-x64' run: | sudo apt-get update -y sudo apt-get install -y --allow-downgrades libstdc++6=8.4.0-1ubuntu1~18.04 sudo apt-get install --reinstall g++-8 - if: matrix.os == 'ubuntu-18.04' + - name: Set up musl on Linux + if: matrix.build == 'linux-musl-x64' + run: | + sudo apt-get update -y + sudo apt-get install -y musl-dev musl-tools - name: Install Rust ${{ matrix.rust }} uses: actions-rs/toolchain@v1 with: @@ -124,7 +135,6 @@ jobs: ~/.cargo/registry ~/.cargo/git key: ${{ matrix.build }}-${{ matrix.target }}-cargo-${{ hashFiles('Cargo.lock') }}-v1 - # Install sccache - uses: actions/cache@v2 with: path: ${{ runner.tool_cache }}/cargo-sccache @@ -142,7 +152,7 @@ jobs: target = "${{ matrix.target }}" EOF if: matrix.target - - name: Set sccache port + - name: Set examples/engine_cross_compilation.rs port run: | netstat -aln | awk ' $6 == "LISTEN" { @@ -171,22 +181,31 @@ jobs: - name: Test run: | make test - if: matrix.target != 'aarch64-apple-darwin' + if: matrix.target != 'aarch64-apple-darwin' && matrix.build != 'linux-musl-x64' + - name: Test (musl) + if: matrix.build == 'linux-musl-x64' + run: | + LIBC=musl WASMER_CAPI_USE_SYSTEM_LIBFFI=1 make test - name: Test C API run: | make test-capi - if: matrix.os != 'windows-latest' && matrix.target != 'aarch64-apple-darwin' # we can't test yet on Apple Silicon or Windows + if: matrix.os != 'windows-latest' && matrix.target != 'aarch64-apple-darwin' && matrix.build != 'linux-musl-x64' # we can't test yet on Apple Silicon or Windows - name: Build C API run: | make build-capi - if: matrix.target != 'aarch64-apple-darwin' + if: matrix.target != 'aarch64-apple-darwin' && matrix.build != 'linux-musl-x64' - name: Build C API (system libffi) run: | make build-capi-cranelift-system-libffi - if: matrix.target == 'aarch64-apple-darwin' + if: matrix.target == 'aarch64-apple-darwin' || matrix.build == 'linux-musl-x64' - name: Build Wasmer binary + if: matrix.build != 'linux-musl-x64' run: | make build-wasmer + - name: Build Wasmer binary (musl) + if: matrix.build == 'linux-musl-x64' + run: | + LIBC=musl WASMER_CAPI_USE_SYSTEM_LIBFFI=1 make build-wasmer - name: Build Wapm binary run: | make build-wapm @@ -241,7 +260,7 @@ jobs: make test-integration if: matrix.run_integration_tests && matrix.os != 'windows-latest' - name: Cross compile from Linux - if: matrix.os == 'ubuntu-18.04' + if: matrix.build == 'linux-x64' shell: bash run: | ls target/release diff --git a/Makefile b/Makefile index d4534b15f1a..4d24c9070bf 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,12 @@ ifneq ($(OS), Windows_NT) ARCH := $(shell uname -m) UNAME_S := $(shell uname -s) + LIBC ?= $(shell ldd 2>&1 | grep -o musl | head -n1) else # We can assume, if in windows it will likely be in x86_64 ARCH := x86_64 - UNAME_S := + UNAME_S := + LIBC ?= endif # Which compilers we build. These have dependencies that may not be on the system. @@ -38,14 +40,21 @@ ifeq ($(ARCH), x86_64) test_compilers_engines += cranelift-jit # LLVM could be enabled if not in Windows ifneq ($(OS), Windows_NT) - # Native engine doesn't work on Windows yet. - test_compilers_engines += 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))) - test_compilers_engines += llvm-jit llvm-native + test_compilers_engines += llvm-jit + + ifneq ($(LIBC), musl) + # Native engine doesn't work on musl yet. + test_compilers_engines += llvm-native + endif endif endif endif @@ -79,9 +88,9 @@ compilers := $(filter-out ,$(compilers)) test_compilers_engines := $(filter-out ,$(test_compilers_engines)) ifneq ($(OS), Windows_NT) - bold := $(shell tput bold) - green := $(shell tput setaf 2) - reset := $(shell tput sgr0) + 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 '') endif @@ -90,6 +99,10 @@ 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)) +endif + $(info Host target: $(bold)$(green)$(HOST_TARGET)$(reset)) $(info Available compilers: $(bold)$(green)${compilers}$(reset)) $(info Compilers features: $(bold)$(green)${compiler_features}$(reset)) @@ -376,7 +389,9 @@ ifeq ($(UNAME_S), Darwin) # Fix the rpath for the dylib install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib else - cp target/release/libwasmer_c_api.so package/lib/libwasmer.so + if [ -f target/release/libwasmer_c_api.so ]; then \ + cp target/release/libwasmer_c_api.so package/lib/libwasmer.so ;\ + fi; \ cp target/release/libwasmer_c_api.a package/lib/libwasmer.a endif endif diff --git a/examples/engine_cross_compilation.rs b/examples/engine_cross_compilation.rs index d5644c35d3d..5bcfa6a9edc 100644 --- a/examples/engine_cross_compilation.rs +++ b/examples/engine_cross_compilation.rs @@ -102,7 +102,8 @@ fn main() -> Result<(), Box> { #[cfg(not(any( windows, // We don't support yet crosscompilation in macOS with Apple Silicon - all(target_os = "macos", target_arch = "aarch64") + all(target_os = "macos", target_arch = "aarch64"), + target_env = "musl", )))] fn test_cross_compilation() -> Result<(), Box> { main() diff --git a/examples/engine_headless.rs b/examples/engine_headless.rs index 40b4881d6ea..1f1170af3d0 100644 --- a/examples/engine_headless.rs +++ b/examples/engine_headless.rs @@ -147,7 +147,7 @@ fn main() -> Result<(), Box> { } #[test] -#[cfg(not(any(windows, target_arch = "aarch64")))] +#[cfg(not(any(windows, target_arch = "aarch64", target_env = "musl")))] fn test_engine_headless() -> Result<(), Box> { main() } diff --git a/examples/engine_native.rs b/examples/engine_native.rs index 3345d0e5bb7..e9f72d1bf97 100644 --- a/examples/engine_native.rs +++ b/examples/engine_native.rs @@ -87,7 +87,7 @@ fn main() -> Result<(), Box> { } #[test] -#[cfg(not(target_arch = "aarch64"))] +#[cfg(not(any(target_arch = "aarch64", target_env = "musl")))] fn test_engine_native() -> Result<(), Box> { main() } diff --git a/tests/compilers/traps.rs b/tests/compilers/traps.rs index aa8d99f8cc9..c619c20459f 100644 --- a/tests/compilers/traps.rs +++ b/tests/compilers/traps.rs @@ -43,6 +43,7 @@ fn test_trap_return() -> Result<()> { feature = "test-singlepass", feature = "test-native", target_arch = "aarch64", + target_env = "musl", ), ignore )] @@ -130,6 +131,7 @@ fn test_trap_trace_cb() -> Result<()> { feature = "test-singlepass", feature = "test-native", target_arch = "aarch64", + target_env = "musl", ), ignore )] @@ -169,6 +171,7 @@ fn test_trap_stack_overflow() -> Result<()> { feature = "test-llvm", feature = "test-native", target_arch = "aarch64", + target_env = "musl", ), ignore )] @@ -210,6 +213,7 @@ RuntimeError: unreachable feature = "test-llvm", feature = "test-native", target_arch = "aarch64", + target_env = "musl", ), ignore )] @@ -424,7 +428,8 @@ fn mismatched_arguments() -> Result<()> { feature = "test-singlepass", feature = "test-llvm", feature = "test-native", - all(target_os = "macos", target_arch = "aarch64") + all(target_os = "macos", target_arch = "aarch64"), + target_env = "musl", ), ignore )] @@ -464,6 +469,7 @@ RuntimeError: indirect call type mismatch feature = "test-llvm", feature = "test-native", target_arch = "aarch64", + target_env = "musl", ), ignore )]