Skip to content

Commit ef587b5

Browse files
cgwaltersrh-atomic-bot
authored andcommitted
build-sys: Turn Rust LTO off by default, add --enable-lto flag
For us, this is primarily right now a size issue. See: https://internals.rust-lang.org/t/rust-staticlibs-and-optimizing-for-size/5746 For more information, there are these two issues: rust-lang/cargo#4349 https://bugzilla.mozilla.org/show_bug.cgi?id=1386371 The basic issue here is that a build with LTO off (and a trivial change to add a `println!` takes 14s here, and with it on takes 38s. However, with LTO off the stripped size of `librpmostree_rust.a` is `6M`, with LTO on it's `1.1M`. I named this `--enable-lto` as I'd like to investigate doing this for the C code too. Closes: #1664 Approved by: jlebon
1 parent 0abfcec commit ef587b5

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

configure.ac

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fi
228228
AC_MSG_RESULT($debug_release)
229229

230230
dnl These bits based on gnome:librsvg/configure.ac
231-
dnl By default, we build in public release mode.
231+
dnl By default, we build in release mode (but without LTO!)
232232
AC_ARG_ENABLE(rust-debug,
233233
AC_HELP_STRING([--enable-rust-debug],
234234
[Build Rust code with debugging information [default=no]]),
@@ -244,6 +244,19 @@ AM_CONDITIONAL(RUST_DEBUG, [test "x$rust_debug_release" = "xdebug"])
244244
dnl Unconditional now.
245245
RPM_OSTREE_FEATURES="$RPM_OSTREE_FEATURES rust"
246246

247+
dnl Only use this for package builds, as it will hackily edit Cargo.toml right now
248+
AC_ARG_ENABLE(lto,
249+
AC_HELP_STRING([--enable-lto],
250+
[Build code with Link Time Optimization [default=no]]))
251+
dnl https://github.com/rust-lang/cargo/issues/4349
252+
dnl https://bugzilla.mozilla.org/show_bug.cgi?id=1386371
253+
if test "${enable_lto}" = yes; then
254+
if ! grep -q '^lto.*=true' rust/Cargo.toml 2>/dev/null; then
255+
echo '# Inserted by configure --enable-lto' >> rust/Cargo.toml
256+
echo "lto = true" >> rust/Cargo.toml
257+
fi
258+
fi
259+
247260
dnl And propagate the release/debug type to cmake
248261
cmake_args=-DCMAKE_BUILD_TYPE=RelWithDebugInfo
249262
if test ${debug_release} = debug; then
@@ -286,6 +299,6 @@ echo "
286299
introspection: $found_introspection
287300
bubblewrap: $with_bubblewrap
288301
gtk-doc: $enable_gtk_doc
289-
rust: $rust_debug_release
302+
rust: $rust_debug_release (lto: ${enable_lto:-no})
290303
cbindgen: ${cbindgen:-internal}
291304
"

rust/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ path = "src/lib.rs"
2424
crate-type = ["staticlib"]
2525

2626
[profile.release]
27+
# Unwinding across FFI boundaries is undefined behavior, and anyways, we're
28+
# [crash-only](https://en.wikipedia.org/wiki/Crash-only_software)
2729
panic = "abort"
28-
lto = true
30+
# We assume we're being delivered via e.g. RPM which supports split debuginfo
2931
debug = true
32+
# For true release builds, we do suggest you enable LTO via e.g.
33+
# env RUSTFLAGS='-C lto=true' as part of the outer build. It's just
34+
# off by default because it's quite slow and the default is more oriented
35+
# towards local development.

0 commit comments

Comments
 (0)