Skip to content

Commit 3b9291d

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

File tree

5 files changed

+143
-39
lines changed

5 files changed

+143
-39
lines changed

.github/workflows/main.yaml

+88-16
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
@@ -77,14 +77,15 @@ jobs:
7777
CARGO_SCCACHE_VERSION: 0.2.14-alpha.0-parity
7878
SCCACHE_AZURE_BLOB_CONTAINER: wasmerstoragesccacheblob
7979
SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.SCCACHE_AZURE_CONNECTION_STRING }}
80+
TARGET: ${{ matrix.target }}
8081
steps:
8182
- uses: actions/checkout@v2
8283
- name: Set up libstdc++ on Linux
84+
if: matrix.build == 'linux-x64'
8385
run: |
8486
sudo apt-get update -y
8587
sudo apt-get install -y --allow-downgrades libstdc++6=8.4.0-1ubuntu1~18.04
8688
sudo apt-get install --reinstall g++-8
87-
if: matrix.os == 'ubuntu-18.04'
8889
- name: Install Rust ${{ matrix.rust }}
8990
uses: actions-rs/toolchain@v1
9091
with:
@@ -125,7 +126,6 @@ jobs:
125126
~/.cargo/registry
126127
~/.cargo/git
127128
key: ${{ matrix.build }}-${{ matrix.target }}-cargo-${{ hashFiles('Cargo.lock') }}-v1
128-
# Install sccache
129129
- uses: actions/cache@v2
130130
with:
131131
path: ${{ runner.tool_cache }}/cargo-sccache
@@ -172,7 +172,7 @@ jobs:
172172
- name: Test
173173
run: |
174174
make test
175-
if: matrix.target != 'aarch64-apple-darwin'
175+
if: matrix.build != 'macos-arm64'
176176
- name: Test C API
177177
run: |
178178
make test-capi
@@ -189,9 +189,9 @@ jobs:
189189
run: |
190190
make build-wasmer
191191
- name: Build Wapm binary
192+
if: needs.setup.outputs.DOING_RELEASE == '1'
192193
run: |
193194
make build-wapm
194-
if: needs.setup.outputs.DOING_RELEASE == '1'
195195
- name: Install Nightly Rust for Headless
196196
uses: actions-rs/toolchain@v1
197197
with:
@@ -201,6 +201,7 @@ jobs:
201201
components: "rust-src"
202202
if: needs.setup.outputs.DOING_RELEASE == '1'
203203
- name: Build Minimal Wasmer Headless
204+
if: needs.setup.outputs.DOING_RELEASE == '1'
204205
run: |
205206
cargo install xargo
206207
echo "" >> Cargo.toml
@@ -215,12 +216,13 @@ jobs:
215216
echo "codegen-units = 1" >> Cargo.toml
216217
echo "rpath = false" >> Cargo.toml
217218
make build-wasmer-headless-minimal
218-
if: needs.setup.outputs.DOING_RELEASE == '1'
219219
- name: Copy target binaries
220220
run: |
221221
mkdir -p target/release
222222
cp target/${{matrix.target}}/release/wasmer* target/release
223-
cp target/${{matrix.target}}/release/libwasmer* target/release
223+
if find target/${{matrix.target}}/release -type f -name 'libwasmer*' -maxdepth 1 | grep -q "."; then
224+
cp target/${{matrix.target}}/release/libwasmer* target/release
225+
fi
224226
if [ -d "wapm-cli" ]; then
225227
mkdir -p wapm-cli/target/release
226228
cp wapm-cli/target/${{matrix.target}}/release/wapm* wapm-cli/target/release
@@ -242,7 +244,7 @@ jobs:
242244
make test-integration
243245
if: matrix.run_integration_tests && matrix.os != 'windows-latest'
244246
- name: Cross compile from Linux
245-
if: matrix.os == 'ubuntu-18.04'
247+
if: matrix.build == 'linux-x64'
246248
shell: bash
247249
run: |
248250
ls target/release
@@ -289,6 +291,71 @@ jobs:
289291
if-no-files-found: error
290292
retention-days: 1
291293

