Skip to content

abuild.conf: set release profile optimisations for cargo

Jakub Panek requested to merge (removed):cargo into master

This is a proposal to set default optimisations for cargo release profile for decreased binary size, similar to CFLAGS.
The main reason is that we already patch in those optimisations for (some) rust packages but as a patch file or within APKBUILD if viable,
it should as well provide sane defaults which maintainers should not think about (we currently have a mix of opt-level = 's'/opt-level = 'z' while for everything non-rust we have -Os as default)

Environmental variables for cargo take precendence over TOML config files (source) so those should be respected no matter what upstream defines in their Cargo.toml
In case of issues with those defaults, it will be possible to unset envvar inside APKBUILD, but I don't expect it to be a common case.

Similar to -Os, s optimises for size, z additionally turns off loop vectorization (https://doc.rust-lang.org/cargo/reference/profiles.html#opt-level)

export CARGO_PROFILE_RELEASE_OPT_LEVEL="s"

Abort instead of unwinding the stack, standard for decreasing binary size (https://doc.rust-lang.org/cargo/reference/profiles.html#panic)

export CARGO_PROFILE_RELEASE_PANIC="abort"

Decrease parallel compiling resulting in better optimised package (https://doc.rust-lang.org/cargo/reference/profiles.html#codegen-units)

export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1

I'm aware that we do not have LTO by default, but we usually patch it in for rust packages (https://doc.rust-lang.org/cargo/reference/profiles.html#lto)

export CARGO_PROFILE_RELEASE_LTO="true"

Relevant issues:
RFC: implement optimization profiles
RFC: Enable link time optimization
enable link time optimization

Signed-off-by: Jakub Panek me@panekj.dev

Edited by Jakub Panek

Merge request reports