Skip to content

Add support for querying kcc compiler #13470

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

Open
Mathias-Buder-Bose opened this issue Apr 8, 2025 · 6 comments
Open

Add support for querying kcc compiler #13470

Mathias-Buder-Bose opened this issue Apr 8, 2025 · 6 comments

Comments

@Mathias-Buder-Bose
Copy link

Mathias-Buder-Bose commented Apr 8, 2025

Environment

  • OS: Windows 10
  • Compiler: kcc (custom)
  • VS Code Version:
    • Version: 1.99.0 (user setup)
    • Commit: 4437686ffebaf200fa4a6e6e67f735f3edf24ada
    • Date: 2025-04-02T21:35:19.530Z
    • Electron: 34.3.2
    • ElectronBuildId: 11161073
    • Chromium: 132.0.6834.210
    • Node.js: 20.18.3
    • V8: 13.2.152.41-electron.0
    • OS: Windows_NT x64 10.0.19045
  • CMake Version: 3.30.0
  • C++ Extension: ms-vscode.cpptools 1.24.5

Bug Summary and Steps to Reproduce

Summary

VS Code fails to correctly query the kcc compiler when using a compile_commands.json generated by CMake. It attempts to call the compiler with -x c++ which is not recognized by kcc, leading to fallback behavior and broken IntelliSense. In addition, the initialization at startup takes forever.

Steps to Reproduce

  • Install and VS Code C++ extension.
  • Configure a Conan-based CMake project with CMakeToolchain and CMakeDeps generators.
  • Use a custom compiler (in this case kcc).
  • Define environment variable CMAKE_EXPORT_COMPILE_COMMANDS in Windows
  • In VS Code, set:
{
  "C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json"
}

Expected Behavior

VS Code should use the flags and definitions from compile_commands.json and correctly provide IntelliSense without trying to query the compiler directly.

Actual Behavior

VS Code attempts to invoke the compiler with:

kcc.exe -x c++ -E -dM nul

But kcc doesn't support the -x option and fails with:

Error: Option '-x' was not recognised.
Run 'kcc -h' for usage information.

Then VS Code falls back to default or broken IntelliSense behavior.

Possible Fixes / Suggestions

  • Allow disabling all compiler probing when compile_commands.json is present and valid.
  • Provide an option to bypass all internal compiler invocations and use only what's in compile_commands.json.
  • Improve support for non-clang/gcc compilers that don’t recognize GCC-like options like -x.

Configuration and Logs

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "compileCommands": "${workspaceFolder}/build/compile_commands.json",
            "intelliSenseMode": "gcc-x86",
            "cStandard": "c17",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

C/C++: Log Diagnostics

Attempting to get defaults from C compiler in compile_commands.json file: 'C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe'
Unable to configure for compiler cl.exe.
Attempting to get defaults from compiler found on the machine: 'C:\cygwin64\bin\gcc.exe'
Querying compiler for default C++ language standard using command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -x c++ -E -dM nul
Querying compiler for default C++ language standard using command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -x c++ -E -dM /dev/null
Detected language standard version: c++98
Querying compiler's default target using command line: "C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe" -dumpmachine
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=c17 -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=c11 -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=c99 -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=c89 -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=gnu23 -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=gnu2x -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=gnu18 -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=gnu17 -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=gnu11 -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=gnu1x -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=gnu99 -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=gnu9x -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -std=gnu89 -m32 -Wp,-v -E -dM -x c nul
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -m32 -Wp,-v -E -dM -x c nul
Failed to query compiler. Falling back to 64-bit intelliSenseMode.
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -m64 -Wp,-v -E -dM -x c nul
Failed to query compiler. Falling back to no bitness.
Compiler query command line: C:\.conan\1cb681\1\tools\kcc\bin\kcc.exe -Wp,-v -E -dM -x c nul
Error: Option '-x' was not recognised.
Run 'kcc -h' for usage information.

KCC help command

PS > kcc.exe -h
Kalimba C compiler driver, version 81
Copyright (c) 2008 - 2023 Qualcomm Technologies International Limited

Usage: kcc [options] <file...>

KCC Driver options:
 --help                   print help
 --version                report all tool versions and exit
 -?                       print help
 -B<path>                 specify tool path and prefix
 -g                       enable debug symbols
 -h                       print help
 -k<chip>                 specify target chip name
 -mark-code-section-type  append '__minim' or '__maxim' to code section names based on
                          instruction set used in compilation unit or assembly module
 -minim                   target MiniMode instruction set
 -n                       report commands rather than running them
 -o <filename>            specify output file
 -save-temps              keep intermediate files around
 -v                       report all tool versions and exit

