makepkg OPTIONS do not take effect for Rust (and possibly other non-C/C++ languages?)
I discovered today that OPTIONS=(lto)
in makepkg.conf seems to have no effect on Rust PKGBUILDS. There is no mention that anything special needs to be done in the PKGBUILD either at https://wiki.archlinux.org/title/Rust_package_guidelines The same issue seems to exist for OPTIONS=(debug)
as well based on looking at the source code of makepkg.
This is a bit unexpected. As a user I would expect the OPTIONS to affect all major languages where it reasonably could (e.g. big languages like C, C++, Go, Rust, maybe Haskell and Zig as well) unless otherwise documented.
Now I don't know those other languages (such as Zig and Go), but for Rust specifically you should probably not set RUSTFLAGS
, as this can have strange interactions by overriding (instead of appending) settings in project specific config files. Instead, you should set:
-
CARGO_PROFILE_RELEASE_DEBUG
to one of the values documented here https://doc.rust-lang.org/cargo/reference/profiles.html#debug (as release builds in rust by default contain no debug info at all). -
CARGO_PROFILE_RELEASE_LTO
to one of the four levels of LTO that Rust supports (see https://doc.rust-lang.org/cargo/reference/profiles.html#lto). Release builds in rust actually defaults to thin local LTO already. - Rust also has different optimisation levels than GCC: https://doc.rust-lang.org/cargo/reference/profiles.html#opt-level which could be set via
CARGO_PROFILE_RELEASE_OPT_LEVEL
(All of this assumes we are building with --release as suggested by the Arch rust packaging guidelines linked earlier.)
In summary, it would seem sensible to do expected things for the bigger languages, and some proper thought needs to go into it from people who know the respective languages.