Skip to content

Commit 424b311

Browse files
committed
chore: Build Wasmer on musl
Closes wasmerio#1482 Closes wasmerio#1766
1 parent fd84bbe commit 424b311

File tree

6 files changed

+78
-44
lines changed

6 files changed

+78
-44
lines changed

.github/workflows/main.yaml

+42-22
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ env:
66
on:
77
push:
88
branches:
9-
- 'master'
10-
- 'staging'
11-
- 'trying'
9+
- '**'
10+
# - 'master'
11+
# - 'staging'
12+
# - 'trying'
1213
tags:
1314
# this is _not_ a regex, see: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
1415
- '[0-9]+.[0-9]+.[0-9]+*'
@@ -38,7 +39,6 @@ jobs:
3839
strategy:
3940
fail-fast: false
4041
matrix:
41-
build: [linux-x64, macos-x64, macos-arm64, windows-x64, linux-aarch64]
4242
include:
4343
- build: linux-x64
4444
os: ubuntu-18.04
@@ -47,44 +47,56 @@ jobs:
4747
artifact_name: 'wasmer-linux-amd64'
4848
cross_compilation_artifact_name: 'cross_compiled_from_linux'
4949
run_integration_tests: true
50+
- build: linux-musl-x64
51+
os: ubuntu-18.04
52+
rust: 1.48
53+
target: x86_64-unknown-linux-musl
54+
artifact_name: 'wasmer-linux-musl-amd64'
55+
cross_compilation_artifact_name: 'cross_compiled_from_linux'
56+
run_integration_tests: false
5057
- build: macos-x64
5158
os: macos-latest
5259
rust: 1.48
5360
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/darwin-amd64.tar.gz'
5461
artifact_name: 'wasmer-darwin-amd64'
5562
cross_compilation_artifact_name: 'cross_compiled_from_mac'
5663
run_integration_tests: true
57-
- build: macos-arm64
58-
os: macos-11.0
59-
rust: 1.49
60-
target: aarch64-apple-darwin
61-
artifact_name: 'wasmer-darwin-arm64'
64+
# - build: macos-arm64
65+
# os: macos-11.0
66+
# rust: 1.49
67+
# target: aarch64-apple-darwin
68+
# artifact_name: 'wasmer-darwin-arm64'
6269
- build: windows-x64
6370
os: windows-latest
6471
rust: 1.48
6572
# llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/windows-amd64.tar.gz'
6673
artifact_name: 'wasmer-windows-amd64'
6774
cross_compilation_artifact_name: 'cross_compiled_from_win'
6875
run_integration_tests: true
69-
- build: linux-aarch64
70-
os: [self-hosted, linux, ARM64]
71-
random_sccache_port: true
72-
rust: 1.48
73-
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-aarch64.tar.gz'
74-
artifact_name: 'wasmer-linux-aarch64'
75-
run_integration_tests: false
76+
# - build: linux-aarch64
77+
# os: [self-hosted, linux, ARM64]
78+
# random_sccache_port: true
79+
# rust: 1.48
80+
# llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-aarch64.tar.gz'
81+
# artifact_name: 'wasmer-linux-aarch64'
82+
# run_integration_tests: false
7683
env:
7784
CARGO_SCCACHE_VERSION: 0.2.14-alpha.0-parity
7885
SCCACHE_AZURE_BLOB_CONTAINER: wasmerstoragesccacheblob
7986
SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.SCCACHE_AZURE_CONNECTION_STRING }}
8087
steps:
8188
- uses: actions/checkout@v2
8289
- name: Set up libstdc++ on Linux
90+
if: matrix.build == 'linux-x64'
8391
run: |
8492
sudo apt-get update -y
8593
sudo apt-get install -y --allow-downgrades libstdc++6=8.4.0-1ubuntu1~18.04
8694
sudo apt-get install --reinstall g++-8
87-
if: matrix.os == 'ubuntu-18.04'
95+
- name: Set up musl on Linux
96+
if: matrix.build == 'linux-musl-x64'
97+
run: |
98+
sudo apt-get update -y
99+
sudo apt-get install -y musl-dev musl-tools
88100
- name: Install Rust ${{ matrix.rust }}
89101
uses: actions-rs/toolchain@v1
90102
with:
@@ -124,7 +136,6 @@ jobs:
124136
~/.cargo/registry
125137
~/.cargo/git
126138
key: ${{ matrix.build }}-${{ matrix.target }}-cargo-${{ hashFiles('Cargo.lock') }}-v1
127-
# Install sccache
128139
- uses: actions/cache@v2
129140
with:
130141
path: ${{ runner.tool_cache }}/cargo-sccache
@@ -171,22 +182,31 @@ jobs:
171182
- name: Test
172183
run: |
173184
make test
174-
if: matrix.target != 'aarch64-apple-darwin'
185+
if: matrix.target != 'aarch64-apple-darwin' && matrix.build != 'linux-musl-x64'
186+
- name: Test (musl)
187+
if: matrix.build == 'linux-musl-x64'
188+
run: |
189+
LIBC=musl WASMER_CAPI_USE_SYSTEM_LIBFFI=1 make test
175190
- name: Test C API
176191
run: |
177192
make test-capi
178-
if: matrix.os != 'windows-latest' && matrix.target != 'aarch64-apple-darwin' # we can't test yet on Apple Silicon or Windows
193+
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
179194
- name: Build C API
180195
run: |
181196
make build-capi
182-
if: matrix.target != 'aarch64-apple-darwin'
197+
if: matrix.target != 'aarch64-apple-darwin' && matrix.build != 'linux-musl-x64'
183198
- name: Build C API (system libffi)
184199
run: |
185200
make build-capi-cranelift-system-libffi
186201
if: matrix.target == 'aarch64-apple-darwin'
187202
- name: Build Wasmer binary
203+
if: matrix.build != 'linux-musl-x64'
188204
run: |
189205
make build-wasmer
206+
- name: Build Wasmer binary (musl)
207+
if: matrix.build == 'linux-musl-x64'
208+
run: |
209+
LIBC=musl WASMER_CAPI_USE_SYSTEM_LIBFFI=1 make build-wasmer
190210
- name: Build Wapm binary
191211
run: |
192212
make build-wapm
@@ -241,7 +261,7 @@ jobs:
241261
make test-integration
242262
if: matrix.run_integration_tests && matrix.os != 'windows-latest'
243263
- name: Cross compile from Linux
244-
if: matrix.os == 'ubuntu-18.04'
264+
if: matrix.build == 'linux-x64'
245265
shell: bash
246266
run: |
247267
ls target/release