Compiler options:
 -D<symbol>               define preprocessor symbol
 -E                       preprocess only
 -I<path>                 add a directory to the compiler's include path for preprocessing
 -MABS                    (Linux only) use absolute paths for prerequisites in make dependency fragments
 -MAC                     allow a colon in dependency paths in generated make dependency file
 -MD                      generate make dependency files for compiled code
 -MF<filename>            specify filename for generated make dependency file
 -MT<target name>         specify target for generated make dependency file
 -O<level>                set optimisation level. <level> may be O0, O1, O2/Osize (the default), or O3/Ospeed
 -P                       preprocess only, no directives
 -S                       produce assembly files, then stop
 -U<symbol>               undefine preprocessor symbol
 -W<level>                enable or disable compiler warnings. <level> can be blank or equal to: all, strict, none, WarningName, noWarningName.
 -Xc <argument>           pass next argument through to the compiler
 -Xcompiler <argument>    pass next argument through to the compiler
 -allow-inline            deprecated option (has no effect)
 -dM                      dump list of preprocessor defines to stdout
 -dp                      show matched compiler rules in generated assembly
 -inline-static-called-once automatically inline static functions that are called only once
 -no-debug-inline         avoid making a copy of inline functions in debug mode - this saves code space, but inlined functions will not be debuggable
 -old-mangling            restore pre-KCC 40 mangling of autogenerated data labels (L_x instead of A_x)
 -optional-reads          restore pre-KCC 40 behaviour of implementing optional reads of volatile objects
 -pic                     generate a limited form of position independent code
 -preinclude <filename>   causes <filename> to be automatically included in every source file

Assembler options:
 -A<path>                 add include path to assembler
 -Xa <argument>           pass next argument through to the assembler
 -Xassembler <argument>   pass next argument through to the assembler
 -c                       produce object files, but do not link

Linker options:
 -L<path>                 append to library search path
 -Xl <argument>           pass next argument through to the linker
 -Xlinker <argument>      pass next argument through to the linker
 -gc-sections             enable garbage collection in the linker (discards unused code and data)
 -l<libname>              add a library for linking
 -mno-crt0                don't link in crt0.o automatically
 -mno-libc                don't link in libc.a automatically
 -mno-libcrt              don't link in libcrt.a (basic runtime) automatically
 -mno-libfle              don't link in libfle.a (floating point emulation) automatically
 -no-relax                turn off prefix relaxation in the linker
 -nodefaultlibs           don't automatically link crt0 or any C libraries (no crt0, libc, libcrt, libfle)

Target chip names accepted by -k are:
kalarch4
csra68100_app
csra68100_audio
QCC302x_apps
QCC302x_audio
QCC512x_apps
QCC512x_audio
QCC514x_apps
QCC514x_audio
QCC516x_apps
QCC516x_audio
QCC517x_apps
QCC517x_audio
QCC518x_apps
QCC518x_audio
QCC309x_apps
QCC309x_audio

Other Extensions

No response

Additional context

No response

@Colengms
Copy link
Contributor

Colengms commented Apr 8, 2025

Hi @Mathias-Buder-Bose . Thanks for your feature request.

Currently, the compiler detection/querying logic in the C/C++ Extension supports only MSVC, GCC, Clang and compilers derived from GCC or Clang (which still support the same arguments). For now, I'd suggest not using compile_commands.json in your configuration, set compilerPath to "" (an empty string) to prevent compiler querying, and provide system defines and system include paths your code requires in your base configuration in defines and includePath.

@Colengms Colengms changed the title VS Code fails to parse kcc compiler with -x flag Add support for querying kcc compiler Apr 8, 2025
@bobbrow
Copy link
Member

bobbrow commented Apr 8, 2025

linking to #6931

@Mathias-Buder-Bose
Copy link
Author

Hi @Mathias-Buder-Bose . Thanks for your feature request.

Currently, the compiler detection/querying logic in the C/C++ Extension supports only MSVC, GCC, Clang and compilers derived from GCC or Clang (which still support the same arguments). For now, I'd suggest not using compile_commands.json in your configuration, set compilerPath to "" (an empty string) to prevent compiler querying, and provide system defines and system include paths your code requires in your base configuration in defines and includePath.

Hi @Colengms,

Thank you for your quick reply. I’m using a build system that combines Conan, CMake, and Artifactory. In this setup, the defines and includes change based on my build configuration. This means that CMake dynamically adds include paths, like C:/.conan/8e38db/1/include, to the build command, as illustrated in the compile_commands.json example below. Unfortunately, the effort required to manually add includes and defines is quite high. Is there a workaround that allows me to avoid compiler queries while still retaining the necessary includes and definitions?

compile_commands.json Example

"command": "C:\\.conan\\87edad\\1\\tools\\kcc\\bin\\kcc.exe -DBLUELAB=1 -DBOSE_STDINT_FILE=\"<core_types.h>\" -DCORE_ENDIANNESS=CORE_ENDIANNESS_LITTLE -DCORE_FORMAT_CHECKS -DDEBUG_BUILD=1 -DENABLE_BT_TOPOLOGY_SINGLE=1 -DGC_SECTIONS=1 -DHAVE_32BIT_DATA_WIDTH=1 -DHYDRACORE=1 -DINSTALL_HYDRA_LOG=1 -DSYSLOG_MAXIMUM_LEVEL=5 -DTAP_HELP_PRINT_ENABLED=1 -DUSB_AUDIO_ENABLED -DWITH_ACTIVE_HANDLE_ISR_SAFE=0 -DWITH_ADC=1 -DWITH_AUDIO_LOOPBACK=0 -DWITH_BLUETOOTH_INTERFACE=1 -DWITH_CORE_MALLOC_FILL=0 -DWITH_CORE_MALLOC_GUARD=0 -DWITH_CORE_MALLOC_METRICS=1 -DWITH_CORE_MUTEX_ASSERT=1 -DWITH_CRASHDUMP=1 -DWITH_CRYPTO=1 -DWITH_DATA_COLLECTION=1 -DWITH_DEBUG_TOOLS=1 -DWITH_FILE=1 -DWITH_GPIO=1 -DWITH_I2C=1 -DWITH_IAP2=1 -DWITH_POWER=1 -DWITH_QUEUE=1 -DWITH_SETTINGS=1 -DWITH_SMALL_CRC32 -DWITH_STATS=1 -DWITH_STCP=1 -DWITH_SYSLOG=1 -DWITH_SYSTEM=1 -DWITH_TAP=1 -DWITH_THREAD_MONITORING=0 -DWITH_USB=1 -DWITH_USB_AUDIO=\"\" -DWITH_WATCHDOG=1 -D__KALIMBA__=1 -IC:/.conan/87edad/1/tools/kcc/include -I. -IC:/.conan/8e38db/1/include -IC:/.conan/58f00d/1/include -IC:/.conan/3c3aa7/1/include -IC:/.conan/3c3aa7/1/bin/proto -Ibuild -I../Source/core -Werror -kQCC518x_apps -Werror -Wall -WnoConstantTest -WCharPointerUnaligned -minim -Xa -apply-b179745-workaround -mark-code-section-type  -O0 -gc-sections -g   -o CMakeFiles\\SpitfireCoreServicesMain.dir\\Source\\core\\connection_manager\\core_connection_protocol_manager.o -c C:\\...\\foo.c",
        "directory": "C:/.../build",
        "file": "C:/.../foo.c"

@Colengms
Copy link
Contributor

Colengms commented Apr 9, 2025

Hi @Mathias-Buder-Bose . It's possible to override the compiler used by compile_commands.json (but not the args) by also setting the compilerPath field in c_cpp_properties.json (or C_Cpp.default.compilerPath, if none is set in c_cpp_properties.json, I think).

You could potentially implement a script that outputs your compiler's predefines and system include paths (in a format matching what is returned by a GCC/Clang compiler query) and use that as your compilerPath. The C/C++ Extension ingests include paths and define arguments from the command line, stripping them before trying to query the compiler. So, as long as the compiler query doesn't fail, those would still be ingested and used to configure IntelliSense.

@Mathias-Buder-Bose
Copy link
Author

Hi @Mathias-Buder-Bose . It's possible to override the compiler used by compile_commands.json (but not the args) by also setting the compilerPath field in c_cpp_properties.json (or C_Cpp.default.compilerPath, if none is set in c_cpp_properties.json, I think).

You could potentially implement a script that outputs your compiler's predefines and system include paths (in a format matching what is returned by a GCC/Clang compiler query) and use that as your compilerPath. The C/C++ Extension ingests include paths and define arguments from the command line, stripping them before trying to query the compiler. So, as long as the compiler query doesn't fail, those would still be ingested and used to configure IntelliSense.

Hi @Colengms, thanks a lot for that. I'll give it a try!

@Mathias-Buder-Bose
Copy link
Author

@Colengms, I wrote a script that parses my compile_commands.json to extract its includes and predefines. The goal is to eventually add them into c_cpp_properties.json. The solution is a bit hacky, but it gets the job done for now.

I'm looking forward to the implementation of this feature request.

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

No branches or pull requests

3 participants