-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
cmake: use object library to avoid duplicate compilation. #4489
Conversation
I have no clue for why https://github.com/microsoft/LightGBM/pull/4489/checks?check_run_id=3167177587 and https://github.com/microsoft/LightGBM/pull/4489/checks?check_run_id=3167177567 failed. The same test using gcc have no problems. |
Together with the failure of this test https://dev.azure.com/lightgbm-ci/lightgbm-ci/_build/results?buildId=10602&view=logs&j=5ea309bb-dea2-5bcb-538b-5c76ecf159eb, seems like there are some compiler flags ( |
Linking #4125. |
@StrikerRUS Just to mention that this PR requires all target uses the same compilation options. |
@cyfdecyf Sorry, could you please elaborate? |
Sorry my previous statement is too vague. Object libraries are targets in CMake and we can define compile options for them. When linking to object library in targets, we need to make sure the compile options of related targets are "compatible". For example, if one object library compiles without From my experiment, compile options does not propagate to depending targets which is reasonable behavior. |
I tried to reproduce the compiling problem on my own macOS system. As I don't want to mess my system, I created a separate conda environement and installed the required R packages as in I'm not able to reproduce the same problem with the following bulid commands:
The compiler I'm using is Xcode command line tools with AppleClang 12.0.5.12050022. This is a little different than the CI environment. So I'm changing build code to get more build output to investigate the issue. Sorry for the noise. |
b41fad4
to
33385b1
Compare
For CI of R-package on macOS using clang,
There are two more options before this PR:
Commit 33385b1 add those two options and fixes CI. But I can't figure out how those two options come into the compilation command. I figure out why I can't reproduce the problem in conda environment. The environment is created with following command:
The conda environment contains |
1e6fa43
to
e1bd371
Compare
Thanks for the investigation in #4489 (comment), @cyfdecyf . Do you need help looking into the errors on Azure DevOps? https://dev.azure.com/lightgbm-ci/lightgbm-ci/_build/results?buildId=10662&view=logs&j=ea56812e-e7ae-55d0-6abc-4a217857fa9f
Makes sense, I guess it's a similar problem to #4131, but for CMake-based builds. |
bbe105f
to
4dab796
Compare
CI failure for "Linux mpi_source" is caused by Commit ccafdab adds |
@jameslamb Thanks, I indeed need help for Windows bdist on Azure Devops https://dev.azure.com/lightgbm-ci/lightgbm-ci/_build/results?buildId=10668&view=logs&j=ea56812e-e7ae-55d0-6abc-4a217857fa9f&t=e61701f8-4e1b-5007-20cb-a000ab3587fb |
I've tried the key building steps of windows bdist build on my local system with Visual Studio 2019.
|
Printing out cmake output shows that windows bdist failed because boost is not added in include library. I'll try to figure out why. |
I didn't notice there are I'll check |
I'm defining all link dependencies, compile definitions to the object library object. This can remove duplicated definitions on two targets. It's not easy to do this right in one shot, sorry for the CI noise. |
@StrikerRUS My PR has conflict with master branch and can't run all CI tests. Resolving the conflit on github would introduce merge commit. To keep a linear history, I made a rebase to current master and force push. Sorry for the noise. |
No problem! We always "Squash and merge" PRs, so please don't worry about dirty commit history next time. |
@StrikerRUS I made some corrections to the used of |
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.
LGTM! Thank you so much for this contribution and for your really hard work with the debugging!
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.
Works for me! Based on passing CI jobs and the review discussion, I'm comfortable with this PR.
Thanks for your hard work, and to @StrikerRUS for a very thorough review that required reading a lot of CMake documentation.
@cyfdecyf @jameslamb @StrikerRUS Thank you all! Is this ready for merge? |
@shiyu1994 It's ready for merge. Please notify me in case there are any problems. |
This PR hasn't been merged yet for the same reason as in #4580 (comment). Do you think we should start merging PRs with large new features? |
It has been 13 days since LightGBM 3.3.1 was released (#4715 (comment)), and one month since LightGBM 3.3.0 was released (#4633 (comment)). In the comments linked from #4580 (comment), we discussed waiting two weeks. I think it has been close enough to two weeks that it is ok to start merging larger PRs and working towards LightGBM 4.0. |
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
By using CMake's object libraries feature, we can avoid recompiling same source file multiple times.
This feature is introduced since CMake 2.8.8 and minmum required CMake version is 3.0 for LightGBM.
Seems like there's no separate compilation flags for building executable and library, thus I think it's safe to use object library to builld LightGBM.
References:
BTW, I guess following build code need some cleanup:
LightGBM/CMakeLists.txt
Lines 304 to 321 in 2370961
variables
is not used in other places.