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 12, 2021
1 parent dd69438 commit 362f136
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 46 deletions.
88 changes: 62 additions & 26 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,48 @@ jobs:
echo $DOING_RELEASE
test:
name: Test on ${{ matrix.build }}
name: Test on ${{ matrix.id }}
runs-on: ${{ matrix.os }}
needs: setup
strategy:
fail-fast: false
matrix:
build: [linux-x64, macos-x64, macos-arm64, windows-x64, linux-aarch64]
include:
- build: linux-x64
- id: linux-x64
os: ubuntu-18.04
rust: 1.48
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-amd64.tar.gz'
artifact_name: 'wasmer-linux-amd64'
cross_compilation_artifact_name: 'cross_compiled_from_linux'
run_integration_tests: true
- build: macos-x64
- id: linux-musl-x64
os: ubuntu-18.04
rust: 1.48
target: x86_64-unknown-linux-musl
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-amd64.tar.gz'
artifact_name: 'wasmer-linux-musl-amd64'
cross_compilation_artifact_name: 'cross_compiled_from_linux'
run_integration_tests: true
- id: macos-x64
os: macos-latest
rust: 1.48
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/darwin-amd64.tar.gz'
artifact_name: 'wasmer-darwin-amd64'
cross_compilation_artifact_name: 'cross_compiled_from_mac'
run_integration_tests: true
- build: macos-arm64
- id: macos-arm64
os: macos-11.0
rust: 1.49
target: aarch64-apple-darwin
artifact_name: 'wasmer-darwin-arm64'
- build: windows-x64
- id: windows-x64
os: windows-latest
rust: 1.48
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/windows-amd64.tar.gz'
artifact_name: 'wasmer-windows-amd64'
cross_compilation_artifact_name: 'cross_compiled_from_win'
run_integration_tests: true
- build: linux-aarch64
- id: linux-aarch64
os: [self-hosted, linux, ARM64]
random_sccache_port: true
rust: 1.48
Expand All @@ -80,24 +87,29 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up libstdc++ on Linux
if: matrix.id == '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.id == '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:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true
- name: Install LLVM (Windows)
if: matrix.os == 'windows-latest'
if: matrix.id == 'windows-x64'
shell: cmd
run: |
choco install llvm
- name: Install LLVM
if: matrix.os != 'windows-latest' && matrix.os != 'macos-11.0'
if: matrix.id != 'windows-x64' && matrix.id != 'macos-arm64' && matrix.id != 'linux-musl-x64'
shell: bash
run: |
curl --proto '=https' --tlsv1.2 -sSf ${{ matrix.llvm_url }} -L -o llvm.tar.gz
Expand All @@ -108,37 +120,37 @@ jobs:
env:
LLVM_DIR: ${{ github.workspace }}/llvm-10
- name: Set up dependencies for Mac OS
if: matrix.id == 'macos-x64' || matrix.id == 'macos-arm64'
run: |
brew install automake
# using gnu-tar is a workaround for https://github.com/actions/cache/issues/403
brew install gnu-tar
echo PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" >> $GITHUB_ENV
if: matrix.os == 'macos-latest' || matrix.os == 'macos-11.0'
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ matrix.build }}-${{ matrix.target }}-cargo-${{ hashFiles('Cargo.lock') }}-v1
# Install sccache
key: ${{ matrix.id }}-${{ matrix.target }}-cargo-${{ hashFiles('Cargo.lock') }}-v1
- uses: actions/cache@v2
with:
path: ${{ runner.tool_cache }}/cargo-sccache
key: ${{ matrix.build }}-${{ matrix.target }}-sccache-bin-${{ env.CARGO_SCCACHE_VERSION }}-v1
key: ${{ matrix.id }}-${{ matrix.target }}-sccache-bin-${{ env.CARGO_SCCACHE_VERSION }}-v1
- name: Install sccache
run: |
if [ ! -f ${{ runner.tool_cache }}/cargo-sccache/bin/sccache ]; then
cargo install sccache --git https://github.com/paritytech/sccache.git --no-default-features --features=dist-client,azure --root ${{ runner.tool_cache }}/cargo-sccache
fi
shell: bash
- name: Setup Rust target
if: matrix.target
run: |
cat << EOF > .cargo/config.toml
[build]
target = "${{ matrix.target }}"
EOF
if: matrix.target
- name: Set sccache port
if: matrix.random_sccache_port
run: |
netstat -aln | awk '
$6 == "LISTEN" {
Expand All @@ -156,7 +168,6 @@ jobs:
' >> $GITHUB_ENV
# echo "SCCACHE_SERVER_PORT=9000"
echo "Setting random sccache port to: $SCCACHE_SERVER_PORT"
if: matrix.random_sccache_port
shell: bash
- name: Start sccache
run: |
Expand All @@ -165,28 +176,53 @@ jobs:
${{ runner.tool_cache }}/cargo-sccache/bin/sccache -s
echo "RUSTC_WRAPPER=${{ runner.tool_cache }}/cargo-sccache/bin/sccache" >> $GITHUB_ENV
- name: Test
if: matrix.id != 'macos-arm64' && matrix.id != 'linux-musl-x64'
run: |
make test
- name: Test (musl)
if: matrix.id == 'linux-musl-x64'
run: |
make test
if: matrix.target != 'aarch64-apple-darwin'
env:
LIBC: musl
- name: Test C API
if: matrix.id != 'windows-x64' && matrix.id != 'macos-arm64' && matrix.id != 'linux-musl-x64' # we can't test yet on Apple Silicon or Windows
run: |
make test-capi
- name: Test C API (musl)
if: matrix.id == 'linux-musl-x64'
run: |
make test-capi
if: matrix.os != 'windows-latest' && matrix.target != 'aarch64-apple-darwin' # we can't test yet on Apple Silicon or Windows
env:
LIBC: musl
- name: Build C API
if: matrix.id != 'macos-arm64' && matrix.id != 'linux-musl-x64'
run: |
make build-capi
- name: Build C API (musl)
if: matrix.id == 'linux-musl-x64'
run: |
make build-capi
if: matrix.target != 'aarch64-apple-darwin'
env:
LIBC: musl
- name: Build C API (system libffi)
if: matrix.id != 'macos-arm64'
run: |
make build-capi-cranelift-system-libffi
if: matrix.target == 'aarch64-apple-darwin'
- name: Build Wasmer binary
if: matrix.id != 'linux-musl-x64'
run: |
make build-wasmer
- name: Build Wasmer binary (musl)
if: matrix.id == 'linux-musl-x64'
run: |
make build-wasmer
env:
LIBC: musl
- name: Build Wapm binary
if: needs.setup.outputs.DOING_RELEASE == '1'
run: |
make build-wapm
if: needs.setup.outputs.DOING_RELEASE == '1'
- name: Copy target binaries
run: |
mkdir -p target/release
Expand All @@ -201,19 +237,19 @@ jobs:
run: |
make distribution
- name: Run integration tests (Windows)
if: matrix.run_integration_tests && matrix.id == 'windows-x64'
shell: cmd
run: |
call refreshenv
set WASMER_DIR=%CD%\package
make test-integration
if: matrix.run_integration_tests && matrix.os == 'windows-latest'
- name: Run integration tests (Unix)
if: matrix.run_integration_tests && matrix.id != 'windows-x64'
run: |
export WASMER_DIR=`pwd`/package
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.id == 'linux-x64'
shell: bash
run: |
ls target/release
Expand All @@ -225,7 +261,7 @@ jobs:
#cp qjs_win_from_linux.wjit cross
cp target/release/wasmer cross
- name: Cross compile from Mac
if: matrix.os == 'macos-latest'
if: matrix.id == 'macos-x64'
shell: bash
run: |
ls target/release
Expand All @@ -237,7 +273,7 @@ jobs:
#cp qjs_win_from_mac.wjit cross
cp target/release/wasmer cross
#- name: Cross compile from Windows
# if: matrix.os == 'windows-latest'
# if: matrix.id == 'windows-x64'
# shell: bash
# run: |
# alias wasmer=target/release/wasmer
Expand Down
26 changes: 19 additions & 7 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 All @@ -32,14 +34,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 @@ -73,15 +82,18 @@ 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


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

ifneq (, $(LIBC))
$(info C standard library: $(bold)$(green)$(LIBC)$(reset))
endif
$(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))
Expand Down
10 changes: 0 additions & 10 deletions examples/engine_cross_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,3 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

#[test]
#[cfg(not(any(
windows,
// We don't support yet crosscompilation in macOS with Apple Silicon
all(target_os = "macos", target_arch = "aarch64")
)))]
fn test_cross_compilation() -> Result<(), Box<dyn std::error::Error>> {
main()
}
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 362f136

Please sign in to comment.