Makefile

+27-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
ifneq ($(OS), Windows_NT)
33
ARCH := $(shell uname -m)
44
UNAME_S := $(shell uname -s)
5+
LIBC ?= $(shell ldd 2>&1 | grep -o musl | head -n1)
56
else
67
# We can assume, if in windows it will likely be in x86_64
78
ARCH := x86_64
8-
UNAME_S :=
9+
UNAME_S :=
10+
LIBC ?=
911
endif
1012

1113
# Which compilers we build. These have dependencies that may not be on the system.
@@ -38,14 +40,21 @@ ifeq ($(ARCH), x86_64)
3840
test_compilers_engines += cranelift-jit
3941
# LLVM could be enabled if not in Windows
4042
ifneq ($(OS), Windows_NT)
41-
# Native engine doesn't work on Windows yet.
42-
test_compilers_engines += cranelift-native
43+
ifneq ($(LIBC), musl)
44+
# Native engine doesn't work on Windows and musl yet.
45+
test_compilers_engines += cranelift-native
46+
endif
4347
# Singlepass doesn't work yet on Windows.
4448
compilers += singlepass
4549
# Singlepass doesn't work with the native engine.
4650
test_compilers_engines += singlepass-jit
4751
ifneq (, $(findstring llvm,$(compilers)))
48-
test_compilers_engines += llvm-jit llvm-native
52+
test_compilers_engines += llvm-jit
53+
54+
ifneq ($(LIBC), musl)
55+
# Native engine doesn't work on musl yet.
56+
test_compilers_engines += llvm-native
57+
endif
4958
endif
5059
endif
5160
endif
@@ -79,21 +88,27 @@ compilers := $(filter-out ,$(compilers))
7988
test_compilers_engines := $(filter-out ,$(test_compilers_engines))
8089

8190
ifneq ($(OS), Windows_NT)
82-
bold := $(shell tput bold)
83-
green := $(shell tput setaf 2)
84-
reset := $(shell tput sgr0)
91+
bold := $(shell tput bold 2>/dev/null || echo -n '')
92+
green := $(shell tput setaf 2 2>/dev/null || echo -n '')
93+
reset := $(shell tput sgr0 2>/dev/null || echo -n '')
8594
endif
8695

8796

8897
compiler_features_spaced := $(foreach compiler,$(compilers),$(compiler))
8998
compiler_features := --features "$(compiler_features_spaced)"
9099

91100
HOST_TARGET=$(shell rustup show | grep 'Default host: ' | cut -d':' -f2 | tr -d ' ')
101+
RUSTFLAGS := "-D dead-code -D nonstandard-style -D unused-imports -D unused-mut -D unused-variables -D unused-unsafe -D unreachable-patterns -D bad-style -D improper-ctypes -D unused-allocation -D unused-comparisons -D while-true -D unconditional-recursion -D bare-trait-objects" # TODO: add `-D missing-docs` # TODO: add `-D function_item_references` (not available on Rust 1.47, try when upgrading)
102+
103+
ifneq (, $(LIBC))
104+
$(info C standard library: $(bold)$(green)$(LIBC)$(reset))
105+
endif
92106