294+
test-docker:
295+
name: Test on ${{ matrix.build }}
296+
runs-on: ubuntu-latest
297+
needs: setup
298+
strategy:
299+
fail-fast: false
300+
matrix:
301+
include:
302+
- build: linux-musl-x64
303+
image: alpine:latest
304+
rust: 1.48
305+
artifact_name: 'wasmer-linux-musl-amd64'
306+
steps:
307+
- uses: actions/checkout@v2
308+
309+
- uses: addnab/docker-run-action@v1
310+
with:
311+
image: ${{ matrix.image }}
312+
options: -v ${{ github.workspace }}:/work
313+
run: |
314+
# Set up tools
315+
apk add musl-dev curl make libtool libffi-dev gcc automake autoconf
316+
317+
# Install Rust ${{ matrix.rust }}
318+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
319+
sh ./rustup.sh -y
320+
source ~/.cargo/env
321+
rm -f ./rustup.sh
322+
323+
# Change working directory
324+
cd /work
325+
326+
# Inspect
327+
pwd
328+
ls -lha
329+
330+
# Test
331+
make test
332+
333+
# Test C API
334+
make test-capi
335+
336+
# Build C API
337+
make build-capi
338+
339+
# Build Wasmer binary
340+
make build-wasmer
341+
342+
# Build Wapm binary
343+
make build-wapm
344+
345+
# Dist
346+
make distribution
347+
348+
# Run integration tests
349+
export WASMER_DIR=`pwd`/package
350+
make test-integration
351+
- name: Upload Artifacts
352+
uses: actions/upload-artifact@v2
353+
with:
354+
name: ${{ matrix.artifact_name }}
355+
path: dist
356+
if-no-files-found: error
357+
retention-days: 1
358+
292359
test-cross-compile-on-linux:
293360
name: Test cross-compile on linux
294361
needs: [setup, test]
@@ -347,7 +414,6 @@ jobs:
347414
uses: actions/download-artifact@v2
348415
with:
349416
path: artifacts
350-
351417
- name: Create Release
352418
id: create_release
353419
uses: actions/create-release@v1
@@ -358,7 +424,6 @@ jobs:
358424
release_name: Release ${{ needs.setup.outputs.VERSION }}
359425
draft: true
360426
prerelease: false
361-
362427
- name: Upload Release Asset Windows Installer
363428
uses: actions/upload-release-asset@v1
364429
env:
@@ -368,7 +433,6 @@ jobs:
368433
asset_path: artifacts/wasmer-windows-amd64/WasmerInstaller.exe
369434
asset_name: wasmer-windows.exe
370435
asset_content_type: application/vnd.microsoft.portable-executable
371-
372436
- name: Upload Release Asset Windows
373437
uses: actions/upload-release-asset@v1
374438
env:
@@ -378,7 +442,6 @@ jobs:
378442
asset_path: artifacts/wasmer-windows-amd64/wasmer.tar.gz
379443
asset_name: wasmer-windows-amd64.tar.gz
380444
asset_content_type: application/gzip
381-
382445
- name: Upload Release Asset Linux amd64
383446
uses: actions/upload-release-asset@v1
384447
env:
@@ -388,7 +451,16 @@ jobs:
388451
asset_path: artifacts/wasmer-linux-amd64/wasmer.tar.gz
389452
asset_name: wasmer-linux-amd64.tar.gz
390453
asset_content_type: application/gzip
391-
454+
- name: Upload Release Asset Linux amd64 (musl)
455+
id: upload-release-asset-linux-musl-amd64
456+
uses: actions/upload-release-asset@v1
457+
env:
458+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
459+
with:
460+
upload_url: ${{ steps.create_release.outputs.upload_url }}
461+
asset_path: artifacts/wasmer-linux-musl-amd64/wasmer.tar.gz
462+
asset_name: wasmer-linux-musl-amd64.tar.gz
463+
asset_content_type: application/gzip
392464
- name: Upload Release Asset Mac amd64
393465
uses: actions/upload-release-asset@v1
394466
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",

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)