Skip to content

Commit 55523c2

Browse files
committed
chore: Build Wasmer on musl
Closes wasmerio#1482 Closes wasmerio#1766
1 parent 4f28b2b commit 55523c2

File tree

6 files changed

+114
-38
lines changed

6 files changed

+114
-38
lines changed

.github/workflows/main.yaml

+53-15
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
3838
strategy:
3939
fail-fast: false
4040
matrix:
41-
build: [linux-x64, macos-x64, macos-arm64, windows-x64, linux-aarch64]
4241
include:
4342
- build: linux-x64
4443
os: ubuntu-18.04
@@ -47,6 +46,13 @@ jobs:
4746
artifact_name: 'wasmer-linux-amd64'
4847
cross_compilation_artifact_name: 'cross_compiled_from_linux'
4948
run_integration_tests: true
49+
- build: linux-musl-x64
50+
os: ubuntu-18.04
51+
rust: 1.48
52+
target: x86_64-unknown-linux-musl
53+
artifact_name: 'wasmer-linux-musl-amd64'
54+
cross_compilation_artifact_name: 'cross_compiled_from_linux'
55+
run_integration_tests: false
5056
- build: macos-x64
5157
os: macos-latest
5258
rust: 1.48
@@ -77,14 +83,20 @@ jobs:
7783
CARGO_SCCACHE_VERSION: 0.2.14-alpha.0-parity
7884
SCCACHE_AZURE_BLOB_CONTAINER: wasmerstoragesccacheblob
7985
SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.SCCACHE_AZURE_CONNECTION_STRING }}
86+
TARGET: ${{ matrix.target }}
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:
@@ -125,7 +137,6 @@ jobs:
125137
~/.cargo/registry
126138
~/.cargo/git
127139
key: ${{ matrix.build }}-${{ matrix.target }}-cargo-${{ hashFiles('Cargo.lock') }}-v1
128-
# Install sccache
129140
- uses: actions/cache@v2
130141
with:
131142
path: ${{ runner.tool_cache }}/cargo-sccache
@@ -172,26 +183,46 @@ jobs:
172183
- name: Test
173184
run: |
174185
make test
175-
if: matrix.target != 'aarch64-apple-darwin'
186+
if: matrix.build != 'macos-arm64' && matrix.build != 'linux-musl-x64'
187+
- name: Test (musl)
188+
if: matrix.build == 'linux-musl-x64'
189+
run: |
190+
LIBC=musl WASMER_CAPI_USE_SYSTEM_LIBFFI=1 make test
176191
- name: Test C API
177192
run: |
178193
make test-capi
179-
if: matrix.os != 'windows-latest' && matrix.target != 'aarch64-apple-darwin' # we can't test yet on Apple Silicon or Windows
194+
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
195+
- name: Test C API (musl)
196+
run: |
197+
CC=musl-gcc LIBC=musl WASMER_CAPI_USE_SYSTEM_LIBFFI=1 make test-capi-cranelift-jit
198+
LIBC=musl make test-capi-tests
199+
CC=musl-gcc LIBC=musl WASMER_CAPI_USE_SYSTEM_LIBFFI=1 make test-capi-singlepass-jit
200+
LIBC=musl make test-capi-tests
201+
if: matrix.build == 'linux-musl-x64'
180202
- name: Build C API
181203
run: |
182204
make build-capi
183-
if: matrix.target != 'aarch64-apple-darwin'
205+
if: matrix.target != 'aarch64-apple-darwin' && matrix.build != 'linux-musl-x64'
184206
- name: Build C API (system libffi)
185207
run: |
186208
make build-capi-cranelift-system-libffi
187209
if: matrix.target == 'aarch64-apple-darwin'
210+
- name: Build C API (musl)
211+
run: |
212+
LIBC=musl WASMER_CAPI_USE_SYSTEM_LIBFFI=1 make build-capi
213+
if: matrix.build == 'linux-musl-x64'
188214
- name: Build Wasmer binary
215+
if: matrix.build != 'linux-musl-x64'
189216
run: |
190217
make build-wasmer
218+
- name: Build Wasmer binary (musl)
219+
if: matrix.build == 'linux-musl-x64'
220+
run: |
221+
LIBC=musl WASMER_CAPI_USE_SYSTEM_LIBFFI=1 make build-wasmer
191222
- name: Build Wapm binary
223+
if: needs.setup.outputs.DOING_RELEASE == '1' && matrix.build != 'linux-musl-x64'
192224
run: |
193225
make build-wapm
194-
if: needs.setup.outputs.DOING_RELEASE == '1'
195226
- name: Install Nightly Rust for Headless
196227
uses: actions-rs/toolchain@v1
197228
with:
@@ -201,6 +232,7 @@ jobs:
201232
components: "rust-src"
202233
if: needs.setup.outputs.DOING_RELEASE == '1'
203234
- name: Build Minimal Wasmer Headless
235+
if: needs.setup.outputs.DOING_RELEASE == '1' && matrix.build != 'linux-musl-x64'
204236
run: |
205237
cargo install xargo
206238
echo "" >> Cargo.toml
@@ -215,12 +247,13 @@ jobs:
215247
echo "codegen-units = 1" >> Cargo.toml
216248
echo "rpath = false" >> Cargo.toml
217249
make build-wasmer-headless-minimal
218-
if: needs.setup.outputs.DOING_RELEASE == '1'
219250
- name: Copy target binaries
220251
run: |
221252
mkdir -p target/release
222253
cp target/${{matrix.target}}/release/wasmer* target/release
223-
cp target/${{matrix.target}}/release/libwasmer* target/release
254+
if find target/${{matrix.target}}/release -type f -name 'libwasmer*' -maxdepth 1 | grep -q "."; then
255+
cp target/${{matrix.target}}/release/libwasmer* target/release
256+
fi
224257
if [ -d "wapm-cli" ]; then
225258
mkdir -p wapm-cli/target/release
226259
cp wapm-cli/target/${{matrix.target}}/release/wapm* wapm-cli/target/release
@@ -242,7 +275,7 @@ jobs:
242275
make test-integration
243276
if: matrix.run_integration_tests && matrix.os != 'windows-latest'
244277
- name: Cross compile from Linux
245-
if: matrix.os == 'ubuntu-18.04'
278+
if: matrix.build == 'linux-x64'
246279
shell: bash
247280
run: |
248281
ls target/release
@@ -347,7 +380,6 @@ jobs:
347380
uses: actions/download-artifact@v2
348381
with:
349382
path: artifacts
350-
351383
- name: Create Release
352384
id: create_release
353385
uses: actions/create-release@v1
@@ -358,7 +390,6 @@ jobs:
358390
release_name: Release ${{ needs.setup.outputs.VERSION }}
359391
draft: true
360392
prerelease: false
361-
362393
- name: Upload Release Asset Windows Installer
363394
uses: actions/upload-release-asset@v1
364395
env:
@@ -368,7 +399,6 @@ jobs:
368399
asset_path: artifacts/wasmer-windows-amd64/WasmerInstaller.exe
369400
asset_name: wasmer-windows.exe
370401
asset_content_type: application/vnd.microsoft.portable-executable
371-
372402
- name: Upload Release Asset Windows
373403
uses: actions/upload-release-asset@v1
374404
env:
@@ -378,7 +408,6 @@ jobs:
378408
asset_path: artifacts/wasmer-windows-amd64/wasmer.tar.gz
379409
asset_name: wasmer-windows-amd64.tar.gz
380410
asset_content_type: application/gzip
381-
382411
- name: Upload Release Asset Linux amd64
383412
uses: actions/upload-release-asset@v1
384413
env:
@@ -388,7 +417,16 @@ jobs:
388417
asset_path: artifacts/wasmer-linux-amd64/wasmer.tar.gz
389418
asset_name: wasmer-linux-amd64.tar.gz
390419
asset_content_type: application/gzip
391-
420+
- name: Upload Release Asset Linux amd64 (musl)
421+
id: upload-release-asset-linux-musl-amd64
422+
uses: actions/upload-release-asset@v1
423+
env:
424+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
425+
with:
426+
upload_url: ${{ steps.create_release.outputs.upload_url }}
427+
asset_path: artifacts/wasmer-linux-musl-amd64/wasmer.tar.gz
428+
asset_name: wasmer-linux-musl-amd64.tar.gz
429+
asset_content_type: application/gzip
392430
- name: Upload Release Asset Mac amd64
393431
uses: actions/upload-release-asset@v1
394432
env:

Makefile

+34-21
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ ifneq ($(OS), Windows_NT)
33
ARCH := $(shell uname -m)
44
UNAME_S := $(shell uname -s)
55
LIBC ?= $(shell ldd 2>&1 | grep -o musl | head -n1)
6+
TARGET ?= $(CARGO_BUILD_TARGET)
67
else
78
# We can assume, if in windows it will likely be in x86_64
89
ARCH := x86_64
910
UNAME_S :=
1011
LIBC ?=
12+
TARGET ?= $(CARGO_BUILD_TARGET)
1113
endif
1214

1315
# Which compilers we build. These have dependencies that may not be on the system.
@@ -103,11 +105,18 @@ ifneq (, $(LIBC))
103105
$(info C standard library: $(bold)$(green)$(LIBC)$(reset))
104106
endif
105107

108+
ifneq (, $(TARGET))
109+
$(info Target: $(bold)$(green)$(TARGET)$(reset))
110+
endif
111+
106112
$(info Host target: $(bold)$(green)$(HOST_TARGET)$(reset))
107113
$(info Available compilers: $(bold)$(green)${compilers}$(reset))
108114
$(info Compilers features: $(bold)$(green)${compiler_features}$(reset))
109115
$(info Available compilers + engines for test: $(bold)$(green)${test_compilers_engines}$(reset))
110116

