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 Feb 12, 2021
1 parent 4f28b2b commit 79574e0
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 38 deletions.
65 changes: 50 additions & 15 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 @@ -77,14 +83,20 @@ jobs:
CARGO_SCCACHE_VERSION: 0.2.14-alpha.0-parity
SCCACHE_AZURE_BLOB_CONTAINER: wasmerstoragesccacheblob
SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.SCCACHE_AZURE_CONNECTION_STRING }}
TARGET: ${{ matrix.target }}
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 @@ -125,7 +137,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 Down Expand Up @@ -172,26 +183,43 @@ jobs:
- name: Test
run: |
make test
if: matrix.target != 'aarch64-apple-darwin'
if: matrix.build != 'macos-arm64' && 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: Test C API (musl)
run: |
CC=musl-gcc LIBC=musl make test-capi

This comment has been minimized.

Copy link
@Hywan

Hywan Feb 12, 2021

Contributor

At this point, we should just have the CC value inside the matrix?

if: matrix.build == 'linux-musl-x64'
- 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'
- name: Build C API (musl)
run: |
LIBC=musl WASMER_CAPI_USE_SYSTEM_LIBFFI=1 make build-capi
if: 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
if: needs.setup.outputs.DOING_RELEASE == '1' && matrix.build != 'linux-musl-x64'
run: |
make build-wapm
if: needs.setup.outputs.DOING_RELEASE == '1'
- name: Install Nightly Rust for Headless
uses: actions-rs/toolchain@v1
with:
Expand All @@ -201,6 +229,7 @@ jobs:
components: "rust-src"
if: needs.setup.outputs.DOING_RELEASE == '1'
- name: Build Minimal Wasmer Headless
if: needs.setup.outputs.DOING_RELEASE == '1' && matrix.build != 'linux-musl-x64'
run: |
cargo install xargo
echo "" >> Cargo.toml
Expand All @@ -215,12 +244,13 @@ jobs:
echo "codegen-units = 1" >> Cargo.toml
echo "rpath = false" >> Cargo.toml
make build-wasmer-headless-minimal
if: needs.setup.outputs.DOING_RELEASE == '1'
- name: Copy target binaries
run: |
mkdir -p target/release
cp target/${{matrix.target}}/release/wasmer* target/release
cp target/${{matrix.target}}/release/libwasmer* target/release
if find target/${{matrix.target}}/release -type f -name 'libwasmer*' -maxdepth 1 | grep -q "."; then
cp target/${{matrix.target}}/release/libwasmer* target/release
fi
if [ -d "wapm-cli" ]; then
mkdir -p wapm-cli/target/release
cp wapm-cli/target/${{matrix.target}}/release/wapm* wapm-cli/target/release
Expand All @@ -242,7 +272,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 Expand Up @@ -347,7 +377,6 @@ jobs:
uses: actions/download-artifact@v2
with:
path: artifacts

- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand All @@ -358,7 +387,6 @@ jobs:
release_name: Release ${{ needs.setup.outputs.VERSION }}
draft: true
prerelease: false

- name: Upload Release Asset Windows Installer
uses: actions/upload-release-asset@v1
env:
Expand All @@ -368,7 +396,6 @@ jobs:
asset_path: artifacts/wasmer-windows-amd64/WasmerInstaller.exe
asset_name: wasmer-windows.exe
asset_content_type: application/vnd.microsoft.portable-executable

- name: Upload Release Asset Windows
uses: actions/upload-release-asset@v1
env:
Expand All @@ -378,7 +405,6 @@ jobs:
asset_path: artifacts/wasmer-windows-amd64/wasmer.tar.gz
asset_name: wasmer-windows-amd64.tar.gz
asset_content_type: application/gzip

- name: Upload Release Asset Linux amd64
uses: actions/upload-release-asset@v1
env:
Expand All @@ -388,7 +414,16 @@ jobs:
asset_path: artifacts/wasmer-linux-amd64/wasmer.tar.gz
asset_name: wasmer-linux-amd64.tar.gz
asset_content_type: application/gzip

- name: Upload Release Asset Linux amd64 (musl)
id: upload-release-asset-linux-musl-amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifacts/wasmer-linux-musl-amd64/wasmer.tar.gz
asset_name: wasmer-linux-musl-amd64.tar.gz
asset_content_type: application/gzip
- name: Upload Release Asset Mac amd64
uses: actions/upload-release-asset@v1
env:
Expand Down
59 changes: 38 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ ifneq ($(OS), Windows_NT)
ARCH := $(shell uname -m)
UNAME_S := $(shell uname -s)
LIBC ?= $(shell ldd 2>&1 | grep -o musl | head -n1)
TARGET ?= $(CARGO_BUILD_TARGET)
else
# We can assume, if in windows it will likely be in x86_64
ARCH := x86_64
UNAME_S :=
LIBC ?=
TARGET ?= $(CARGO_BUILD_TARGET)
endif

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

ifneq (, $(TARGET))
$(info Target: $(bold)$(green)$(TARGET)$(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))
$(info Available compilers + engines for test: $(bold)$(green)${test_compilers_engines}$(reset))

