|
10 | 10 | #
|
11 | 11 | # $FEATURES - a list of Vector features to include when building, defaults to all
|
12 | 12 | # $NATIVE_BUILD - whether to pass the --target flag when building via cargo
|
| 13 | +# $RUST_LTO - possible values are "lto", "lto=thin", "" |
13 | 14 | # $TARGET - a target triple. ex: x86_64-apple-darwin
|
14 | 15 | # $VERSION - the version of Vector, can be obtained via `make version`
|
15 | 16 |
|
16 | 17 | NATIVE_BUILD=${NATIVE_BUILD:-}
|
| 18 | +RUST_LTO=${RUST_LTO:-} |
17 | 19 |
|
18 | 20 | set -eu
|
19 | 21 |
|
@@ -46,8 +48,26 @@ if [ "$FEATURES" != "default" ]; then
|
46 | 48 | build_flags="$build_flags --no-default-features --features $FEATURES"
|
47 | 49 | fi
|
48 | 50 |
|
| 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 | + |
49 | 66 | cargo build $build_flags
|
50 | 67 |
|
| 68 | +# Strip the output binary |
| 69 | +strip $target_dir/release/vector |
| 70 | + |
51 | 71 | # Build the archive directory
|
52 | 72 | rm -rf $archive_dir
|
53 | 73 | mkdir -p $archive_dir
|
|
0 commit comments