CMake: generate chpl-language-server .cls-commands.json#28427
CMake: generate chpl-language-server .cls-commands.json#28427DanilaFe wants to merge 6 commits intochapel-lang:mainfrom
.cls-commands.json#28427Conversation
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
The idea is to make things work with CMake. CMake explicitly computes the Chapel executable path. This is great, but `chpl-shim` isn't very good at handling this, since its whole modus operandi is to place itself as 'chpl' in the PATH, which CMake circumvents. To make things work, * Allow calling code to override 'CHPL_SHIM_REAL_COMPILER_PATH' (so that it's not read by chpl-shim from the PATH variable, which would violate whatever CMake computed). * Have CMake invoke the linking command as 'chpl' (no explicit path) but provide 'CHPL_SHIM_REAL_COMPILER_PATH' (with the explicit path). This way, CMake invokes `chpl-shim chpl <args>`, `chpl-shim` places hooks into that call and parses the arguments (thus generating JSON), and finally it reads the environment variable to invoke the compiler CMake intends. Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
1c4c962 to
c31e72d
Compare
doc/rst/usingchapel/compiling.rst
Outdated
| mkdir build && cd build | ||
| cmake .. -CMAKE_EXPORT_CHPL_COMMANDS=ON | ||
| cmake --build . | ||
| cd .. && ln -s build/.cls_commands.json .cls_commands.json |
There was a problem hiding this comment.
This is a bit unfortunate. We should consider adding a flag to CLS to specify the .cls-commands to use
There was a problem hiding this comment.
Maybe, but that's not a flag that can be passed in general since CLS starts up in an arbitrary folder. Not to mention in VSCode, it starts up in potentially a different folder. So as far as I can see:
- Using the flag with an absolute path is not possible, since that hardcodes CLS to only one project (as opposed to any project your editor opens)
- Using the flag with a relative path doesn't work since that relative path need no exist
I suppose we could configure .cls-commands.json to allow pointing to a DIFFERENT .cls-commands.json, but isn't that a worse symlink?
FWIW, I use symlinks like this with compile-commands.json and C/C++.
There was a problem hiding this comment.
FWIW, I use symlinks like this with compile-commands.json and C/C++.
👍
doc/rst/usingchapel/compiling.rst
Outdated
| mkdir build && cd build | ||
| cmake .. -CMAKE_EXPORT_CHPL_COMMANDS=ON | ||
| cmake --build . | ||
| cd .. && ln -s build/.cls_commands.json .cls_commands.json |
There was a problem hiding this comment.
also note, its cls-commands, not cls_commands
There was a problem hiding this comment.
I knew it looked wrong!
| set(CMAKE_CHPL_LINK_EXECUTABLE "<CMAKE_CHPL_COMPILER> -o <TARGET> <OBJECTS> <FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>") | ||
| if(CMAKE_EXPORT_CHPL_COMMANDS) | ||
| # Get the directory containing the chpl compiler to find chpl-shim | ||
| get_filename_component(CHPL_BIN_DIR "${CMAKE_CHPL_COMPILER}" DIRECTORY) | ||
| set(CHPL_SHIM_SCRIPT "${CHPL_BIN_DIR}/chpl-shim") | ||
|
|
||
| message(STATUS "CMAKE_EXPORT_CHPL_COMMANDS is ON, checking for chpl-shim at ${CHPL_SHIM_SCRIPT}") | ||
|
|
||
| if(EXISTS "${CHPL_SHIM_SCRIPT}") | ||
| # Use chpl-shim as a wrapper to generate .cls-commands.json | ||
| # Note: chpl-shim expects to be called as 'chpl-shim chpl <args>', not with full path | ||
| message(STATUS "Using chpl-shim to generate .cls-commands.json") | ||
| set(CMAKE_CHPL_LINK_EXECUTABLE "<CMAKE_COMMAND> -E env CHPL_SHIM_REAL_COMPILER_PATH=${CMAKE_CHPL_COMPILER} ${CHPL_SHIM_SCRIPT} chpl -o <TARGET> <OBJECTS> <FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>") |
There was a problem hiding this comment.
anyway to reduce the duplication between the two link commands?
| # Use chpl-shim as a wrapper to generate .cls-commands.json | ||
| # Note: chpl-shim expects to be called as 'chpl-shim chpl <args>', not with full path |
There was a problem hiding this comment.
Feels like that's a hard limitation without dynamic loading magic (whatever bear does)
| if(EXISTS "${CHPL_SHIM_SCRIPT}") | ||
| # Use chpl-shim as a wrapper to generate .cls-commands.json | ||
| # Note: chpl-shim expects to be called as 'chpl-shim chpl <args>', not with full path | ||
| message(STATUS "Using chpl-shim to generate .cls-commands.json") |
There was a problem hiding this comment.
nit, this message will be printed when configuring, not when chpl-shim is actually used
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
jabraham17
left a comment
There was a problem hiding this comment.
except for the docs typo, looks good!
|
|
||
| To enable use of CMake-based projects with the :ref:`language server <readme-chpl-language-server>`, | ||
| the CMake integration provides a special variable ``CMAKE_EXPORT_CHPL_COMMANDS``. | ||
| When set to ``ON``, CMake will generate a file named ``.cls_commands.json`` in |
This enables editors to properly make sense of a project generated with CMake.
Testing
.cls-commands.jsonwhen the environment variable is set.