Remote SSH - Thoemi09/moderncpp_vscode GitHub Wiki
The Remote-SSH extension lets us use a remote machine as our development environment while running VS Code locally. The source code is located on the remote machine.
Preliminary setup
We are assuming the following tasks have been done beforehand:
- The remote host that we want to connect to is defined in the local SSH configuration file
~/.ssh/config
. - The toy repository has been cloned and set up on the remote machine as described in Basic VS Code setup.
Install the extension
To install/enable the extension, follow the same steps as in the previous sections.
Get started
Connect to Host
To establish a connection to the remote machine,
- Run
>Remote-SSH: Connect to Host...
- Select your host from the pop up window (
workstation
in our case)
This opens a new VS Code window that is connected to the remote host (see bottom left corner):
Install extensions on the remote machine
Just like we did in the previous sections, we can install extensions on the remote machine.
- Go to
Extensions
in the activity bar
VS Code shows you all the extensions which are installed on the local and on the remote machine. It will also disable certain local extensions if they cannot be used on the remote machine.
To install an extension remotely, simply select a greyed out local extension and click Install in SSH: workstation
:
Settings on the remote machine
To modify VS Code user settings on the remote machine,
- Run
>Preferences: Open Remote Settings (JSON) (SSH: workstation)
You can simply copy the contents of your local user settings to the remote file.
Note: Be careful to adjust all paths in case they don't make sense for the remote machine. Settings for extensions which are not installed remotely will simply be greyed out and ignored.
Open the workspace on the remote machine
To open a folder on the remote machine,
- Run
>File: Open Folder...
- Select the remote workspace folder
moderncpp_vscode
Configure CMake
First, follow the same steps as in Setting the source directory.
Setting up the CMake kits can be a little bit more complicated.
Often we want to connect to an HPC cluster which uses Environment modules.
In this case, we don't want CMake Tools to find the kits for us.
Instead, we will add them manually by running >CMake: Edit User-Local CMake Kits
:
The first kit we added is
{
"name": "GCC 12",
"compilers": {
"C": "gcc",
"CXX": "g++",
"Fortran": "gfortran"
},
"isTrusted": true,
"environmentSetupScript": "/mnt/home/thahn/scripts/compilers/init_gcc12.sh",
"description": "v12.2.0"
}
As you can see, we did not specify any absolute paths for the compilers.
Instead, we will bring them into the PATH
by loading the right modules with the setup script /mnt/home/thahn/scripts/compilers/init_gcc12.sh
.
The script is located on the remote machine and contains the following lines:
module purge
module load modules/2.2
module load gcc/12
module load cmake
module load git
module load python
Of course, you will need to adjust this file for the remote machine that you are connected to.
Build and Run
Once we have all our kits defined, we can Select a kit + variant and configure the project and Build the project.
To Run tests and examples from the terminal, we might have to load the corresponding modules first.
Otherwise, you can simply run them directly from the Status Bar.
clangd
We can also check that the language server works as expected by opening the ./src/linalg.cpp
file and hovering over nda::matrix
:
CodeLLDB and Debugging
If you don't need any specific environment setup for your executable, you can simply follow the steps in the CodeLLDB section.
If your executable depends on certain environment modules to be loaded beforehand, it might be easier to debug from the command line or use Dev Containers as explained in the next section.