Path: blob/main/ci/build-release-artifacts.sh
3064 views
#!/bin/bash12# A script to build the release artifacts of Wasmtime into the `target`3# directory. For now this is the CLI and the C API. Note that this script only4# produces the artifacts through Cargo and doesn't package things up. That's5# intended for the `build-tarballs.sh` script.6#7# This script takes a Rust target as its first input and optionally a parameter8# afterwards which can be "-min" to indicate that a minimal build should be9# produced with as many features as possible stripped out.1011set -ex1213build=$114target=$215wrapper=""1617# If `$DOCKER_IMAGE` is set then run the build inside of that docker container18# instead of on the host machine. In CI this uses `./ci/docker/*/Dockerfile` to19# have precise glibc requirements for Linux platforms for example.20if [ "$DOCKER_IMAGE" != "" ]; then21if [ -f "$DOCKER_IMAGE" ]; then22docker build --tag build-image --file $DOCKER_IMAGE ci/docker23DOCKER_IMAGE=build-image24fi2526# Inherit the environment's rustc and env vars related to cargo/rust, and then27# otherwise re-execute ourselves and we'll be missing `$DOCKER_IMAGE` in the28# container so we'll continue below.29exec docker run --interactive \30--volume `pwd`:`pwd` \31--volume `rustc --print sysroot`:/rust:ro \32--workdir `pwd` \33--interactive \34--env-file <(env | grep 'CARGO\|RUST') \35$DOCKER_IMAGE \36bash -c "PATH=\$PATH:/rust/bin RUSTFLAGS=\"\$RUSTFLAGS \$EXTRA_RUSTFLAGS\" `pwd`/$0 $*"37fi3839# Default build flags for release artifacts. Leave debugging for40# builds-from-source which have richer information anyway, and additionally the41# CLI won't benefit from catching unwinds and neither will the C API so use42# panic=abort in both situations.43export CARGO_PROFILE_RELEASE_STRIP=debuginfo44export CARGO_PROFILE_RELEASE_PANIC=abort4546if [[ "$build" = *-min ]]; then47# Configure a whole bunch of compile-time options which help reduce the size48# of the binary artifact produced.49export CARGO_PROFILE_RELEASE_OPT_LEVEL=s50export RUSTFLAGS="-Zlocation-detail=none $RUSTFLAGS"51export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=152export CARGO_PROFILE_RELEASE_LTO=true53build_std=-Zbuild-std=std,panic_abort54flags="$build_std --no-default-features --features disable-logging"55cmake_flags="-DWASMTIME_DISABLE_ALL_FEATURES=ON"56cmake_flags="$cmake_flags -DWASMTIME_FEATURE_DISABLE_LOGGING=ON"57cmake_flags="$cmake_flags -DWASMTIME_USER_CARGO_BUILD_OPTIONS:LIST=$build_std"58else59# For release builds the CLI is built a bit more feature-ful than the Cargo60# defaults to provide artifacts that can do as much as possible.61bin_flags="--features all-arch,component-model"62fi6364if [[ "$target" = "x86_64-pc-windows-msvc" ]]; then65# Avoid emitting `/DEFAULTLIB:MSVCRT` into the static library by using clang.66export CC=clang67export CXX=clang++68fi6970cargo build --release $flags --target $target -p wasmtime-cli $bin_flags --features run7172# For the C API force unwind tables to be emitted to make the generated objects73# more flexible. Embedders can always build without this but this enables74# libunwind to produce better backtraces by default when Wasmtime is linked into75# a different project that wants to unwind.76export RUSTFLAGS="$RUSTFLAGS -C force-unwind-tables"7778# Shrink the size of `*.a` artifacts without spending too much extra time in CI.79# See #11476 for some more context. Here Windows builds achieve this with 1 CGU80# which results in modest size gains, and other platforms use LTO to achieve81# much more significant size gains. The reason the platforms are different is82# that CI is extremely slow on Windows, almost 2x slower, so this is an attempt83# to keep CI cycle time under control.84case $build in85*-mingw* | *-windows*)86export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=187;;88*)89export CARGO_PROFILE_RELEASE_LTO=true90;;91esac9293mkdir -p target/c-api-build94cd target/c-api-build95cmake \96-G Ninja \97../../crates/c-api \98$cmake_flags \99-DCMAKE_BUILD_TYPE=Release \100-DWASMTIME_TARGET=$target \101-DCMAKE_INSTALL_PREFIX=../c-api-install \102-DCMAKE_INSTALL_LIBDIR=../c-api-install/lib103cmake --build . --target install104105106