ifneq (,$(TARGET))
TARGET := $(TARGET)/
endif

############
# Building #
Expand Down Expand Up @@ -335,13 +344,13 @@ package-wapm:
mkdir -p "package/bin"
ifneq ($(OS), Windows_NT)
if [ -d "wapm-cli" ]; then \
cp wapm-cli/target/release/wapm package/bin/ ;\
cp wapm-cli/target/$(TARGET)release/wapm package/bin/ ;\
echo "#!/bin/bash\nwapm execute \"\$$@\"" > package/bin/wax ;\
chmod +x package/bin/wax ;\
fi
else
if [ -d "wapm-cli" ]; then \
cp wapm-cli/target/release/wapm package/bin/ ;\
cp wapm-cli/target/$(TARGET)release/wapm package/bin/ ;\
fi
ifeq ($(UNAME_S), Darwin)
codesign -s - package/bin/wapm
Expand All @@ -362,9 +371,9 @@ endif
package-wasmer:
mkdir -p "package/bin"
ifeq ($(OS), Windows_NT)
cp target/release/wasmer.exe package/bin/
cp target/$(TARGET)release/wasmer.exe package/bin/
else
cp target/release/wasmer package/bin/
cp target/$(TARGET)release/wasmer package/bin/
ifeq ($(UNAME_S), Darwin)
codesign -s - package/bin/wasmer
endif
Expand All @@ -377,25 +386,33 @@ package-capi:
cp lib/c-api/wasmer_wasm.h* package/include
cp lib/c-api/wasm.h* package/include
cp lib/c-api/README.md package/include/README.md
ifeq ($(OS), Windows_NT)
cp target/release/wasmer_c_api.dll package/lib/wasmer.dll
cp target/release/wasmer_c_api.lib package/lib/wasmer.lib
else
ifeq ($(UNAME_S), Darwin)

# Windows
if [ -f target/$(TARGET)release/wasmer_c_api.dll ]; then \
cp target/$(TARGET)release/wasmer_c_api.dll package/lib/wasmer.dll ;\
fi
if [ -f target/$(TARGET)release/wasmer_c_api.lib ]; then \
cp target/$(TARGET)release/wasmer_c_api.lib package/lib/wasmer.lib ;\
fi

# Darwin
# For some reason in macOS arm64 there are issues if we copy constantly in the install_name_tool util
rm -f package/lib/libwasmer.dylib
cp target/release/libwasmer_c_api.dylib package/lib/libwasmer.dylib
cp target/release/libwasmer_c_api.a package/lib/libwasmer.a
# Fix the rpath for the dylib
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib
else
# In some cases the .so may not be available, for example when building against musl (static linking)
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
if [ -f target/$(TARGET)release/libwasmer_c_api.dylib ]; then \
cp target/$(TARGET)release/libwasmer_c_api.dylib package/lib/libwasmer.dylib ;\
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib ;\
fi

if [ -f target/$(TARGET)release/libwasmer_c_api.so ]; then \
cp target/$(TARGET)release/libwasmer_c_api.so package/lib/libwasmer.so ;\
fi
if [ -f target/$(TARGET)release/libwasmer_c_api.a ]; then \
cp target/$(TARGET)release/libwasmer_c_api.a package/lib/libwasmer.a ;\
fi

# Inspect
ls -lhaR target/$(TARGET)release
ls -lhaR package

package-docs: build-docs build-docs-capi
mkdir -p "package/docs"
Expand Down
1 change: 1 addition & 0 deletions bors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ status = [
"Audit",
"Code lint",
"Test on linux-x64",
"Test on linux-musl-x64",
"Test on linux-aarch64",
"Test on macos-x64",
"Test on windows-x64",
Expand Down
17 changes: 15 additions & 2 deletions lib/c-api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
//! * setting `inline-c` up.
use cbindgen::{Builder, Language};
use std::{env, fs, path::PathBuf};
use std::{
env, fs,
path::{Path, PathBuf},
};

const PRE_HEADER: &'static str = r#"
// Define the `ARCH_X86_X64` constant.
Expand Down Expand Up @@ -556,7 +559,17 @@ fn build_inline_c_env_vars() {
} else if cfg!(target_os = "macos") {
"libwasmer_c_api.dylib".to_string()
} else {
"libwasmer_c_api.so".to_string()
let path = format!(
"{shared_object_dir}/{lib}",
shared_object_dir = shared_object_dir,
lib = "libwasmer_c_api.so"
);

if Path::new(path.as_str()).exists() {
"libwasmer_c_api.so".to_string()
} else {
"libwasmer_c_api.a".to_string()
}
}
);
}
5 changes: 5 additions & 0 deletions lib/c-api/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# ignore wasm-c-api binaries
wasm-c-api-*
test-*
wasm-c-api/example/*

# Unignore files ending with `.c` (i.e. `wasm-c-api-wasi.c`)
!*.c
!wasm-c-api/example/*.c
!wasm-c-api/example/*.cc
!wasm-c-api/example/*.wasm
!wasm-c-api/example/*.wat

0 comments on commit 79574e0

Please sign in to comment.