117+
ifneq (,$(TARGET))
118+
TARGET := $(TARGET)/
119+
endif
111120

112121
############
113122
# Building #
@@ -335,13 +344,13 @@ package-wapm:
335344
mkdir -p "package/bin"
336345
ifneq ($(OS), Windows_NT)
337346
if [ -d "wapm-cli" ]; then \
338-
cp wapm-cli/target/release/wapm package/bin/ ;\
347+
cp wapm-cli/target/$(TARGET)release/wapm package/bin/ ;\
339348
echo "#!/bin/bash\nwapm execute \"\$$@\"" > package/bin/wax ;\
340349
chmod +x package/bin/wax ;\
341350
fi
342351
else
343352
if [ -d "wapm-cli" ]; then \
344-
cp wapm-cli/target/release/wapm package/bin/ ;\
353+
cp wapm-cli/target/$(TARGET)release/wapm package/bin/ ;\
345354
fi
346355
ifeq ($(UNAME_S), Darwin)
347356
codesign -s - package/bin/wapm
@@ -362,9 +371,9 @@ endif
362371
package-wasmer:
363372
mkdir -p "package/bin"
364373
ifeq ($(OS), Windows_NT)
365-
cp target/release/wasmer.exe package/bin/
374+
cp target/$(TARGET)release/wasmer.exe package/bin/
366375
else
367-
cp target/release/wasmer package/bin/
376+
cp target/$(TARGET)release/wasmer package/bin/
368377
ifeq ($(UNAME_S), Darwin)
369378
codesign -s - package/bin/wasmer
370379
endif
@@ -377,25 +386,29 @@ package-capi:
377386
cp lib/c-api/wasmer_wasm.h* package/include
378387
cp lib/c-api/wasm.h* package/include
379388
cp lib/c-api/README.md package/include/README.md
380-
ifeq ($(OS), Windows_NT)
381-
cp target/release/wasmer_c_api.dll package/lib/wasmer.dll
382-
cp target/release/wasmer_c_api.lib package/lib/wasmer.lib
383-
else
384-
ifeq ($(UNAME_S), Darwin)
389+
390+
# Windows
391+
if [ -f target/$(TARGET)release/wasmer_c_api.dll ]; then \
392+
cp target/$(TARGET)release/wasmer_c_api.dll package/lib/wasmer.dll ;\
393+
fi
394+
if [ -f target/$(TARGET)release/wasmer_c_api.lib ]; then \
395+
cp target/$(TARGET)release/wasmer_c_api.lib package/lib/wasmer.lib ;\
396+
fi
397+
398+
# Darwin
385399
# For some reason in macOS arm64 there are issues if we copy constantly in the install_name_tool util
386400
rm -f package/lib/libwasmer.dylib
387-
cp target/release/libwasmer_c_api.dylib package/lib/libwasmer.dylib
388-
cp target/release/libwasmer_c_api.a package/lib/libwasmer.a
389-
# Fix the rpath for the dylib
390-
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib
391-
else
392-
# In some cases the .so may not be available, for example when building against musl (static linking)
393-
if [ -f target/release/libwasmer_c_api.so ]; then \
394-
cp target/release/libwasmer_c_api.so package/lib/libwasmer.so ;\
395-
fi;
396-
cp target/release/libwasmer_c_api.a package/lib/libwasmer.a
397-
endif
398-
endif
401+
if [ -f target/$(TARGET)release/libwasmer_c_api.dylib ]; then \
402+
cp target/$(TARGET)release/libwasmer_c_api.dylib package/lib/libwasmer.dylib ;\
403+
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib ;\
404+
fi
405+
406+
if [ -f target/$(TARGET)release/libwasmer_c_api.so ]; then \
407+
cp target/$(TARGET)release/libwasmer_c_api.so package/lib/libwasmer.so ;\
408+
fi
409+
if [ -f target/$(TARGET)release/libwasmer_c_api.a ]; then \
410+
cp target/$(TARGET)release/libwasmer_c_api.a package/lib/libwasmer.a ;\
411+
fi
399412

