From cc93e8f7f0476c89e1a2ca3a27518e0a7c4177aa Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 20 May 2024 19:58:23 -0500 Subject: [PATCH] Add release binaries for x86_64-musl (#8668) * Add release binaries for x86_64-musl This was requested in bytecodealliance/wasmtime-py#237 and shouldn't cost us too much in terms of CI resources and maintenance overhead. * Fix combining rustflags prtest:full --- ci/build-build-matrix.js | 5 +++++ ci/build-release-artifacts.sh | 2 +- ci/docker/x86_64-musl/Dockerfile | 17 +++++++++++++++++ crates/wasmtime/build.rs | 4 ++++ docs/stability-tiers.md | 6 ++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 ci/docker/x86_64-musl/Dockerfile diff --git a/ci/build-build-matrix.js b/ci/build-build-matrix.js index 842348c969..321eca46d9 100644 --- a/ci/build-build-matrix.js +++ b/ci/build-build-matrix.js @@ -59,6 +59,11 @@ const array = [ "os": "ubuntu-latest", "target": "x86_64-linux-android", }, + { + "build": "x86_64-musl", + "os": "ubuntu-latest", + "target": "x86_64-unknown-linux-musl", + }, ]; const builds = []; diff --git a/ci/build-release-artifacts.sh b/ci/build-release-artifacts.sh index 5c0118a401..cd91e43003 100755 --- a/ci/build-release-artifacts.sh +++ b/ci/build-release-artifacts.sh @@ -25,7 +25,7 @@ if [[ "$build" = *-min ]]; then # Configure a whole bunch of compile-time options which help reduce the size # of the binary artifact produced. export CARGO_PROFILE_RELEASE_OPT_LEVEL=s - export RUSTFLAGS=-Zlocation-detail=none + export RUSTFLAGS="-Zlocation-detail=none $RUSTFLAGS" export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 export CARGO_PROFILE_RELEASE_LTO=true build_std=-Zbuild-std=std,panic_abort diff --git a/ci/docker/x86_64-musl/Dockerfile b/ci/docker/x86_64-musl/Dockerfile new file mode 100644 index 0000000000..c34c19bb83 --- /dev/null +++ b/ci/docker/x86_64-musl/Dockerfile @@ -0,0 +1,17 @@ +# Rust binaries need `libgcc_s.so` but ubuntu's musl toolchain does not have it. +# Get it from alpine instead. +FROM alpine:3.16 as libgcc_s_src +RUN apk add libgcc + +# Use something glibc-based for the actual compile because the Rust toolchain +# we're using is glibc-based in CI. +FROM ubuntu:24.04 +RUN apt-get update -y && apt-get install -y cmake musl-tools +COPY --from=libgcc_s_src /usr/lib/libgcc_s.so.1 /usr/lib/x86_64-linux-musl + +ENV PATH=$PATH:/rust/bin + +# Note that `-crt-feature` is passed here to specifically disable static linking +# with musl. We want a `*.so` to pop out so static linking isn't what we want. +ENV RUSTFLAGS=-Ctarget-feature=-crt-static +ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc diff --git a/crates/wasmtime/build.rs b/crates/wasmtime/build.rs index 300234af3a..5622bc4739 100644 --- a/crates/wasmtime/build.rs +++ b/crates/wasmtime/build.rs @@ -35,4 +35,8 @@ fn build_c_helpers() { println!("cargo:rerun-if-changed=src/runtime/vm/helpers.c"); build.file("src/runtime/vm/helpers.c"); build.compile("wasmtime-helpers"); + + if os == "linux" { + println!("cargo:rustc-link-lib=m"); + } } diff --git a/docs/stability-tiers.md b/docs/stability-tiers.md index 3894be35fa..a038e296e4 100644 --- a/docs/stability-tiers.md +++ b/docs/stability-tiers.md @@ -91,6 +91,7 @@ For explanations of what each tier means see below. | Target | `wasm32-wasi` [^3] | Supported but not tested | | Target | `aarch64-linux-android` | CI testing, full-time maintainer | | Target | `x86_64-linux-android` | CI testing, full-time maintainer | +| Target | `x86_64-unknown-linux-musl` [^4] | CI testing, full-time maintainer | | Compiler Backend | Winch on aarch64 | finished implementation | | WebAssembly Proposal | [`gc`] | Complete implementation | | WASI Proposal | [`wasi-nn`] | More expansive CI testing | @@ -119,6 +120,11 @@ as well. but not the `runtime` feature at this time. This means that Wasmtime-compiled-to-wasm can itself compile wasm but cannot execute wasm. +[^4]: Binary artifacts for MUSL are dynamically linked, not statically +linked, meaning that they are not suitable for "run on any linux distribution" +style use cases. Wasmtime does not have static binary artifacts at this time and +that will require building from source. + #### Unsupported features and platforms While this is not an exhaustive list, Wasmtime does not currently have support