-
Notifications
You must be signed in to change notification settings - Fork 684
[project/cmake] add auto linker selection based on availability #4013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9c0a18a
to
eac1517
Compare
A crude test to demonstrate the link speed difference. Test steps:
-- Results -- Baseline: Default linker (GNU ld) > cmake -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_LINKER_TYPE=DEFAULT -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -S . -B build
> cmake --build build/ --parallel 32
> rm build/bin/multipass_tests
> time cmake --build build/ --parallel 32 --target multipass_tests
[0/2] Re-checking globbed directories...
[1/1] Linking CXX executable bin/multipass_tests
[0/2] Re-checking globbed directories...
[1/1] Linking CXX executable bin/multipass_tests
real 0m12,426s
user 0m8,445s
sys 0m3,980s Contender 1: mold > cmake -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_LINKER_TYPE=MOLD -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -S . -B build
> cmake --build build/ --parallel 32
> rm build/bin/multipass_tests
> time cmake --build build/ --parallel 32 --target multipass_tests
[0/2] Re-checking globbed directories...
[1/1] Linking CXX executable bin/multipass_tests
real 0m1,105s
user 0m0,100s
sys 0m0,028s Contender 2: lld > cmake -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_LINKER_TYPE=LLD -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -S . -B build
> cmake --build build/ --parallel 32
> rm build/bin/multipass_tests
> time cmake --build build/ --parallel 32 --target multipass_tests
[0/2] Re-checking globbed directories...
[1/1] Linking CXX executable bin/multipass_tests
real 0m1,351s
user 0m4,301s
sys 0m2,776s Conclusion: |
Not a review, but this is a great idea! It should speed up iterating a lot without affecting our confidence on what we ship. 👍 |
cd58db3
to
ea312ca
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4013 +/- ##
=======================================
Coverage 89.34% 89.34%
=======================================
Files 260 260
Lines 14738 14738
=======================================
Hits 13167 13167
Misses 1571 1571 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Hmm, I see that Linux CI runs log |
Yes, that's the case. I opted to set the CMAKE_LINKER_TYPE in |
It's not a big deal, but I think it is a bit confusing that the CI logs report that the build was not running in CI. So if it isn't too difficult to fix, I'd like that. IMO, if forwarding the env var to snapcraft would not introduce any other issue, I think that approach would be more consistent. |
ea312ca
to
6a334df
Compare
Yeah, at least we can ditch the CI patchfile changes. Updated the branch, let's see if it works. |
0b72efa
to
2737db8
Compare
`mold` and `lld` are usually several magnitudes faster compared to the default linker of the toolchains. This PR adds the configure_linker CMake function to automatically configure which linker to use based on availability of the "mold" and "lld" in the environment. The function is no-op below CMake 3.29 since the current implementation depends on a rather recent CMake variable, CMAKE_LINKER_TYPE. The user can disable the auto linker selection by explicitly specifying the CMAKE_LINKER_TYPE at configure step, i.e.,: cmake -DCMAKE_LINKER_TYPE=DEFAULT -S . -B build The `configure_linker` is intended to be only run in non-CI environments. The `is_running_in_ci` determines whether the project is being built in a CI environment. Signed-off-by: Mustafa Kemal Gilor <[email protected]>
847de09
to
2e345f7
Compare
Done, the CI is now injecting the GITHUB_ACTIONS environment variable to |
By default, the host's environment variables are not being forwarded to the snap build environment. Since the detection of CI environment relies on presence of GITHUB_ACTIONS environment variable, forward it. Signed-off-by: Mustafa Kemal Gilor <[email protected]>
2e345f7
to
b2df790
Compare
Not an actual review, but I just want to add a couple of remarks
|
Done! |
some of the variables are not expanded by mistake, which results in tests always being true regardless of the variable contents. Signed-off-by: Mustafa Kemal Gilor <[email protected]>
Signed-off-by: Mustafa Kemal Gilor <[email protected]>
244efb6
to
afab3c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
@levkropp It's ready for a secondary review, lemme know if it looks good to you :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this @xmkg ! I have tested building and I am seeing the speedup :)
[0/2] Re-checking globbed directories...
[1/2] Linking CXX executable bin/multipass_tests
real 0m1.019s
user 0m0.048s
sys 0m0.028s
mold
andlld
are usually several magnitudes faster compared to the default linker of the toolchains. This PR adds the configure_linker CMake function to automatically configure which linker to use based on availability of the "mold" and "lld" in the environment. The function is no-op below CMake 3.29 since the current implementation depends on a rather recent CMake variable, CMAKE_LINKER_TYPE.The user can disable the auto linker selection by explicitly specifying the CMAKE_LINKER_TYPE at configure step, i.e.,:
cmake -DCMAKE_LINKER_TYPE=DEFAULT -S . -B build
The
configure_linker
is intended to be only run in non-CI environments. Theis_running_in_ci
determines whether the project is being built in a CI environment.MULTI-1912