Repository navigation
feat: Support depend mode for MSVC - #992
Conversation
|
Quoting from #952
|
3fa7d88 to
2f0fcf1
Compare
I think these two apply to most of the MSVC commits, or they at least need checked. As for tests, do MSVC-based tests already work?
It really is the same as the GCC-based depend mode, it just uses a different option and output format, but otherwise it's the same, including the usage. The build system will usually add the option automatically, just like it does for GCC, and it should also filter it out from MSVC's output (and commented in #952 that's the case for ninja and e.g. LibreOffice's build system works similarly). I think even the name depend mode still fits, it's a mode that uses dependencies generated by the compiler, in whatever format the compiler provides them. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
@llunak wrote:
I was referring to the unit tests, i.e. the tests in the unittest directory, not the integration tests in the test directory. The
OK, thanks. Since e.g. Ninja already makes use of it out of the box I agree that it makes sense to support it.
OK, I can live with that name if it's documented in a good way. |
|
Docs seem to say that cl.exe writes to stderr, not stdout.
|
It's a lie! 😈 I just tested, and it outputs to stdout. |
It hardly matters, since if they change it, you'd still have to assume that the output could go to either. (without assuming that every user is using the latest release of the latest version). |
|
They won't change it, since that will break existing tools. I reported so they fix the docs. |
Will you plan to make another version of the patch to check both stdout and stderr ? |
The docs were updated. stderr is no longer mentioned. |
|
@orgads Hi, could you please rebase on master? I'm getting some compile errors due to recent changes like the bump to c++17. |
|
@orgads Builds rebased on master for me with this patch: diff --git a/src/ShowIncludesParser.cpp b/src/ShowIncludesParser.cpp
index 9e7365f3..e99ce817 100644
--- a/src/ShowIncludesParser.cpp
+++ b/src/ShowIncludesParser.cpp
@@ -23,8 +23,8 @@
namespace ShowIncludesParser {
-std::vector<nonstd::string_view>
-tokenize(nonstd::string_view file_content, nonstd::string_view prefix)
+std::vector<std::string_view>
+tokenize(std::string_view file_content, std::string_view prefix)
{
// -showIncludes output is written to stdout together with other messages.
// Every line of it is '<prefix> <spaces> <file>', prefix is 'Note: including
@@ -34,17 +34,17 @@ tokenize(nonstd::string_view file_content, nonstd::string_view prefix)
prefix = "Note: including file:";
}
- std::vector<nonstd::string_view> result;
+ std::vector<std::string_view> result;
// This will split at each \r or \n, but that simply means there will be empty
// "lines".
- for (nonstd::string_view line :
+ for (std::string_view line :
Util::split_into_views(file_content, "\r\n")) {
if (util::starts_with(line, prefix)) {
size_t pos = prefix.size();
while (pos < line.size() && isspace(line[pos])) {
++pos;
}
- nonstd::string_view include = line.substr(pos);
+ std::string_view include = line.substr(pos);
if (!include.empty()) {
result.push_back(include);
}
diff --git a/src/ShowIncludesParser.hpp b/src/ShowIncludesParser.hpp
index 6a774641..89559c98 100644
--- a/src/ShowIncludesParser.hpp
+++ b/src/ShowIncludesParser.hpp
@@ -18,13 +18,12 @@
#pragma once
-#include "third_party/nonstd/string_view.hpp"
-
+#include <string_view>
#include <vector>
namespace ShowIncludesParser {
-std::vector<nonstd::string_view> tokenize(nonstd::string_view file_content,
- nonstd::string_view prefix);
+std::vector<std::string_view> tokenize(std::string_view file_content,
+ std::string_view prefix);
} // namespace ShowIncludesParser
diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp
index 18d1f7c8..44da048c 100644
--- a/src/argprocessing.cpp
+++ b/src/argprocessing.cpp
@@ -648,7 +648,7 @@ process_option_arg(const Context& ctx,
if (args[i] == "-showIncludes") {
args_info.generating_includes = true;
state.dep_args.push_back(args[i]);
- return nullopt;
+ return std::nullopt;
}
if (args[i] == "-fprofile-arcs") {
diff --git a/src/ccache.cpp b/src/ccache.cpp
index 5db23aac..e7db244b 100644
--- a/src/ccache.cpp
+++ b/src/ccache.cpp
@@ -678,7 +678,7 @@ result_key_from_depfile(Context& ctx, Hash& hash)
// Extract the used includes from -showIncludes output in stdout. Note that we
// cannot distinguish system headers from other includes here.
-static optional<Digest>
+static std::optional<Digest>
result_key_from_includes(Context& ctx,
Hash& hash,
const std::string& stdout_path)
@@ -688,10 +688,10 @@ result_key_from_includes(Context& ctx,
file_content = Util::read_file(stdout_path);
} catch (const core::Error& e) {
LOG("Cannot open stdout tmp file {}: {}", stdout_path, e.what());
- return nullopt;
+ return std::nullopt;
}
- for (string_view token : ShowIncludesParser::tokenize(
+ for (std::string_view token : ShowIncludesParser::tokenize(
file_content, ctx.config.msvc_dep_prefix())) {
if (!ctx.has_absolute_include_headers) {
ctx.has_absolute_include_headers = util::is_absolute_path(token); |
|
Thank you, sorry for the delay. Done. |
|
Awesome, thank you! Hope we can get this merged soon 👍 |
f0d0174 to
f097e69
Compare
|
Rebased and adapted to build. @jrosdahl Please review. |
|
Confirmed that this makes building postgres about 2x faster when the cache is empty. Actually .. this also makes fully-cached builds slower than without depend mode (which take ~90sec under cirrus), maybe due to the enormous amount of output. Would it make sense to suppress (or allow suppressing) the output from -ShowIncludes, during cache hits ? |
|
@orgads: The implementation looks reasonable to me after a cursory glance. That leaves "Missing documentation" and "Unit tests would be appreciated". Are those something that you would like to address? |
|
@llunak can you take care of these issues? |
|
@justinpryzby wrote:
That doesn't make sense to me. What on earth makes them so much slower?
I think that it could be a good idea for ccache to add |
Sounds good to me. |
I can reproduce that. When running without On my tests, compilation without ccache takes ~1.7s, while with ccache it can reach even 5s, average is around 3-4s. With depend mode and |
|
Auto mode pushed in #1158. |
|
Please review the documentation. I'll try to add unit tests tomorrow. |
Thanks. Regarding the manual I'm missing documentation of the Another thing that comes to mind when I read the diff is that it would be good to use Lines 936 to 941 in e9ddf68 |
Based on -showIncludes, which prints included files on stdout with a certain text prefix. Otherwise pretty similar to depend mode handling for GCC. This makes MSVC building way faster.
|
Done. I moved the doc and tests to a separate commit. |
|
|
||
| TEST_SUITE_BEGIN("ShowIncludesParser"); | ||
|
|
||
| TEST_CASE("ShowIncludesParser::tokenize") |
Check notice
Code scanning / CodeQL
Unused static function
|
On Mon, Sep 12, 2022 at 11:01:12PM -0700, Orgad Shaneh wrote:
> @justinpryzby wrote:
>
> > cache misses are so slow (3x-4x slower than without using ccache)
>
> That doesn't make sense to me. What on earth makes them so much slower?
I can reproduce that. When running without `-showIncludes`, or with depend_mode disabled, ccache runs the preprocessor, and it takes as long as (and sometimes more than) the compiler itself.
On my tests, compilation without ccache takes ~1.7s, while with ccache it can reach even 5s, average is around 3-4s.
With depend mode and `-showIncludes`, performance is quite close to without ccache. 1.7s -> 2s.
I wonder if it's because of the "file tracker" used by MSVC to support
incremental compilation. Even when it's ostensibly disabled, I still
see that "tlog" files are written. If the file tracker is active, it
seems like it'd be similar to running ccache (and the compiler) under
strace - obviously not good for performance.
|
|
Thanks. |
|
@orgads congrats on getting this merged! Some of us have been pulling this PR into our local copies. |
|
👍 |
Based on -showIncludes, which prints included files on stdout
with a certain text prefix. Otherwise pretty similar to depend mode
handling for GCC.
This makes MSVC building way faster.