Skip to content

Commit d2df9ba

Browse files
a-rodinbinarylogic
authored andcommitted
chore: Build for x86_64-unknown-linux-musl with all features and optimized binary size (#689)
Signed-off-by: Alexander Rodin <[email protected]>
1 parent e37995e commit d2df9ba

File tree

3 files changed

+365
-20
lines changed

3 files changed

+365
-20
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ jobs:
183183
name: Build archive
184184
command: |
185185
export VERSION=$(make version)
186-
make build-archive FEATURES="jemallocator"
186+
export RUST_LTO="lto"
187+
make build-archive FEATURES="jemallocator leveldb rdkafka rdkafka/cmake_build"
187188
- persist_to_workspace:
188189
root: target/artifacts
189190
paths:

scripts/build-archive.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
#
1111
# $FEATURES - a list of Vector features to include when building, defaults to all
1212
# $NATIVE_BUILD - whether to pass the --target flag when building via cargo
13+
# $RUST_LTO - possible values are "lto", "lto=thin", ""
1314
# $TARGET - a target triple. ex: x86_64-apple-darwin
1415
# $VERSION - the version of Vector, can be obtained via `make version`
1516

1617
NATIVE_BUILD=${NATIVE_BUILD:-}
18+
RUST_LTO=${RUST_LTO:-}
1719

1820
set -eu
1921

@@ -46,8 +48,26 @@ if [ "$FEATURES" != "default" ]; then
4648
build_flags="$build_flags --no-default-features --features $FEATURES"
4749
fi
4850

51+
# Currently the only way to set Rust codegen LTO type (-C lto, as opposed to
52+
# -C compiler-plugin-lto) at build time for a crate with library dependencies
53+
# is to patch Cargo.toml before the build. See
54+
# https://github.com/rust-lang/cargo/issues/4349 and
55+
# https://bugzilla.mozilla.org/show_bug.cgi?id=1386371#c2.
56+
if [ -n "$RUST_LTO" ]; then
57+
cp Cargo.toml Cargo.toml.orig
58+
trap "mv Cargo.toml.orig Cargo.toml" EXIT
59+
case "$RUST_LTO" in
60+
lto) lto_value="true";;
61+
lto=thin) lto_value="\"thin\"";;
62+
esac
63+
printf "[profile.release]\nlto = $lto_value" >> Cargo.toml
64+
fi
65+
4966
cargo build $build_flags
5067

68+
# Strip the output binary
69+
strip $target_dir/release/vector
70+
5171
# Build the archive directory
5272
rm -rf $archive_dir
5373
mkdir -p $archive_dir

0 commit comments

Comments
 (0)