400413
package-docs: build-docs build-docs-capi
401414
mkdir -p "package/docs"

bors.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ status = [
22
"Audit",
33
"Code lint",
44
"Test on linux-x64",
5+
"Test on linux-musl-x64",
56
"Test on linux-aarch64",
67
"Test on macos-x64",
78
"Test on windows-x64",

docker/Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM alpine
2+
3+
RUN apk add curl tar wget make gcc musl-dev musl-tools autoconf automake libtool
4+
5+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > install.sh && \
6+
sh ./install.sh -y

lib/c-api/build.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
//! * setting `inline-c` up.
55
66
use cbindgen::{Builder, Language};
7-
use std::{env, fs, path::PathBuf};
7+
use std::{
8+
env, fs,
9+
path::{Path, PathBuf},
10+
};
811

912
const PRE_HEADER: &'static str = r#"
1013
// Define the `ARCH_X86_X64` constant.
@@ -556,7 +559,17 @@ fn build_inline_c_env_vars() {
556559
} else if cfg!(target_os = "macos") {
557560
"libwasmer_c_api.dylib".to_string()
558561
} else {
559-
"libwasmer_c_api.so".to_string()
562+
let path = format!(
563+
"{shared_object_dir}/{lib}",
564+
shared_object_dir = shared_object_dir,
565+
lib = "libwasmer_c_api.so"
566+
);
567+
568+
if Path::new(path.as_str()).exists() {
569+
"libwasmer_c_api.so".to_string()
570+
} else {
571+
"libwasmer_c_api.a".to_string()
572+
}
560573
}
561574
);
562575
}

lib/c-api/tests/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# ignore wasm-c-api binaries
22
wasm-c-api-*
33
test-*
4+
wasm-c-api/example/*
45

56
# Unignore files ending with `.c` (i.e. `wasm-c-api-wasi.c`)
67
!*.c
8+
!wasm-c-api/example/*.c
9+
!wasm-c-api/example/*.cc
10+
!wasm-c-api/example/*.wasm
11+
!wasm-c-api/example/*.wat

0 commit comments

Comments
 (0)