Skip to content

MSVC features - #952

Closed
llunak wants to merge 13 commits into
ccache:masterfrom
llunak:msvc
Closed

llunak wants to merge 13 commits into
ccache:masterfrom
llunak:msvc

Conversation

@llunak

@llunak llunak commented Oct 31, 2021 •

Copy link
Copy Markdown
Contributor

These changes makes various MSVC-related features work. This PR is based on #954.

I picked only the compiler commits from:
ccache#162

The following commits I've adapted to the latest ccache C++ code:

375fe24: Add compiler_is_msvc() and MSVC specific option table.
7e01763: Add handling of /Fo option (replaces -o, but shall have no space)
0c5cd25: Manage /E, /c equivalence. -g is gcc only. -O or /O is msvc only.
4f61b59: MSVC send part of the error/warning messages to STDOUT, so concat wit…
MSVC outputs some messages to stdout instead of stderr, so cache
stdout in addition to stderr, and remove the merge-to-stderr hack.
Since MSVC understands both /option and -option, change all of them
to -option, which means now old code handling e.g. -U gets reused,
and this also simplifies handling of both variants (/Fo was handled,
but -Fo wasn't).

The list had two options -P and -u that mean something else for MSVC
than it does for GCC, so handle those explicitly.
These are used by compiler but they also #define some things,
so they need to be passed to both steps.
@llunak llunak changed the title MSVC PCH support MSVC features Nov 2, 2021
@cristianadam cristianadam mentioned this pull request Nov 2, 2021
4 of 6 tasks
@llunak
llunak force-pushed the msvc branch 2 times, most recently from 439e97f to 45ab2a1 Compare November 2, 2021 12:57
This more or less maps to PCH support for GCC/Clang, just handle
the /Yu and /Fp options.

Note that MSVC is apparently unable to generate the same PCH
from the same sources, just like GCC, so a rebuild that also rebuilds
the PCH will get cache misses. So either somebody can add support
for -Yc (if caching those huge PCHs is a good idea), or
CCACHE_PCH_EXTSUM can be used (with a checksum based on preprocessed
PCH input, i.e. -E instead of -c -Yc).
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.
Without this, clang-cl is detected as clang and then ccache barfs
because clang-cl produces stdout output.
Since clang-cl is technically sort of cl and and sort of clang,
add is_compiler_group_cl() and is_compiler_group_clang() to check
similar compilers easily instead of enumerating them repeatedly.
Everything after it should be passed to the linker, which conflicts
with ccache appending its extra arguments when calling the compiler.
This probably could be handled somehow, but ccache shouldn't cache
compilations that also link, so either the option doesn't belong
there anyway, or the compilation cannot be cached.
While MSVC technically has that option as deprecated, it's a source
of trouble with the way ccache curently handles the option, and since
it broke ccache's debug output, it was hard to find.
@jrosdahl jrosdahl added this to the 4.6 milestone Nov 6, 2021
@orgads

orgads commented Jan 5, 2022

Copy link
Copy Markdown
Contributor

Should this be closed? Rebased?

@cristianadam

Copy link
Copy Markdown
Contributor

Should this be closed? Rebased?

Should be rebased. The features are very welcome!

@orgads orgads mentioned this pull request Jan 7, 2022
@orgads

orgads commented Jan 7, 2022

Copy link
Copy Markdown
Contributor

Rebased and pushed as #987.

@jrosdahl

Copy link
Copy Markdown
Member

Please split this PR into one PR per feature where feasible. That way it's easier to review, discuss and apply them individually.

Super quick review:

  1. support MSVC /Yu option (compiling with PCH): Looks OK in principle.
  2. make depend mode work for MSVC:
    • Missing documentation.
    • Unit tests would be appreciated.
    • Since the feature doesn't use dependency files, I don't think that it makes sense to piggy back on the name "depend mode". We could consider renaming it to something more generic that doesn't lock us into implementation details, though (not sure what).
    • Also, do I understand correctly that the user is expected to add /showIncludes themselves? If so, is that really reasonable since stderr will be littered with header file lists intermixed with errors and warnings?
  3. detect clang-cl as a compiler: Looks OK in principle.
  4. do not handle -o for MSVC: OK.
  5. MSVC's -Zs is GCC's -fsyntax-only: OK.

@cristianadam

Copy link
Copy Markdown
Contributor

Regarding the depend mode, here is what the ninja manual has to say to their corresponding feature:

It turns out that for large projects (and particularly on Windows, where the file system is slow) loading
these dependency files on startup is slow.

Ninja 1.3 can instead process dependencies just after they’re generated and save a compacted form
of the same information in a Ninja-internal database.

Ninja supports this processing in two forms.

  1. deps = gcc specifies that the tool outputs gcc-style dependencies in the form of Makefiles. Adding this to
    the above example will cause Ninja to process the depfile immediately after the compilation finishes,
    then delete the .d file (which is only used as a temporary).
  2. deps = msvc specifies that the tool outputs header dependencies in the form produced by Visual Studio’s
    compiler’s /showIncludes flag. Briefly, this means the tool outputs specially-formatted lines to its stdout.
    Ninja then filters these lines from the displayed output. No depfile attribute is necessary, but the localized
    string in front of the the header file path. For instance msvc_deps_prefix = Note: including file: for a English
    Visual Studio (the default). Should be globally defined.

The user doesn't have to add /showIncludes by themselves, their build tool (ninja) requires it, and the build tool generator takes care of that (cmake).

ccache will tap in and get the dependency information, since it's already there, but not in the form of a .d file.

@orgads

orgads commented Feb 7, 2022

Copy link
Copy Markdown
Contributor

The last commit is in #992. @llunak please close this PR and move the discussion there.

@jrosdahl

Copy link
Copy Markdown
Member

@cristianadam wrote:

Regarding the depend mode, here is what the ninja manual has to say to their corresponding feature:

Thanks for the clarification.

@orgads wrote:

The last commit is in #992. @llunak please close this PR and move the discussion there.

I'll close it!

@jrosdahl jrosdahl closed this Feb 15, 2022
@jrosdahl jrosdahl added status: duplicate Duplicate of another issue issue: feature New feature compiler: msvc Related to Microsoft Visual C++ labels Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler: msvc Related to Microsoft Visual C++ issue: feature New feature status: duplicate Duplicate of another issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants