Skip to content
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

Suppress "Unable to resolve configuration with compilerPath" warning in CMake+Swift projects #4097

Closed
tristanlabelle opened this issue Sep 13, 2024 · 22 comments · Fixed by #4111
Assignees
Labels
Milestone

Comments

@tristanlabelle
Copy link
Contributor

Environment

  • OS and Version: Windows 11 22H2
  • VS Code Version: 1.93.0
  • C/C++ Extension Version: v1.21.6
  • If using SSH remote, specify OS of remote machine: N/A

Bug Summary and Steps to Reproduce

Bug Summary:
While working on a CMake Swift project, the C++ extension will regularly print the message below to the C/C++ Configuration Warnings output window righ after a build, which is annoying because:

  1. It steals the focus from the CMake/Build output pane, hiding the output of the build
  2. I'm not trying to use C/C++ code at the time where this shows up (though the project includes some C sources)
  3. The C/C++ extension probably shouldn't be trying to resolve anything with the swiftc.exe compiler
[9/13/2024, 6:32:16 AM] Unable to resolve configuration with compilerPath "c:/users/tristan/appdata/local/programs/swift/toolchains/0.0.0+asserts/usr/bin/swiftc.exe".  Using "cl.exe" instead.
[9/13/2024, 6:36:45 AM] Unable to resolve configuration with compilerPath "c:/users/tristan/appdata/local/programs/swift/toolchains/0.0.0+asserts/usr/bin/swiftc.exe".  Using "cl.exe" instead.

Steps to reproduce:

  1. Install Swift for Windows from https://www.swift.org/install/windows/
  2. Clone https://github.com/tristanlabelle/swift-winrt
  3. Open the Generator subfolder in VS Code from a VS dev cmd
  4. Run cmake --preset debug and cmake --build --preset debug
    (the bug is not specific to this repo, I see it regularly when working in Swift)

Expected behavior:
The C/C++ extension should not produce this warning. Probably it should ignore anything to do with the Swift compiler.

Configuration and Logs

