Repository navigation
Generate a file containing command-line options for translation - #8181
Conversation
This will make reproducing the compilation artifact easier, e.g., when debugging.
Abbreviated Benchmark Summary@ commit b1f9f7bc527a3e9ca78228fbe8ad8c5c5cde4323 (vs. base 769036f0e2c501500d3901d2c5059598912a8b4d) Regressed Benchmarks 🚩
Improved Benchmarks 🎉
For more information: |
| set(_COMPOPT_FILE "${_RUN_SPEC_DIR}/compilation_flagfile") | ||
| add_custom_command( | ||
| OUTPUT "${_COMPOPT_FILE}" | ||
| COMMAND |
There was a problem hiding this comment.
I didn't find an easier way to dump multiple lines into a file, so using an extra Python script. Any other ideas?
There was a problem hiding this comment.
There was a problem hiding this comment.
Thanks! Yes I've run into these two before. Here we don't have key/value pairs like normal compiler defines and there are unknown number of different kinds of option strings to be emitted. So using configure_file would mean shorehorning for this specific case. For file, I didn't find a good way to wire it up with custom commands and targets. So not sure they are better than the current way..
There was a problem hiding this comment.
Hmm I think configure_file you can just sub in a list. The documentation mostly talks about cmakedefine, but it will replace @VAR@ or ${VAR} also. It seems like you should also be able to do something with cmake command mode:
add_custom_command(OUTPUT | TARGET ...
COMMAND ${CMAKE_COMMAND} -E echo "<content-of-the-file>" > "</path/to/file>"
)
but maybe the shell redirect would make it dependent on bash and mess things up on windows? Ugh it really seems like a python script shouldn't be necessary here, but maybe it's the least bad option
There was a problem hiding this comment.
I haven't looked at the details here, but I don't think we should need a 1 line python file (with 40 lines of supporting flag parsing) to generate a file :P
That would also place yet another fringe dep on python in the build system...
There was a problem hiding this comment.
Yeah that's my feeling as well :-D Also, is it important that this happen at build time instead of configure time? It seems like using file(WRITE and have it happen at configure time should be fine since it's all based on configure-time information
There was a problem hiding this comment.
The difficulty with cmake -E echo is that it cannot handle newlines. Giving it a string containing \n will cause it generate broken build.ninja file. :)
On a second thought, I actually don't strictly need to use newline as separators. The compilation tools we have does not support --flagfile like the runtime tools we have anyway. So concatenating with " " is fine for now at least. Helps to kick the can down the road a bit. Changed.
There was a problem hiding this comment.
LLVM CL parsing supports flagfiles (by a different name), actually: https://llvm.org/docs/CommandLine.html#response-files. Also, you can make configure_file sub in a variable with newlines. It's what LLVM does for some enumeration of macros. See https://github.com/llvm/llvm-project/blob/dbf278b984eebf17a8977e79b67cdb960e9af5db/llvm/CMakeLists.txt#L788 and https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Config/AsmPrinters.def.in, for instance. I think that would be better. Then we can actually use the flagfile in the build, also, instead of only putting it somewhere for human reference.
There was a problem hiding this comment.
Interesting. Didn't know that you can do @file to inject command-line options for LLVM binaries.. Okay that makes sense then. I switched to use configure_file. Thanks for the suggestion!
There was a problem hiding this comment.
Wait, part of my suggestion was to use the flagfile in the actual cmake COMMAND as well. It seems a bit weird to generate it and then not use it in the actual build system
|
This is ready for reviews now @GMNGeoffrey @ScottTodd, PTAL. :) |
| set(_COMPOPT_FILE "${_RUN_SPEC_DIR}/compilation_flagfile") | ||
| add_custom_command( | ||
| OUTPUT "${_COMPOPT_FILE}" | ||
| COMMAND |
There was a problem hiding this comment.
LLVM CL parsing supports flagfiles (by a different name), actually: https://llvm.org/docs/CommandLine.html#response-files. Also, you can make configure_file sub in a variable with newlines. It's what LLVM does for some enumeration of macros. See https://github.com/llvm/llvm-project/blob/dbf278b984eebf17a8977e79b67cdb960e9af5db/llvm/CMakeLists.txt#L788 and https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Config/AsmPrinters.def.in, for instance. I think that would be better. Then we can actually use the flagfile in the build, also, instead of only putting it somewhere for human reference.
|
I didn't hit send on my review yesterday, whoops :-/ I think this can be done with configure_file and flagfiles (called response files in LLVM for whatever reason) such that we actually use it in the build and it's a single command for someone to use it |
This will make reproducing the compilation easier, e.g., when debugging.