Vscode-cmake-tools: clang-arm intelliSenseMode selected instead of clang-arm64 on Apple Silicon machine

Created on 4 Dec 2020  Â·  9Comments  Â·  Source: microsoft/vscode-cmake-tools

Brief Issue Summary

The configuration provider for C++ extension in VS Code is supposed to automatically detect include paths.

It also should not ignore user-provided paths in the configuration file when failing to auto-find the paths (thought this might not be up to this extension – if so, ignore that).

Expected:

  1. Passing CMake Tools as a configuration provider
  2. All system include paths are resolved. If not, at least user-provided paths are taken.

Apparent Behavior:

  1. Passing CMake Tools as a configuration provider
  2. Squiggly include directive for system files show up saying for instance: "cannot open source file iostream"

Configuration file

// File: .vscode/c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/usr/local/include",
                "/Library/Developer/CommandLineTools/usr/include/c++/v1/**",
                "/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/**",
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/**",
                "/Library/Developer/CommandLineTools/usr/include/**",
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++20",
            "intelliSenseMode": "clang-arm64",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}

Platform and Versions

  • Operating System: macOS Big Sur on Apple Silicon (M1 chip)
  • CMake Version: cmake version 3.19.1
  • VSCode Version: 1.51.1
  • CMake Tools Extension Version: 1.5.3
  • Compiler/Toolchain: Apple Clang 12
cpptools integration bug

All 9 comments

If you go to the Output panel and select the C/C++ Configuration Warnings channel, do you see anything there?
image

I can only see C/C++ option but it indeed has some errors:

Quick info operation failed: FE: 'Compiler exited with error - No IL available'
Quick info operation failed: FE: 'Compiler exited with error - No IL available'
Quick info operation failed: FE: 'Compiler exited with error - No IL available'
Quick info operation failed: FE: 'Compiler exited with error - No IL available'
Failed to read response from server: 20
Quick info operation failed: FE: 'Compiler exited with error - No IL available'

Thanks for the prompt response, though. I really appreciate it.

EDIT: Also, here's a part from Log (Extension Host) window

[...]
[2020-12-04 20:38:05.181] [exthost] [error] [ms-vscode.cpptools] provider FAILED
[2020-12-04 20:38:05.181] [exthost] [error] undefined
[2020-12-04 20:38:12.199] [exthost] [error] [ms-vscode.cpptools] provider FAILED
[2020-12-04 20:38:12.199] [exthost] [error] undefined
[2020-12-04 20:38:26.110] [exthost] [error] [ms-vscode.cpptools] provider FAILED
[2020-12-04 20:38:26.110] [exthost] [error] undefined
[2020-12-04 20:40:15.438] [exthost] [warning] ms-vscode.cpptools - Code actions of kind 'quickfix 'requested but returned code action does not have a 'kind'. Code action will be dropped. Please set 'CodeAction.kind'.
[2020-12-04 20:40:15.438] [exthost] [warning] ms-vscode.cpptools - Code actions of kind 'quickfix 'requested but returned code action does not have a 'kind'. Code action will be dropped. Please set 'CodeAction.kind'.
[2020-12-04 20:40:16.438] [exthost] [warning] ms-vscode.cpptools - Code actions of kind 'quickfix 'requested but returned code action does not have a 'kind'. Code action will be dropped. Please set 'CodeAction.kind'.
[2020-12-04 20:40:16.438] [exthost] [warning] ms-vscode.cpptools - Code actions of kind 'quickfix 'requested but returned code action does not have a 'kind'. Code action will be dropped. Please set 'CodeAction.kind'.
[2020-12-04 20:40:17.131] [exthost] [warning] ms-vscode.cpptools - Code actions of kind 'quickfix 'requested but returned code action does not have a 'kind'. Code action will be dropped. Please set 'CodeAction.kind'.
[2020-12-04 20:40:17.131] [exthost] [warning] ms-vscode.cpptools - Code actions of kind 'quickfix 'requested but returned code action does not have a 'kind'. Code action will be dropped. Please set 'CodeAction.kind'.
[2020-12-04 20:40:21.146] [exthost] [warning] ms-vscode.cpptools - Code actions of kind 'quickfix 'requested but returned code action does not have a 'kind'. Code action will be dropped. Please set 'CodeAction.kind'.
[2020-12-04 20:40:21.146] [exthost] [warning] ms-vscode.cpptools - Code actions of kind 'quickfix 'requested but returned code action does not have a 'kind'. Code action will be dropped. Please set 'CodeAction.kind'.
[2020-12-04 20:40:47.185] [exthost] [error] [ms-vscode.cpptools] provider FAILED
[2020-12-04 20:40:47.185] [exthost] [error] undefined

Log (Window)

I guess it contains more reference:

[2020-12-04 20:38:26.116] [renderer5] [error] An unknown error occurred. Please consult the log for more details.
[2020-12-04 20:40:06.213] [renderer5] [error] Line 21: Unexpected token ILLEGAL: Error: Line 21: Unexpected token ILLEGAL
    at ErrorHandler.constructError (/Users/pawelparuzel/.vscode/extensions/ms-vscode.cpptools-1.1.3/dist/main.js:47100:22)
    at ErrorHandler.createError (/Users/pawelparuzel/.vscode/extensions/ms-vscode.cpptools-1.1.3/dist/main.js:47116:27)
    at ErrorHandler.throwError (/Users/pawelparuzel/.vscode/extensions/ms-vscode.cpptools-1.1.3/dist/main.js:47123:21)
    at Scanner.throwUnexpectedToken (/Users/pawelparuzel/.vscode/extensions/ms-vscode.cpptools-1.1.3/dist/main.js:47252:35)
    at Scanner.scanStringLiteral (/Users/pawelparuzel/.vscode/extensions/ms-vscode.cpptools-1.1.3/dist/main.js:48026:19)
    at Scanner.lex (/Users/pawelparuzel/.vscode/extensions/ms-vscode.cpptools-1.1.3/dist/main.js:48328:26)
    at Tokenizer.getNextToken (/Users/pawelparuzel/.vscode/extensions/ms-vscode.cpptools-1.1.3/dist/main.js:48763:84)
    at Object.tokenize (/Users/pawelparuzel/.vscode/extensions/ms-vscode.cpptools-1.1.3/dist/main.js:42242:36)
    at tokenize (/Users/pawelparuzel/.vscode/extensions/ms-vscode.cpptools-1.1.3/dist/main.js:24930:34)
    at Object.parse (/Users/pawelparuzel/.vscode/extensions/ms-vscode.cpptools-1.1.3/dist/main.js:25299:12)
    at /Users/pawelparuzel/.vscode/extensions/ms-vscode.cpptools-1.1.3/dist/main.js:59221:42
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
[2020-12-04 20:40:47.187] [renderer5] [error] An unknown error occurred. Please consult the log for more details.

Ok. If you run the C/C++: Log Diagnostics command, can you share what is printed out in that log window?

Sure, here's the log:

-------- Diagnostics - 12/4/2020, 10:37:31 PM
Version: 1.1.3
Current Configuration:
{
    "name": "Mac",
    "includePath": [
        "/usr/local/include",
        "/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/**",
        "/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/**",
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/**",
        "/Library/Developer/CommandLineTools/usr/include/**",
        "${workspaceFolder}/**"
    ],
    "defines": [],
    "macFrameworkPath": [
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
    ],
    "compilerPath": "/usr/bin/clang",
    "cStandard": "c11",
    "cppStandard": "c++20",
    "intelliSenseMode": "clang-arm64",
    "configurationProvider": "ms-vscode.cmake-tools",
    "customConfigurationVariables": {},
    "compilerArgs": [],
    "intelliSenseModeIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "compilerPathIsExplicit": true,
    "browse": {
        "path": [
            "/usr/local/include",
            "/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/**",
            "/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/**",
            "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/**",
            "/Library/Developer/CommandLineTools/usr/include/**",
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Custom browse configuration: 
{
    "browsePath": [
        "/users/pawelparuzel/documents/developer/test_project/inc",
        "/usr/local/include",
        "/users/pawelparuzel/documents/developer/test_project",
        "/users/pawelparuzel/documents/developer/test_project/src"
    ],
    "standard": "gnu++20",
    "compilerPath": "/usr/bin/clang++",
    "compilerArgs": [
        "-g",
        "-arch",
        "arm64",
        "-isysroot",
        "/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk",
        "-std=gnu++2a"
    ]
}
Custom configurations:
[ /Users/pawelparuzel/Documents/Developer/test_project/main.cpp ]
{
    "defines": [],
    "standard": "gnu++20",
    "includePath": [
        "/users/pawelparuzel/documents/developer/test_project/inc",
        "/usr/local/include"
    ],
    "intelliSenseMode": "clang-arm",
    "compilerPath": "/usr/bin/clang++",
    "compilerArgs": [
        "-g",
        "-arch",
        "arm64",
        "-isysroot",
        "/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk",
        "-std=gnu++2a"
    ]
}
Translation Unit Mappings:
[ /Users/pawelparuzel/Documents/Developer/test_project/main.cpp ]:
    /Users/pawelparuzel/Documents/Developer/test_project/main.cpp
Translation Unit Configurations:
[ /Users/pawelparuzel/Documents/Developer/test_project/main.cpp ]:
    Process ID: 13757
    Memory Usage: 84 MB
    Compiler Path: /usr/bin/clang++
    Includes:
        /usr/local/include
        /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include
    Standard Version: c++20
    IntelliSense Mode: clang-arm
    Other Flags:
        --clang
        --clang_version=120000
Total Memory Usage: 84 MB

------- Workspace parsing diagnostics -------
Number of folders and files enumerated: 2806
Number of files discovered (not excluded): 2608

Okay, I think I see the issue. When it says at the end:
Includes:
the /usr/local/include does not exist and /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include is not the correct path for system includes. It's for x86 sse stuff for some reason.

I could probably make a workaround by symlinking /usr/local/include but is there a clean way where I could change the "Includes:" to show up correctly?

@reconndev, just FYI, cpptools doesn't support the new Apple Silicon processor yet. https://github.com/microsoft/vscode-cpptools/issues/6595

There was a PR to enable the extension to run in emulated mode, but we haven't released that version yet. Which version of cpptools are you using? Did you patch the code manually to allow it to run on Apple Silicon? If that's how you got it running, then I suspect there is a problem querying the compiler for the system includes. I don't see anything wrong from the CMake side here. You definitely don't want to put system include paths in the includePath variable because gcc/clang are picky about the order of includes due to the way they structure their headers.

The Translation Unit Configurations: at the end shows you what the final include path (including system includes) was resolved to. The fact that your sysroot is not in there points to a problem with the compiler querying logic. For this to be the case though, I expected to see a warning in the Output channel I mentioned earlier.

cc: @Colengms

(The TypeScript callstack points to a problem with a bad character in your c_cpp_properties.json file. We should probably wrap the call to jsonc.parse with a try/catch - that's another bug for cpptools)

Yeah, I understand this is not yet supported. I was kind of thinking that because it is working 99%, I could maybe get it up to a 100% somehow (at least on emulation).

Which version of cpptools are you using? Did you patch the code manually to allow it to run on Apple Silicon?

C/C++ extension version is 1.1.3

I did not patch any code because the system itself can run x86 apps in Rosetta 2 so I ran it just like that and it seems to work right off the bat. The compiler path resolution may have gone wrong, maybe due to the mixing that I'm running in vscode in emulation but using a native compiler, I don't know.

I was just thinking, the final resolution path for any clang should probably be similar to output of this command:
/usr/bin/clang -Wp,-v -E -xc -x c++ /dev/null

I'm not sure what's in the guts of the extension but this way gets me the information I need pretty well.

I believe those are the exact switches we pass to the compiler when doing the query (and also -dD for defines), but the log doesn't show the right paths being used, so I'm not sure what's going on there. Until we get full support ready, you may not be able to use the configuration provider and will have to manually set includePath with the system includes that you get from running the compiler query. Just remember to keep the system include paths in the exact order they are reported and also to list them last in the includePath. You can also set compilerPath to the empty string "" to disable the compiler querying temporarily.

I recommend tracking microsoft/vscode-cpptools#6595, but based on our current schedule it may not be ready until cpptools version 1.4 which means you'll probably have to live with the workaround for a little while.

I was going to close this issue because it looks like CMake Tools is doing the right thing and we just need to wait for cpptools, but I do think it's passing the wrong IntelliSense mode clang-arm instead of clang-arm64. If it's alright with you, I'll repurpose this issue to cover that investigation.

Oh, it might be my doodling with the settings. I've put clang-arm64 because it defaulted to clang-x86 on emulated VS Code. Sorry if this change caused any ruckus. Feel free to close the issue if this is the case.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

decimad picture decimad  Â·  6Comments

bobbrow picture bobbrow  Â·  4Comments

andschwa picture andschwa  Â·  6Comments

Nightlights524 picture Nightlights524  Â·  3Comments

ItachiSan picture ItachiSan  Â·  6Comments