rust: Set release profile settings
authorJeffery To <jeffery.to@gmail.com>
Sat, 30 Sep 2023 05:57:43 +0000 (13:57 +0800)
committerJeffery To <jeffery.to@gmail.com>
Wed, 11 Oct 2023 07:50:24 +0000 (15:50 +0800)
* codegen-units, lto, opt-level - Set to values to optimize binary
  size[1].

* overflow-checks - Enabled because in release mode, integer overflows
  are defined as two's complement wrap[2]. It is highly unlikely that
  any program is intentionally relying on this behaviour; it would be
  better to panic instead of continue execution in this case.

* debug, debug-assertions, panic, rpath - Set to their default (release)
  values, to override any settings made by packages, e.g. ripgrep sets
  debug = 1[3].

[1]: https://github.com/johnthagen/min-sized-rust
[2]: https://huonw.github.io/blog/2016/04/myths-and-legends-about-integer-overflow-in-rust/
[3]: https://github.com/BurntSushi/ripgrep/blob/13.0.0/Cargo.toml#L79-L80

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
lang/rust/rust-values.mk

index 0a18cd17f4d0a03d9c735c4810ac160c676d13d6..4c21c27522232bd31c5881bf6e74e0b87df81598 100644 (file)
@@ -81,7 +81,14 @@ CARGO_PKG_CONFIG_VARS= \
        $(RUST_SCCACHE_VARS) \
        CARGO_BUILD_TARGET=$(RUSTC_TARGET_ARCH) \
        CARGO_HOME=$(CARGO_HOME) \
-       CARGO_PROFILE_RELEASE_OPT_LEVEL=s \
+       CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \
+       CARGO_PROFILE_RELEASE_DEBUG=false \
+       CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS=false \
+       CARGO_PROFILE_RELEASE_LTO=true \
+       CARGO_PROFILE_RELEASE_OPT_LEVEL=z \
+       CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS=true \
+       CARGO_PROFILE_RELEASE_PANIC=unwind \
+       CARGO_PROFILE_RELEASE_RPATH=false \
        CARGO_TARGET_$(subst -,_,$(call toupper,$(RUSTC_TARGET_ARCH)))_LINKER=$(TARGET_CC_NOCACHE) \
        RUSTFLAGS="$(CARGO_RUSTFLAGS)" \
        TARGET_CC=$(TARGET_CC_NOCACHE) \