An overview of how to set up remote code development environment, useful even after 106L!
When developing C++, developers rarely start by copying a pasting a blank Qt Creator project. Although Qt is an excellent integrated development environment (IDE) for learning C++, it's important for you to learn how to build and run your C++ files yourself. To give you the experience of working on C++ projects from scratch, outside of environments like Qt Creator, we’ll be running our code remotely on the myth machines, a set of computers in the Gates building's basement. Don’t fear! You’ll be able to use a code editor on your laptop just like Qt Creator called VSCode while editing files on a completely different myth machine computer.
If that sounds like a lot, don't worry! We'll take you through it step by step. If you follow the instructions shown below, you will rarely (if ever) have issues with your setup. There are two parts to this page: instructions that you need to only run once to first set up for the class, and instructions to follow each time you're starting an assignment.
If you ever have any trouble at all with any part of this page, please feel free to email us at cs106l-win2223-staff (at) lists (dot) stanford (dot) edu. We'll be happy to help with any issue you find!
This entire section will have instructions you only need to run once. The next section will detail what you need to do for each assignment. This quarter, you'll usually have two windows open--one to edit your code, and another to run it. Let's download and set up the first, a code editor called VSCode!
That's it for VSCode for now! Next, we'll show you how to log into the myth machines (to eventually run your code) and create a folder that you'll keep your assignments in.
Ctrl + `
to use VSCode's command line. If that doesn't work for you, for Macs, open the "Terminal" app (click here for help).
For Windows, open your start menu, type "command prompt", and open the Command Prompt app.ssh yourSUIDHere@myth.stanford.edu
Here are instructions to follow when you start work on each of our assignments (you'll need to repeat these for each assignment).
First, we'll need to download the assignment into the folder we created in the previous section (we called ours "cs106L"). Let's connect to the myth machines first!
ssh yourSUIDHere@myth.stanford.edu
cd cs106L
git clone https://github.com/snme/cs106L-assignment2.git
mv cs106L-assignment2 cs106L-assignment1
./setup.sh
Leave this window open, but that's it! To recap, we've connected to the myth machines, downloaded our assignment, set up the project, and got the full path to our working directory. Now, you may be wondering--how do I edit files? There are ways to edit files through your shell, but we'll spare you of learning that now (if you'd like to, send us an email).
If the below steps havent been working for you (or if you want to learn a different way to edit files stored in the myth machines), jump to here! If you have not yet set up your VSCode, please jump to that link.
Let's get you editing code with VSCode! By the end, you'll be able to edit code files locally, with your changes automatically syncing to the myth machines whenever you hit save!
First, we need to create a folder that we'll download our code files from the myth machines into. Create a folder wherever you want on your computer (with Finder or Windows Explorer). Next, open VSCode, click File>Open... and select your folder.
Now, we'll set up our automatic file syncing to sync our changes from your computer to the myth machines. Click View>Command Palette..., type "SFTP: Config", and hit enter.
Delete everything in the file that pops up and paste the text below. Add your username where indicated (in quotes, after "username":), and replace the text in the quotes after "remotePath:" with the output from step 6 above.
{
"name": "Myth",
"host": "myth.stanford.edu",
"protocol": "sftp",
"port": 22,
"username": "YOURUSERNAMEHERE",
"interactiveAuth" : true,
"remotePath": "replace this with the path to your assignment1 directory on the myth machine (output from the pwd command, step 6, above)",
"uploadOnSave": true,
"ignore" : [
"build/",
"vcpkg/",
"build_and_run.sh"
]
}
Congratulations! You've just been exposed to several technologies that developers of all code will use throughout their careers, from bash (shell) to git to C++ project files. You're all set!
Good luck! :)
This verison gets you set up with VS Code SSH instead of VS Code SFTP. In the version above, you were setting up a protocol which allowed you to download files from myth, edit them locally, and then reupload your local files to myth every time you saved. Basically, you are working on a local copy of your assignment files and constantly uploading that copy to myth as you work. With this method, you will have no local copy of your work, you will simply use VS Code to ssh into myth, and then the VS Code editor will be like a window into the myth machines, and all edits you make in the editor will be on the actual files in myth, not on local files!
cd
into the path you saved while dowloading the code and type code .
into the terminal. It should open up a new window with all the files in the direcotry you chose! Voila!
If you are editing code this way, when its time for you to turn in the assignment, you will need to make a local copy of the files you've been editing in myth. You can do this with a single command line command!
~/Desktop/CS106L
! We will refer to this as LOCAL_PATH. You also need the path to your assignment folder in myth, which is what you copied in the step before VS Code setup, this will be MYTH_PATH. scp -r <yoursunetid>@myth.stanford.edu:MYTH_PATH LOCAL_PATH
scp [-r] [HOST:]SOURCE [HOST:]DESTINATATION
(where []
denotes including this is optional, you would want to include sunet@myth.stanford.edu:
in the relevant [HOST:]
). If you are moving a directory instead of just one file, you will need to use the -r
flag after scp