Re: Default optimization of rust ports

From: Nuno Teixeira <>
Date: Tue, 13 Sep 2022 09:54:47 UTC

I think this issue is related to what happened in terms of optimizations in
go 1.18.3_1:
Add amd64 microarchitecture level knobs for the Go compiler. Note that
this will affect only the compiler itself, port users will still need to
set GOAMD64 in the environment to adjust the microarchitecture of the
compiled code
I've found this optimizations interesting, e.g.:
The current high level steps to reduce binary size are:

   1. Use Rust 1.32.0 or newer (which doesn't include jemalloc by default)
   2. Add the following to Cargo.toml

opt-level = 'z'     # Optimize for size.
lto = true          # Enable Link Time Optimization
codegen-units = 1   # Reduce number of codegen units to increase
panic = 'abort'     # Abort on panic
strip = true        # Strip symbols from binary*

*strip = true requires Rust 1.59+. On older Rust versions, run strip
manually on the resulting binary.

I was searching for cargo stripping instead of using STRIP_CMD and I found
this but this means that we have to hack ports Cargo.toml's or should be
upstream to implement a [profile.release]?


Mark Millard <> escreveu no dia sábado, 10/09/2022 à(s)

> Daniel Engberg <> wrote on
> Date: Sat, 10 Sep 2022 09:45:21 UTC :
> > Since there is work and general interest regarding optimization would it
> > make sense to make LTO and possibly CODEGEN_UNITS=1 opt-out while we
> > still have a fairly manageable amount of ports using Rust?
> Just making sure I understand the wording:
> So, in part, you are requesting that the FreeBSD build servers build
> using LTO and CODEGEN_UNITS=1? (Those build servers always use the
> defaults as I understand. Thus, the defaults are set to what is
> desired for use on the build servers, if I understand right. Other
> contexts that happen to want something different override some
> default(s): opt out of the defaults.)
> ===
> Mark Millard
> marklmi at

Nuno Teixeira
FreeBSD Committer (ports)