93107
$(info Host target: $(bold)$(green)$(HOST_TARGET)$(reset))
94108
$(info Available compilers: $(bold)$(green)${compilers}$(reset))
95109
$(info Compilers features: $(bold)$(green)${compiler_features}$(reset))
96110
$(info Available compilers + engines for test: $(bold)$(green)${test_compilers_engines}$(reset))
111+
$(info RUSTFLAGS: $(bold)$(green)${RUSTFLAGS}$(reset))
97112

98113

99114
############
@@ -376,7 +391,9 @@ ifeq ($(UNAME_S), Darwin)
376391
# Fix the rpath for the dylib
377392
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib
378393
else
379-
cp target/release/libwasmer_c_api.so package/lib/libwasmer.so
394+
if [ -f "target/$(HOST_TARGET)/release/wasmer-headless" ]; then \
395+
cp target/release/libwasmer_c_api.so package/lib/libwasmer.so ;\
396+
fi; \
380397
cp target/release/libwasmer_c_api.a package/lib/libwasmer.a
381398
endif
382399
endif
@@ -413,7 +430,8 @@ endif
413430
update-testsuite:
414431
git subtree pull --prefix tests/wast/spec https://github.com/WebAssembly/testsuite.git master --squash
415432

416-
RUSTFLAGS := "-D dead-code -D nonstandard-style -D unused-imports -D unused-mut -D unused-variables -D unused-unsafe -D unreachable-patterns -D bad-style -D improper-ctypes -D unused-allocation -D unused-comparisons -D while-true -D unconditional-recursion -D bare-trait-objects" # TODO: add `-D missing-docs` # TODO: add `-D function_item_references` (not available on Rust 1.47, try when upgrading)
433+
# TODO: add `-D missing-docs`
434+
# TODO: add `-D function_item_references` (not available on Rust 1.47, try when upgrading)
417435
lint-packages:
418436
RUSTFLAGS=${RUSTFLAGS} cargo clippy -p wasmer
419437
RUSTFLAGS=${RUSTFLAGS} cargo clippy -p wasmer-c-api

examples/engine_cross_compilation.rs

-10
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,3 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
9797

9898
Ok(())
9999
}
100-
101-
#[test]
102-
#[cfg(not(any(
103-
windows,
104-
// We don't support yet crosscompilation in macOS with Apple Silicon
105-
all(target_os = "macos", target_arch = "aarch64")
106-
)))]
107-
fn test_cross_compilation() -> Result<(), Box<dyn std::error::Error>> {
108-
main()
109-
}

examples/engine_headless.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
147147
}
148148

149149
#[test]
150-
#[cfg(not(any(windows, target_arch = "aarch64")))]
150+
#[cfg(not(any(windows, target_arch = "aarch64", target_env = "musl")))]
151151
fn test_engine_headless() -> Result<(), Box<dyn std::error::Error>> {
152152
main()
153153
}

examples/engine_native.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
8787
}
8888

8989
#[test]
90-
#[cfg(not(target_arch = "aarch64"))]
90+
#[cfg(not(any(target_arch = "aarch64", target_env = "musl")))]
9191
fn test_engine_native() -> Result<(), Box<dyn std::error::Error>> {
9292
main()
9393
}

tests/compilers/traps.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fn test_trap_return() -> Result<()> {
4343
feature = "test-singlepass",
4444
feature = "test-native",
4545
target_arch = "aarch64",
46+
target_env = "musl",
4647
),
4748
ignore
4849
)]
@@ -130,6 +131,7 @@ fn test_trap_trace_cb() -> Result<()> {
130131
feature = "test-singlepass",
131132
feature = "test-native",
132133
target_arch = "aarch64",
134+
target_env = "musl",
133135
),
134136
ignore
135137
)]
@@ -169,6 +171,7 @@ fn test_trap_stack_overflow() -> Result<()> {
169171
feature = "test-llvm",
170172
feature = "test-native",
171173
target_arch = "aarch64",
174+
target_env = "musl",
172175
),
173176
ignore
174177
)]
@@ -210,6 +213,7 @@ RuntimeError: unreachable
210213
feature = "test-llvm",
211214
feature = "test-native",
212215
target_arch = "aarch64",
216+
target_env = "musl",
213217
),
214218
ignore
215219
)]
@@ -424,7 +428,8 @@ fn mismatched_arguments() -> Result<()> {
424428
feature = "test-singlepass",
425429
feature = "test-llvm",
426430
feature = "test-native",
427-
all(target_os = "macos", target_arch = "aarch64")
431+
all(target_os = "macos", target_arch = "aarch64"),
432+
target_env = "musl",
428433
),
429434
ignore
430435
)]
@@ -464,6 +469,7 @@ RuntimeError: indirect call type mismatch
464469
feature = "test-llvm",
465470
feature = "test-native",
466471
target_arch = "aarch64",
472+
target_env = "musl",
467473
),
468474
ignore
469475
)]

0 commit comments

Comments
 (0)