A Dev Container gives you a pre-configured programming environment inside VS Code. Instead of installing the RISC-V compiler and other tools directly on your laptop, VS Code runs them inside a container.
This helps make sure everyone in the class is using the same setup.
Install these on your computer:
You only need to install these once.
Note for those installing Docker on Mac! If you have the issue where VSCode is not recognizing your Docker installation, please open Docker Desktop –> Settings –> Advanced, change the CLI tools configuration from User to System.
Download or clone the assignment/starter folder, then open that folder in VS Code.
You should see a folder named:
.devcontainer
inside the project.
Open the VS Code Command Palette:
Mac: Cmd + Shift + P
Windows: Ctrl + Shift + P
Search for:
Dev Containers: Reopen in Container
and select it.
The first time you do this, VS Code may take a few minutes to build the environment.
After the container opens, start a new terminal in VS Code.
You should see a prompt that looks something like:
vscode@...
rather than your normal laptop username.
Then run:
311-checkYou should eventually see:
Success: generated RV32I assembly.
If you see that, your environment is ready.
The RISC-V tools are installed inside the Dev Container, not directly on your laptop.
So this may fail in your normal Terminal app:
311-checkwith an error like:
riscv64-unknown-elf-gcc: command not found
That usually means you are running the command outside the container.
Open the project in VS Code and use:
Dev Containers: Reopen in Container
before running the COMP 311 commands.
To compile a C program without compiler optimizations:
311-compile -O0 examples/scale.cTo compile the same program with optimization:
311-compile -O2 examples/scale.cGenerated files will appear in the build/ directory.
For example:
build/scale_O0.s
build/scale_O0.o
build/scale_O0.dump
The most useful file for this assignment is usually:
.s
which contains the compiler-generated RISC-V assembly.
You can open it directly in VS Code.
If you write your own assembly file:
myprogram.s
you can assemble it using:
311-assemble myprogram.sThe resulting object code and disassembly will appear in
build/.
311-checkChecks that the environment is working.
311-compile -O0 file.cCompile C to RV32I with no optimization.
311-compile -O2 file.cCompile C to RV32I with compiler optimization.
311-assemble file.sAssemble hand-written RV32I assembly.
ls buildSee your generated files.
cat build/example_O0.sPrint generated assembly in the terminal.
If the container does not open correctly, try:
Cmd/Ctrl + Shift + P
then:
Dev Containers: Rebuild Container
If you get:
command not found
for a COMP 311 or RISC-V command, first check that you are actually inside the Dev Container.
You can also run:
whoamiInside the container, this will typically print:
vscode
You can think of the setup like this:
Your laptop
|
+-- VS Code
|
+-- Dev Container
|
+-- RISC-V compiler
+-- assembler
+-- course scripts
+-- your project files
Your files are still visible on your computer, but the programming tools run inside the container.
The main rule to remember is:
Open the project in the Dev Container before running COMP 311 commands.