Page MenuHomeFreeBSD

Mk/Features/ Use Cargo and Meson toggles

Authored by diizzy on Sep 25 2022, 9:56 AM.
Referenced Files
F81868210: D36696.diff
Mon, Apr 22, 9:24 AM
Unknown Object (File)
Sun, Apr 21, 8:53 AM
Unknown Object (File)
Sun, Apr 21, 8:53 AM
Unknown Object (File)
Sun, Apr 21, 8:50 AM
Unknown Object (File)
Sun, Apr 21, 8:36 AM
Unknown Object (File)
Feb 4 2024, 3:19 AM
Unknown Object (File)
Dec 28 2023, 4:21 AM
Unknown Object (File)
Dec 28 2023, 4:18 AM



Use corresponding toggles for each build framework to enable LTO

Diff Detail

R11 FreeBSD ports repository
Lint Not Applicable
Tests Not Applicable

Event Timeline

diizzy created this revision.

There's also a similar feature for CMake but as far as I can tell it requires patching of files.

diizzy retitled this revision from Mk/Features/ Use Cargo and Meson helpers to Mk/Features/ Use Cargo and Meson toggles.Sep 25 2022, 9:59 AM

It's a great idea, I was looking for a way to detect using Meson or CMake, but didn't think about checking the define.
Could you also do the same for CMake? Just need to add -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=TRUE to CMAKE_ARGS.

This revision is now accepted and ready to land.Sep 26 2022, 1:04 PM

The CMake change can go in the separate commit.

The reason I looped in Tobias ;-)

From what I can tell cmake_minimum_required kinda limits how (if) it works and it's not possible to override it without modifying CMakeLists.txt.
We basically need a clever way (which might be deemed as hack-ish to begin with) to determine what its current value is and bump it to (at least) 3.9 if it's below but I don't know how much we'll break by doing so.

I tested my theory on audio/exhale (mainly because it's tiny so its easy to tell what's going on) and it works as expected.

I'll commit it soon

Best regards,

CMake 3.9 is from 2017:
I think we can safely assume everyone has at least 3.9.

To enforce LTO with CMake, you probably also need CMAKE_POLICY_DEFAULT_CMP0069:STRING=NEW. Look at

The issue are lines that define cmake_minimum_required, see for example.

Anything lower than 3.9 and it wont apply which we need to solve before adding any CMake support. I would imagine that bumping it if needed may break some ports but I would rather see that fallout than it being "randomly" applied.

tobik added inline comments.

Why fat LTO ("true") and not "thin"?

Should lto=off be enforced when LTO_UNSAFE is defined?


Thin unforuntately performs worse at producing small binaries and at least for in my tests it doesn't (yet) seem to be worth switching to.


fat (true) vs thin
        45.29s real             2m15.60s user           3.79s sys
-rwxr-xr-x  1 root  wheel  1774704 Sep 27 13:57 work/stage/usr/local/bin/ztop
        39.41s real             2m40.61s user           3.41s sys
-rwxr-xr-x  1 root  wheel  1884976 Sep 27 13:59 work/stage/usr/local/bin/ztop

        2m31.12s real           7m56.87s user           16.93s sys
-rwxr-xr-x  1 root  wheel  4148512 Sep 27 14:08 work/stage/usr/local/bin/librespot
        2m15.24s real           9m15.35s user           14.81s sys
-rwxr-xr-x  1 root  wheel  5279912 Sep 27 14:04 work/stage/usr/local/bin/librespot

I left lto=off out as some ports already define release flags and I'm unsure of the benefit since it's not something rust/cargo enforces on its own
sysutils/bupstash -->