Path: blob/main/ci/build-release-artifacts.sh
1685 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_abort54build_std_features=-Zbuild-std-features=std_detect_dlsym_getauxval55flags="$build_std $build_std_features --no-default-features --features disable-logging"56cmake_flags="-DWASMTIME_DISABLE_ALL_FEATURES=ON"57cmake_flags="$cmake_flags -DWASMTIME_FEATURE_DISABLE_LOGGING=ON"58cmake_flags="$cmake_flags -DWASMTIME_USER_CARGO_BUILD_OPTIONS:LIST=$build_std;$build_std_features"59else60# For release builds the CLI is built a bit more feature-ful than the Cargo61# defaults to provide artifacts that can do as much as possible.62bin_flags="--features all-arch,component-model,component-model-async"63fi6465if [[ "$target" = "x86_64-pc-windows-msvc" ]]; then66# Avoid emitting `/DEFAULTLIB:MSVCRT` into the static library by using clang.67export CC=clang68export CXX=clang++69fi7071cargo build --release $flags --target $target -p wasmtime-cli $bin_flags --features run7273# For the C API force unwind tables to be emitted to make the generated objects74# more flexible. Embedders can always build without this but this enables75# libunwind to produce better backtraces by default when Wasmtime is linked into76# a different project that wants to unwind.77export RUSTFLAGS="$RUSTFLAGS -C force-unwind-tables"7879# Shrink the size of `*.a` artifacts without spending too much extra time in CI.80# See #11476 for some more context. Here Windows builds achieve this with 1 CGU81# which results in modest size gains, and other platforms use LTO to achieve82# much more significant size gains. The reason the platforms are different is83# that CI is extremely slow on Windows, almost 2x slower, so this is an attempt84# to keep CI cycle time under control.85case $build in86*-mingw* | *-windows*)87export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=188;;89*)90export CARGO_PROFILE_RELEASE_LTO=true91;;92esac9394mkdir -p target/c-api-build95cd target/c-api-build96cmake \97-G Ninja \98../../crates/c-api \99$cmake_flags \100-DCMAKE_BUILD_TYPE=Release \101-DWASMTIME_TARGET=$target \102-DCMAKE_INSTALL_PREFIX=../c-api-install \103-DCMAKE_INSTALL_LIBDIR=../c-api-install/lib104cmake --build . --target install105106107