-------- Diagnostics - 9/13/2024, 6:53:56 AM
Version: 1.21.6
Current Configuration:
{
    "name": "Win32",
    "includePath": [
        "d:/swift-winrt/Generator/**"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
    ],
    "windowsSdkVersion": "10.0.22621.0",
    "compilerPath": "cl.exe",
    "cStandard": "c17",
    "cppStandard": "c++17",
    "intelliSenseMode": "windows-msvc-x64",
    "compilerPathInCppPropertiesJson": "cl.exe",
    "intelliSenseModeIsExplicit": false,
    "cStandardIsExplicit": false,
    "cppStandardIsExplicit": false,
    "mergeConfigurations": false,
    "compilerPathIsExplicit": false,
    "configurationProvider": "ms-vscode.cmake-tools",
    "browse": {
        "path": [
            "d:/swift-winrt/Generator/**",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Custom browse configuration: 
{
    "browsePath": [
        "d:/swift-winrt/generator/build/debug/dependencies/swift-argument-parser",
        "d:/swift-winrt/generator/build/debug/_deps/swift-argument-parser-src/sources/argumentparser/completions",
        "d:/swift-winrt/generator/build/debug/_deps/swift-argument-parser-src/sources/argumentparser/parsable properties",
        "d:/swift-winrt/generator/build/debug/_deps/swift-argument-parser-src/sources/argumentparser/parsable types",
        "d:/swift-winrt/generator/build/debug/_deps/swift-argument-parser-src/sources/argumentparser/parsing",
        "d:/swift-winrt/generator/build/debug/_deps/swift-argument-parser-src/sources/argumentparser/usage",
        "d:/swift-winrt/generator/build/debug/_deps/swift-argument-parser-src/sources/argumentparser/utilities",
        "d:/swift-winrt/generator/build/debug/_deps/swift-argument-parser-src/sources/argumentparsertoolinfo",
        "d:/swift-winrt/generator/sources/codewriters/c",
        "d:/swift-winrt/generator/sources/codewriters/cmake",
        "d:/swift-winrt/generator/sources/codewriters",
        "d:/swift-winrt/generator/sources/codewriters/swift",
        "d:/swift-winrt/generator/sources/codewriters/swift/syntaxwriters",
        "d:/swift-winrt/generator/build/debug/dependencies/swift-collections",
        "d:/swift-winrt/generator/build/debug/_deps/swift-collections-src/sources/collections",
        "d:/swift-winrt/generator/build/debug/_deps/swift-collections-src/sources/dequemodule",
        "d:/swift-winrt/generator/build/debug/dependencies/swift-dotnetmetadata",
        "d:/swift-winrt/generator/build/debug/_deps/swift-dotnetmetadata-src/sources/dotnetmetadatacinterop/include",
        "d:/swift-winrt/generator/build/debug/_deps/swift-dotnetmetadata-src/sources/dotnetmetadata",
        "d:/swift-winrt/generator/build/debug/_deps/swift-dotnetmetadata-src/sources/dotnetmetadata/attributes",
        "d:/swift-winrt/generator/build/debug/_deps/swift-dotnetmetadata-src/sources/dotnetmetadatacinterop",
        "d:/swift-winrt/generator/build/debug/_deps/swift-dotnetmetadata-src/sources/dotnetmetadataformat",
        "d:/swift-winrt/generator/build/debug/_deps/swift-dotnetmetadata-src/sources/dotnetxmldocs",
        "d:/swift-winrt/generator/build/debug/_deps/swift-collections-src/sources/orderedcollections/hashtable",
        "d:/swift-winrt/generator/build/debug/_deps/swift-collections-src/sources/orderedcollections/ordereddictionary",
        "d:/swift-winrt/generator/build/debug/_deps/swift-collections-src/sources/orderedcollections/orderedset",
        "d:/swift-winrt/generator/build/debug/_deps/swift-collections-src/sources/orderedcollections/utilities",
        "d:/swift-winrt/generator/build/debug/sources/codewriters",
        "d:/swift-winrt/generator/sources/projectionmodel",
        "d:/swift-winrt/generator/sources/projectionmodel/cabi",
        "d:/swift-winrt/generator/build/debug/sources/projectionmodel",
        "d:/swift-winrt/generator/sources/swiftwinrt",
        "d:/swift-winrt/generator/sources/swiftwinrt/writing",
        "d:/swift-winrt/generator/build/debug/sources/swiftwinrt",
        "d:/swift-winrt/generator/build/debug/_deps/swift-dotnetmetadata-src/sources/windowsmetadata/attributes",
        "d:/swift-winrt/generator/build/debug/_deps/swift-dotnetmetadata-src/sources/windowsmetadata"
    ],
    "compilerPath": "c:/users/tristan/appdata/local/programs/swift/toolchains/0.0.0+asserts/usr/bin/swiftc.exe",
    "compilerArgs": [],
    "compilerFragments": [
        "-sdk C:/Users/tristan/AppData/Local/Programs/Swift/Platforms/0.0.0/Windows.platform/Developer/SDKs/Windows.sdk/ -O -g -wmo -libc MD",
        "-suppress-remarks",
        "-suppress-warnings"
    ]
}
cpptools version (native): 1.21.6.0
Translation Unit Mappings:
[ D:\swift-winrt\Generator\.build\checkouts\swift-dotnetmetadata\Sources\DotNetMetadataCInterop\shim.c - source TU]:
Translation Unit Configurations:
[ D:\swift-winrt\Generator\.build\checkouts\swift-dotnetmetadata\Sources\DotNetMetadataCInterop\shim.c ]:
    Process ID: 18168
    Memory Usage: 50 MB
    Compiler Path: C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64\cl.exe
    Includes:
        C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\include
        C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\atlmfc\include
        C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\VS\include
        C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\Include\um
    System Includes:
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\winrt
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\cppwinrt
    Defines:
        _DEBUG
        UNICODE
        _UNICODE
    Standard Version: ms_c17
    IntelliSense Mode: windows-msvc-x64
    Other Flags:
        --using_directory
        C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\ATLMFC\lib\x64
        --using_directory
        C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\lib\x64
        --using_directory
        C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\lib\x86\store\references
        --using_directory
        C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.22621.0
        --using_directory
        C:\Program Files (x86)\Windows Kits\10\References\10.0.22621.0
        --using_directory
        C:\Windows\Microsoft.NET\Framework64\v4.0.30319
Total Memory Usage: 50 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 6004


### Other Extensions

CMake Tools and Swift extension, both of which I need (and more than the C/C++ extension in this scenario)

### Additional context

_No response_
@tristanlabelle tristanlabelle changed the title The "Unable to resolve configuration with compilerPath" warning steals the output window focus Bogus "Unable to resolve configuration with compilerPath" warning in Swift+CMake projects Sep 13, 2024
@tristanlabelle tristanlabelle changed the title Bogus "Unable to resolve configuration with compilerPath" warning in Swift+CMake projects Bogus "Unable to resolve configuration with compilerPath" warning in CMake+Swift projects Sep 13, 2024
@tristanlabelle
Copy link
Contributor Author

I'd be happy to submit a PR but I can't find how the string is referenced:
https://github.com/microsoft/vscode-cpptools/blob/fc5a084781aab590d0220f2ac4ff3c3e3cfcaec8/Extension/src/nativeStrings.json#L241

@bobbrow
Copy link
Member

bobbrow commented Sep 13, 2024

I don't think you need a PR, can you just set the C_Cpp.configurationWarnings setting to "disabled"? Maybe that's a bigger hammer than you want, but as long as CMake reports your compiler this way, we'll try to use it. I don't recall off hand whether we have a way to override the configuration provider's compiler. Perhaps @Colengms or @sean-mcmanus knows.

@sean-mcmanus
Copy link
Contributor

As far as I know there's no way to override configuration provider's compiler path.

@sean-mcmanus sean-mcmanus added the bug a bug in the product label Sep 13, 2024
@sean-mcmanus
Copy link
Contributor

Why is our extension being run on Swift files? We don't currently support Swift. Can the files.associations be changed such that our extension doesn't process the files?

@bobbrow
Copy link
Member

bobbrow commented Sep 13, 2024

There are C files in the workspace, so we get activated and will try to get the system includes before we index it.

@bobbrow bobbrow changed the title Bogus "Unable to resolve configuration with compilerPath" warning in CMake+Swift projects want to suppress "Unable to resolve configuration with compilerPath" warning in CMake+Swift projects Sep 13, 2024
@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Sep 13, 2024

@bobbrow You mean .c files that are actually Swift files? That should be fixed by setting files.associations appropriately, such as

   "files.associations": {
      "**/DotNetMetadataCInterop/*.c": "swift"
   }

Or CMake Tools or some Swift extension or us could maybe do that automatically?

I don't think it matters if we're activated if the file is not associated with C/C++ then we won't process it, although maybe setting the files.association might also fix the activation.

@tristanlabelle
Copy link
Contributor Author

tristanlabelle commented Sep 14, 2024

I've boiled it down to a more minimal repro where nothing should cause the C/C++ extension to be involved

  1. Install a Swift toolchain from https://www.swift.org/install/windows/
  2. Create a folder with these files:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.21.0)
project(Repro LANGUAGES Swift)

CMakePresets.json:

{
    "version": 3,
    "configurePresets": [
      {
        "name": "default",
        "generator": "Ninja",
        "binaryDir": "${sourceDir}/build"
      }
    ],
    "buildPresets": [
      {
        "name": "default",
        "configurePreset": "default"
      }
    ]
  }

.vscode/settings.json:

{
    "C_Cpp.configurationWarnings": "disabled"
}
  1. Open that folder in VS Code from a VS dev cmd
  2. Run the CMake: Configure command

A few seconds after CMake configure completes, the focus switches to the C/C++ Configuration Warnings pane, which shows:

[9/14/2024, 6:43:07 AM] Unable to resolve configuration with compilerPath "c:/users/tristan/appdata/local/programs/swift/toolchains/0.0.0+asserts/usr/bin/swiftc.exe".  Using "cl.exe" instead.

(note that the C_Cpp.configurationWarnings config did not prevent this)

CMake should be able to report a per-language compiler path so it seems like a bug that the C/C++ Extension ends up with the swiftc.exe path at all when it should only query the compiler for C and for C++ languages.

@tristanlabelle tristanlabelle changed the title want to suppress "Unable to resolve configuration with compilerPath" warning in CMake+Swift projects Suppress "Unable to resolve configuration with compilerPath" warning in CMake+Swift projects Sep 14, 2024
@bobbrow
Copy link
Member

bobbrow commented Sep 16, 2024

Thanks for the update @tristanlabelle,

I'm sorry, I gave you wrong information about that setting. It does not actually control this scenario.

I don't currently see any way to disable that behavior besides disabling the C++ extension for that workspace. CMake Tools activates the C++ extension automatically because it calls our API. It's possible that CMake Tools could be improved to not call our API and activate our extension if it detects that there is no C or C++ code that needs configurations, but in the meantime, if you don't need C++ support active, there should be no harm in disabling the extension for that workspace.

To do this, go to the Extensions tab and click the gear for the extension (lower right corner):
image
Then choose "Disable (Workspace)"
image

@tristanlabelle
Copy link
Contributor Author

Thanks as well for the follow-up. Unfortunately, this solution would regress our developer experience. While I am able to reproduce the issue with a minimal Swift-only project, all of the real-world projects in which we encounter this bug (including The Browser Company's main codebase) have a mix of Swift and C/C++ files. This interoperability is also a selling point of Swift, so it's a common scenario.

There's a few ways this could be solved (best to worse):

  1. The CMake Tools should provide the C/C++ extension with per-language compiler info since that is CMake's data model, or the C/C++ extension could query it from CMake, depending on what the interface between the C/C++ extension and CMake is. I couldn't find the code in the repo.
  2. The C/C++ extension could explicitly ignore a compiler called swiftc
  3. The C/C++ extension could provide a new setting or extend the existing one to silence those warnings.

@tristanlabelle
Copy link
Contributor Author

It seems likely that the issue is in this integration:

compilerPath: normalizedCompilerPath || undefined,
.

@sean-mcmanus
Copy link
Contributor

@gcampbell-msft Should this be moved to the vscode-cmake-tools repo?

@bobbrow
Copy link
Member

bobbrow commented Sep 16, 2024

@tristanlabelle @gcampbell-msft, my guess is that CMake Tools should skip the SWIFT compiler kind of like what we did for RC a long time ago. I think the fix would go here:

const lang = fileGroup.language === "RC" ? undefined : fileGroup.language;

@tristanlabelle
Copy link
Contributor Author

Ping @gcampbell-msft !

@bobbrow bobbrow transferred this issue from microsoft/vscode-cpptools Sep 26, 2024
@v-frankwang
Copy link
Collaborator

@tristanlabelle When we use the reproduction steps you provided to reproduce the issue, we get this error, can you give some advice?

image

@tristanlabelle
Copy link
Contributor Author

@v-frankwang , it looks like you don't have Swift installed as in my repro steps. where.exe swiftc.exe in the terminal should print the path to the swiftc compiler

@v-frankwang
Copy link
Collaborator

@tristanlabelle I still get the error after installing the Swift compiler.
Error message.txt

@tristanlabelle
Copy link
Contributor Author

@v-frankwang please make sure to open VS Code from a VS Developer Command prompt which reports x64 for both host and target:

C:\Code>set VSCMD_ARG
VSCMD_ARG_HOST_ARCH=x64
VSCMD_ARG_TGT_ARCH=x64

You might want to use the explicit x64 Native Tools Command Prompt for VS 2022 shortcut in the start menu.

@gcampbell-msft
Copy link
Collaborator

@tristanlabelle For the fix that @bobbrow pointed out, is the filegroup language for swift simply "swift"?

@tristanlabelle
Copy link
Contributor Author

@gcampbell-msft , I don't know what that filegroup concept is. It doesn't seem to come from CMake, from a code search, so I assume it comes from the CMake Tools extension?

@gcampbell-msft
Copy link
Collaborator

@tristanlabelle I'll investigate, thanks.

@gcampbell-msft
Copy link
Collaborator

@tristanlabelle Could you test out the fix in this vsix?

cmake-tools.zip

You'll have to change the file extension from .zip to .vsix after downloading.

@gcampbell-msft gcampbell-msft self-assigned this Oct 1, 2024
@gcampbell-msft gcampbell-msft added this to the 1.20 milestone Oct 1, 2024
@tristanlabelle
Copy link
Contributor Author

@gcampbell-msft Sorry for the wait. Yup! That fixed it with my repro. Mind @'ing me in the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Completed
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants