Cross-compiling to AmigaOS with VS Code - Setting Up the Code Editor/IDE
In the previous video I showed you how to set up an Amiga cross-compiler on your machine. The next step to setup a good code editor or Integrated Development Environment (IDE). My preferred editor and IDE is currently VS Code, and I'm going to show you how to set it up for cross-compiling to AmigaOS.
And by this I mean, be able to use the cross-compiler directly from within VS Code. You can already use VS Code to write Amiga software without installing anything else, but then you'd have to run an external shell window for compiling your code, which is inconvenient and inefficient.
Setup VS Code
First, download and install VS Code from its website (link), and follow the instructions for your platform.
Now, in VS Code, go to the extensions manager, search for the "Dev Containers" extension, and install it. This extension allows you to open your AmigaOS projects inside a Docker container, which is great, because our cross-compiler runs in a container.
While you're at it, install the "C/C++ Extension Pack," because you're going to be writing C/C++ code, and those extensions are very useful.
That's the setup done.
Configuring Our AmigaOS Project to Use the Dev Container
But, how do we use the "Dev Containers" extension? The key is to add the some config files to your projects. Don't worry, you only have to set this up once, and then you can copy and paste it from one project to another.
So, open up a project, and create a sub-directory called .devcontainer. Copy the docker-compose.yml containing the Amiga cross-compiler containers from the previous video into this new sub-directory.
Next, create a devcontainer.json file inside .devcontainer, and enter the following:
What this does, is tell VS Code's Dev Containers extension that we want to use the gcc11-ppc container from docker-compose.yml, and our workspace should be made available to the container at /opt/code.
By the way, a fully buildable example project with all these config files set up is available in the Kea Campus' Amiga Corner to Creator tier and higher members. So, if you want a short-cut, head over there and download it.
Building AmigaOS Software from VS Code
Alright! That's the config files done. Now we need to get VS Code to open our project from within the container. So, click the green "><" button lower left-hand corner, and select "Reopen in Container" from the dropdown. Alternatively, reopen the project, and VS Code should pop up a requester, asking you if you want to reopen the project in the Docker container.
Starting and entering the container might take a bit of time. Once it's done, then you're ready to go. You can type make in the VS Code terminal, and build your code.
Creating Build Tasks
We now have a pretty good AmigaOS development setup. However, wouldn't it be great if we could build the code without having to click on the terminal. To do that, we need to create some build tasks.
So, create a .vscode sub-directory, and create a file called tasks.json inside. The exact contents of this file depends on your project's build system. Here's an example for one of my Makefiles
Each task has a label, and some parameters to call make the same way you would do manually:
Once you've saved this file, then you can run a build at any time by pusing "Ctrl + Shift + B", and selecting which build you want. You can also select it from the Terminal menu (Terminal => Run Build Task...), but "Ctrl + Shift + B" is faster.
And just like that, we can conveniently work on and build AmigaOS software directly from within VS Code.
Get Ready-Made Templates
Template projects containing all the config files you saw in this video can be downloaded from Kea Campus' Amiga Corner (Creator tier and higher).
Next time I'll show you the fast way to copy the build files to the Amiga for testing.
Post your comment