Repository navigation
Fix IntelliSense in projects with compiler arguments in CMAKE_<LANG>_COMPILER - #4627
Conversation
390eb3b to
46ff0fb
Compare
|
Rebased on the updated #4620 to fix merge conflicts. No changes required. |
46ff0fb to
6bb8e92
Compare
|
Rebased on main, with minor manual conflict resolution. Verified that it still works, using the Steps to Reproduce above and CMake 4.3.1. Tests also still pass (although #4891 was required for me). I am guessing that the proper location for the changelog entry is now 1.24, because as far as I understand, version 1.23.51 has now been released as the final 1.23 release, and there is a new pre-release 1.24.0. |
|
@microsoft-github-policy-service agree company="Indel AG" |
6bb8e92 to
09f0f4d
Compare
|
Rebased to fix merge conflict in changelog. |
|
I will suspend further changelog conflict fixing whack-a-mole until asked or other changes become necessary. |
|
Hi Christian Walther (@cwalther), I really appreciate this contribution! I would like to properly review it, would you mind placing a changelog entry for it under 1.24 under Improvements? I understand it is a little bit of a whack-a-mole, but would appreciate your time so we can take this in! |
09f0f4d to
443ebda
Compare
|
Rebased and moved changelog entry from Features to Improvements. I see you made some changes to |
|
#4898 does not completely resolve the open question: |
|
CI fails because microsoft/vscode-cmake-tools-api#15 is not released yet. Until it is, you can test with a local checkout using this change: diff --git a/package.json b/package.json
index 7ca2066c..f2cabc34 100644
--- a/package.json
+++ b/package.json
@@ -4497,7 +4497,7 @@
"tsconfig-paths": "^3.11.0",
"tslint": "^6.1.3",
"typescript": "^4.1.5",
- "vscode-cmake-tools": "^1.7.0",
+ "vscode-cmake-tools": "file:../vscode-cmake-tools-api",
"vscode-nls-dev": "^3.3.2",
"webpack": "^5.104.1",
"webpack-cli": "^5.1.4" |
|
Christian Walther (@cwalther) got in your PR for the API + published it, all should be set now :) would you be alright resolving the conflicts? please let me or MacGyver Codilla (@mcodilla) know if you have any questions! |
443ebda to
0d783c2
Compare
|
Thanks, looks good! Rebased on main with manual conflict resolution in CHANGELOG.md, no other changes required; added yarn.lock changes for API package update. |
|
I’m not sure why the tests fail on Windows. I see no reason why CMake should choose cl.exe when I explicitly tell it to use cross-compile-gcc.exe. Looks like that somehow doesn’t get through. I guess I’ll have to set up a Windows development system and debug it. |
0d783c2 to
5d62a04
Compare
|
Before I do that, a shot in the dark: This reminds me of a similar problem I had while working on the CMake part: Could it be that in this Windows case CMake defaults to a Visual Studio generator that does not support other compilers than MSVC? Let’s try with an explicit generator. Hannia Valera (@hanniavalera) or MacGyver Codilla (@mcodilla), could you start the workflow again? |
|
Still the same failure. Too bad. Let me try to reproduce and debug it. |
The `CMAKE_<LANG>_COMPILER` variable or the `CC` or similar environment variable can contain command line arguments that must be passed to every invocation of the compiler. Previously, these were lost on the way from CMake to cpptools because the CMake file API did not expose them, causing non-working code navigation after cpptools called the compiler without them to determine system include paths and built-in preprocessor macro definitions. CMake 4.3 adds a new `commandFragment` member to the `toolchains. toolchains[].compiler` object to rectify that. Pass that along in configuration provider responses.
5d62a04 to
eac8959
Compare
|
Got it. I need to pass the generator using |
|
Christian Walther (@cwalther), thank you so much for the ongoing iterations and contributions, i was about to reply to inform you that is what i was theorizing, but we'll see if we're missing something! (i doubt it, though!) thanks a lot! |
|
Approved and merged! Thanks a lot once again! I really appreciate the diligence :) |
|
Thanks for the review! |
This changes visible behavior
The following changes are proposed:
The purpose of this change
Fix IntelliSense in projects with compiler arguments in
CMAKE_<LANG>_COMPILERby passing those arguments, newly exposed in the file API by CMake 4.3, to cpptools so it can properly determine system include paths and built-in preprocessor macro definitions.Other Notes/Information
Problem
In CMake, the
CCor similar environment variables as well as theCMAKE_<LANG>_COMPILERvariables set by toolchain files can, in addition to the compiler path, contain mandatory command line arguments that must be passed to every invocation of the compiler. Previously, these arguments were not exposed in the File API, therefore CMake Tools as an IntelliSense configuration provider had no way to pass them on tocpptools, thereforecpptoolswould call the compiler without them when trying to determine system include paths and built-in preprocessor macro definitions, potentially resulting in non-working code navigation.For example, for building for embedded systems with different CPU architectures we use toolchain files with lines like
where the referenced config file contains arguments like
--target,--sysroot,-stdlib++-isystemthat influence include paths and definitions. Currently, Visual Studio Codecpptoolscalls the compiler without these arguments when trying to determine the include paths and definitions, and gets back wrong values related to the host platform instead of the embedded system.Steps to Reproduce
Making a generic minimal reproducing example is a bit tricky because CMake expects working compilers (including sysroots). Here is something that works for me on an x86_64 Linux system with Clang 18 installed (Ubuntu 20.04,
clang-18package from official archive.ubuntu.com/security.ubuntu.com):CMakeLists.txt:
toolchain.cmake:
CMakePresets.json:
{ "version": 6, "configurePresets": [ { "name": "Test", "generator": "Ninja", "binaryDir": "${sourceDir}/output", "toolchainFile": "toolchain.cmake" } ] }main.c:
/usr/include/i386-linux-gnu/something.h:
Steps to reproduce
./output/test; echo $?to get the expected result42.file output/testconfirms that it was compiled for i386.Actual result
#include <something.h>has red squiggly underlines. Ctrl-clicking on it does nothing.helloshows no tooltip.hellodoes work and takes me to its definition in …/i386-linux-gnu/something.h. I would expect it to fail as well.-target i386-linux-gnuarguments have made it from CMake to cpptools, in particular the C/C++ diagnostics show the wrongsystem include: /usr/include/x86_64-linux-gnufor main.c.Expected result
helloshows a tooltip “int hello”.<something.h>orhelloopens …/i386-linux-gnu/something.h."compilerFragments": ["-target i386-linux-gnu"]for main.c.system include: /usr/include/i386-linux-gnufor main.c.Proposed Solution
CMake has just merged an addition to the file API to expose these arguments, to be released in CMake 4.3. I therefore propose the attached commits to retrieve them from the file API and pass them on to cpptools.
Only the last two commits are part of this change, the rest are #4620, which is required to actually be able to test with CMake 4.3 (so don’t use the combined diff for review, but the individual commits). But if there are objections to that, I will of course rework it. This change does not strictly depend on #4620, some of the added tests will just be skipped without it.An update to vscode-cmake-tools-api is required, submitted in microsoft/vscode-cmake-tools-api#15, so there is a dependency version bump in package.json. CONTRIBUTING.md tells me to ping “our team” in that case, but I don’t know who that is (maybe Garrett Campbell (@gcampbell-msft)?).
Open Questions
I am not sure what to do about the use of
shlex.split(), see comments in cpptools.ts:471. Possible options:shlex.splitto be what I would expect and what is needed here. However I fear that would break other things, because presumably the current behavior, which is explicitly tested for in test/unit-tests/shlex.test.td, was introduced for a reason in support parsing substring and also substrings with single quote and space #1663.Any preferences? Any comment from Elaheh Rashedi (@elahehrashedi) who wrote that behavior?