Skip to content

Commit

Permalink
chore: Build Wasmer on musl
Browse files Browse the repository at this point in the history
Closes #1482
Closes #1766
  • Loading branch information
jubianchi committed Jan 14, 2021
1 parent 98cf81c commit 4a58338
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 21 deletions.
37 changes: 28 additions & 9 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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" {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 23 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion examples/engine_cross_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
#[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<dyn std::error::Error>> {
main()
Expand Down
2 changes: 1 addition & 1 deletion examples/engine_headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

#[test]
#[cfg(not(any(windows, target_arch = "aarch64")))]
#[cfg(not(any(windows, target_arch = "aarch64", target_env = "musl")))]
fn test_engine_headless() -> Result<(), Box<dyn std::error::Error>> {
main()
}
2 changes: 1 addition & 1 deletion examples/engine_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

#[test]
#[cfg(not(target_arch = "aarch64"))]
#[cfg(not(any(target_arch = "aarch64", target_env = "musl")))]
fn test_engine_native() -> Result<(), Box<dyn std::error::Error>> {
main()
}
8 changes: 7 additions & 1 deletion tests/compilers/traps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn test_trap_return() -> Result<()> {
feature = "test-singlepass",
feature = "test-native",
target_arch = "aarch64",
target_env = "musl",
),
ignore
)]
Expand Down Expand Up @@ -130,6 +131,7 @@ fn test_trap_trace_cb() -> Result<()> {
feature = "test-singlepass",
feature = "test-native",
target_arch = "aarch64",
target_env = "musl",
),
ignore
)]
Expand Down Expand Up @@ -169,6 +171,7 @@ fn test_trap_stack_overflow() -> Result<()> {
feature = "test-llvm",
feature = "test-native",
target_arch = "aarch64",
target_env = "musl",
),
ignore
)]
Expand Down Expand Up @@ -210,6 +213,7 @@ RuntimeError: unreachable
feature = "test-llvm",
feature = "test-native",
target_arch = "aarch64",
target_env = "musl",
),
ignore
)]
Expand Down Expand Up @@ -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
)]
Expand Down Expand Up @@ -464,6 +469,7 @@ RuntimeError: indirect call type mismatch
feature = "test-llvm",
feature = "test-native",
target_arch = "aarch64",
target_env = "musl",
),
ignore
)]
Expand Down

0 comments on commit 4a58338

Please sign in to comment.