Using VS Code With a Dev Container
In this section we’ll learn how to use VS Code and Dev Containers.
Opening Docker Desktop
Before running VS Code with a Dev Container, we need to make sure Docker Desktop is running. Please open it now. You can leave it running in the background.
Opening VS Code
- Make sure you have your terminal open to the
env-learningdirectory.pwdEnsure that the result of
pwdends withenv-learning. - Open VS Code in the current directory by running:
code .If this does not work, you can instead open VS Code, and click on File > Open Folder. Then find and select the
env-learningfolder. Either way, keep the terminal window open. We will return it it soon.
Opening in a Dev Container
- VS Code should automatically detect that there is a Dev Container in this repo. There will likely be a pop-up in the bottom right corner asking if you want to re-open the project in a Dev Container. Click the button to do so.
If the pop-up does not appear, you can manually choose to re-open in container by clicking the button with the left and right arrows in the VERY bottom left of the VS Code window. It will pop up a list of options at the top of the window. Choose “Reopen in Container”
- This will create a new container (similar to a lightweight virtual machine) that has all the tools we need for Game Boy Advance Development set up in it. It will take a while the first time it sets up, there’s a lot it needs to download. It will be faster after the first time.
How does VS Code Know How to Configure the Environment?
The configuration for the Dev Container is in the
.devcontainerdirectory. Feel free to take a peek in there to explore your curiosity if you like! You won’t need to change anything there, but it might be interesting to see.
The Dev Container Terminal
- Once the repo has been reopened in a container, you will be able to use the environment. Open a new terminal by clicking the “Terminal” button at the top of the screen and choosing “New Terminal”. NOTE THAT THIS TERMINAL is running in the Dev Container NOT on your host computer.
- Do a quick
lsin the terminal. You should see roughly the same files/folders as a re shown on the left ofVS Code.
Making the Sample Game
- The code for the game is in
src/main.cpp. Click on the arrow next tosrcon the left panel to expand the directory, then click onmain.cpp. - Take a quick look through the file. It’s OK if you don’t fully understand it yet!
- We will now make a game using
make. Go to the terminal in VS Code and run:make - This will compile the game. It will take a while the first time, but will be faster on subsequent makes.
How does
makeknow how to make the game?The configuration for
makeis in theMakefilefile. Feel free to open it up and take a quick look if you’re curious. Most of the magic happens in Butano / DevKitArm’s Makefiles, but this one shows you how they’re configured. Explore your curiosity! - If all goes well, a few files will be created, including
env-learning.gba. This is your compiled Game Boy Advance ROM!
After the game compiles, we’ll try running it in mGBA!