Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/ci/build-release-artifacts.sh
1685 views
1
#!/bin/bash
2
3
# A script to build the release artifacts of Wasmtime into the `target`
4
# directory. For now this is the CLI and the C API. Note that this script only
5
# produces the artifacts through Cargo and doesn't package things up. That's
6
# intended for the `build-tarballs.sh` script.
7
#
8
# This script takes a Rust target as its first input and optionally a parameter
9
# afterwards which can be "-min" to indicate that a minimal build should be
10
# produced with as many features as possible stripped out.
11
12
set -ex
13
14
build=$1
15
target=$2
16
wrapper=""
17
18
# If `$DOCKER_IMAGE` is set then run the build inside of that docker container
19
# instead of on the host machine. In CI this uses `./ci/docker/*/Dockerfile` to
20
# have precise glibc requirements for Linux platforms for example.
21
if [ "$DOCKER_IMAGE" != "" ]; then
22
if [ -f "$DOCKER_IMAGE" ]; then
23
docker build --tag build-image --file $DOCKER_IMAGE ci/docker
24
DOCKER_IMAGE=build-image
25
fi
26
27
# Inherit the environment's rustc and env vars related to cargo/rust, and then
28
# otherwise re-execute ourselves and we'll be missing `$DOCKER_IMAGE` in the
29
# container so we'll continue below.
30
exec docker run --interactive \
31
--volume `pwd`:`pwd` \
32
--volume `rustc --print sysroot`:/rust:ro \
33
--workdir `pwd` \
34
--interactive \
35
--env-file <(env | grep 'CARGO\|RUST') \
36
$DOCKER_IMAGE \
37
bash -c "PATH=\$PATH:/rust/bin RUSTFLAGS=\"\$RUSTFLAGS \$EXTRA_RUSTFLAGS\" `pwd`/$0 $*"
38
fi
39
40
# Default build flags for release artifacts. Leave debugging for
41
# builds-from-source which have richer information anyway, and additionally the
42
# CLI won't benefit from catching unwinds and neither will the C API so use
43
# panic=abort in both situations.
44
export CARGO_PROFILE_RELEASE_STRIP=debuginfo
45
export CARGO_PROFILE_RELEASE_PANIC=abort
46
47
if [[ "$build" = *-min ]]; then
48
# Configure a whole bunch of compile-time options which help reduce the size
49
# of the binary artifact produced.
50
export CARGO_PROFILE_RELEASE_OPT_LEVEL=s
51
export RUSTFLAGS="-Zlocation-detail=none $RUSTFLAGS"
52
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
53
export CARGO_PROFILE_RELEASE_LTO=true
54
build_std=-Zbuild-std=std,panic_abort
55
build_std_features=-Zbuild-std-features=std_detect_dlsym_getauxval
56
flags="$build_std $build_std_features --no-default-features --features disable-logging"
57
cmake_flags="-DWASMTIME_DISABLE_ALL_FEATURES=ON"
58
cmake_flags="$cmake_flags -DWASMTIME_FEATURE_DISABLE_LOGGING=ON"
59
cmake_flags="$cmake_flags -DWASMTIME_USER_CARGO_BUILD_OPTIONS:LIST=$build_std;$build_std_features"
60
else
61
# For release builds the CLI is built a bit more feature-ful than the Cargo
62
# defaults to provide artifacts that can do as much as possible.
63
bin_flags="--features all-arch,component-model,component-model-async"
64
fi
65
66
if [[ "$target" = "x86_64-pc-windows-msvc" ]]; then
67
# Avoid emitting `/DEFAULTLIB:MSVCRT` into the static library by using clang.
68
export CC=clang
69
export CXX=clang++
70
fi
71
72
cargo build --release $flags --target $target -p wasmtime-cli $bin_flags --features run
73
74
# For the C API force unwind tables to be emitted to make the generated objects
75
# more flexible. Embedders can always build without this but this enables
76
# libunwind to produce better backtraces by default when Wasmtime is linked into
77
# a different project that wants to unwind.
78
export RUSTFLAGS="$RUSTFLAGS -C force-unwind-tables"
79
80
# Shrink the size of `*.a` artifacts without spending too much extra time in CI.
81
# See #11476 for some more context. Here Windows builds achieve this with 1 CGU
82
# which results in modest size gains, and other platforms use LTO to achieve
83
# much more significant size gains. The reason the platforms are different is
84
# that CI is extremely slow on Windows, almost 2x slower, so this is an attempt
85
# to keep CI cycle time under control.
86
case $build in
87
*-mingw* | *-windows*)
88
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
89
;;
90
*)
91
export CARGO_PROFILE_RELEASE_LTO=true
92
;;
93
esac
94
95
mkdir -p target/c-api-build
96
cd target/c-api-build
97
cmake \
98
-G Ninja \
99
../../crates/c-api \
100
$cmake_flags \
101
-DCMAKE_BUILD_TYPE=Release \
102
-DWASMTIME_TARGET=$target \
103
-DCMAKE_INSTALL_PREFIX=../c-api-install \
104
-DCMAKE_INSTALL_LIBDIR=../c-api-install/lib
105
cmake --build . --target install
106
107