-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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] Serialize native builds for Make generator #121021
Conversation
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.
Isn't this fragile? The build system allows multiple invocation of subprocess builds in the native folder.
Isn't there a way to present this?
@joker-eph this is indeed fragile. Following previous discussion in https://reviews.llvm.org/D149072, it shouldn't be a problem for Ninja generator because of the use of console tool and for Visual Studio because of the introduction of dependency chain. It mentioned job server for GNU make, but I don't see it's being used anywhere. I think it's possible to leverage job server to serialize the sub-make invocation. More specifically, below setup is needed if I understand it correctly: Alternatively, shall we simply apply the dependency chain to GNU make generator as well? It's mentioned in https://reviews.llvm.org/D149072 that it would regress Makefile build time. However, I don't feel it would regress much compared with the job server solution. -- |
I think you should pull in the folks from the review you mentioned. |
Inspired by https://discourse.cmake.org/t/good-way-of-running-custom-commands-serially/8412, I implemented serial execution of sub-make invocations via cmake |
@llvm-beanz @aganea @smeenai @mstorsjo @chapuni Please kindly review. |
b0dc686
to
e6c555e
Compare
e6c555e
to
d3c3711
Compare
Ping |
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.
I think this mostly looks fine. One small suggestion.
e419a54
to
add0b79
Compare
@joker-eph @llvm-beanz The PR is ready for merge. I don't have commit access to llvm-project repo. Could you please help merge if it looks all good. |
Ping. Sorry for bothering. |
set(make_cmd "$(MAKE)" "-C" "${bin_dir}" "${target}") | ||
set(file_lock_script "${LLVM_CMAKE_DIR}/FileLock.cmake") | ||
set(${out_var} ${CMAKE_COMMAND} "-DLOCK_FILE_PATH=${stamp_dir}/cmake.lock" | ||
"-DCOMMAND='${make_cmd}'" |
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.
We might be better off using something like |
instead of a semicolon-separated list when constructing make_cmd
above; and then replacing |
with ;
inside FileLock.cmake. Using \;
or $<SEMICOLON>
(since all places this will be used support generator expressions) would also work. You can then remove the separate_arguments
inside FileLock.cmake and have things still work correctly for paths with spaces.
The single quotes here will also likely cause issues on Windows; you can use \"
instead so that the command ends up with double quotes instead.
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.
@smeenai Thanks for reviewing. I've made changes according to your suggestions. Please take a look.
I found that semicolon-separated list just happened to work because VERBATIM
was not used in add_custom_command
, even that the build cmd was indeed problematic.
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.
I did a quick test and it looks like ExternalProject_Add_Step
would wrap command with sh -c
, i.e. it has the same behavior as add_custom_command
without VERBATIM
, and unfortunately ExternalProject_Add_Step
does not have a VERBATIM
argument. So it would break code here if either |
or \;
is used as separator because they have special meaning in shell.
For now, I use @
as separator. We can choose something different if @
is too common. I'm not familiar with how to test CMake flow here. So I just ran some CMake unit test to verify cmd parsing works as expected with/without VERBATIM mode on both linux/windows.
add0b79
to
34023d6
Compare
34023d6
to
56be0d9
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.
Good point. @
seems good to me.
The build system is fragile by allowing multiple invocation of subprocess builds in the native folder for Make generator. For example, during sub-invocation of the native llvm-config, llvm-min-tblgen is also built. If there is another sub-invocation of the native llvm-min-tblgen build running in parallel, they may overwrite each other's build results, and may lead to errors like "Text file busy". This patch adds a cmake script that uses file lock to serialize all native builds for Make generator.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/64/builds/1992 Here is the relevant piece of the build log for the reference
|
The build system is fragile by allowing multiple invocation of subprocess builds in the native folder for Make generator. For example, during sub-invocation of the native llvm-config, llvm-min-tblgen is also built. If there is another sub-invocation of the native llvm-min-tblgen build running in parallel, they may overwrite each other's build results, and may lead to errors like "Text file busy". This patch adds a cmake script that uses file lock to serialize all native builds for Make generator.
The build system is fragile by allowing multiple invocation of subprocess builds in the native folder for Make generator.
For example, during sub-invocation of the native llvm-config, llvm-min-tblgen is also built. If there is another sub-invocation of the native llvm-min-tblgen build running in parallel, they may overwrite each other's build results, and may lead to errors like "Text file busy".
This patch adds a cmake script that uses file lock to serialize all native builds for Make generator.