The SDK for Windows is a little anemic, so I figured this might be useful to anyone trying to figure out how to program in C on Windows. Also, none of this is really Windows only, the modified bits are fixed up to also support Windows properly as well as allow user defined paths for the SDK and toolchain using environment variables.
This will setup a simple C project using Visual Studio Code and CMake. We use CMake because Panic has provided some helper CMake files that help generate/compile our project, and Visual Studio Code as it has extensions to interact with CMake.
-
CMake (https://cmake.org/)
First half of our build system; this will configure and generate Ninja build files for us to build our project with. -
Visual Studio Code
- C/C++ extension by Microsoft
- CMake Tools extension by Microsoft
Don’t forget the extensions! They help us get Visual Studio Code to a decently functioning IDE for our project.
-
Ninja (https://github.com/ninja-build/ninja/releases)
Just unpack this in some directory (for ex. C:/playdate_dev/bin). Remember where you put it, we’re gonna need to add it to our PATH environment variable later. This would be done so CMake Tools would be able to use it. -
GCC ARM Toolchain (https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads/9-2019-q4-major)
As we did with Ninja, unpack the zip into some directory (for ex. C:/playdate_dev/arm_toolchain) and note the path. We will save the path in a new environment variable later. -
Playdate SDK
If you haven’t already unpacked this, go on and do it! Be sure to note the path where “bin” is a child directory. Again, this will be going into its own environment variable. -
Addtional Helper Files vscode_helpers_v2.zip (3.8 KB)
This zip holds a template workspace folder called “c_template”, which is already setup to be working with VSCode when your environment is setup properly. There is also the “arm_patched.cmake” file, place that in (Playdate SDK)/C_API/buildsupport. This essentially defines our toolchain to cmake.
Once CMake, Visual Studio Code + Extensions are setup and everything is unpacked to where they’re supposed to be, we need to setup an environment with which that would allow our setup to work. I’m using environment variables for this, and you can set these up however you like, as long as they’ll be defined in an environment that VS Code executes in. You can set it up under your user’s environment variable or setup some command prompt shell that has the environment variables setup for that shell window (you can open a workspace folder in VS Code from prompt via “vscode .”).
- PATH: For the PATH environment variable, you need to add the path to wherever Ninja was unpacked.
- PLAYDATE_SDK: This will be a new one, the path define should point to your SDK directory where bin is a child directory.
- PLAYDATE_ARM_GCC: Another new environment variable, this time the path defined to where you’ve unpacked the ARM GCC toolchain.
Don’t forget to escape your back slashes (or use forward slashes) in your paths!! Once that’s done, make a copy of the “c_template” folder and rename it to whatever you’d like. After that, we open VS Code with that copied folder as our workspace. Again, when we open VS Code, it has to have the environment variables setup as above.
Once VS Code opens up, the cmake-tools extension will detect the CMakeLists.txt file, and will ask if you want to configure it. Hit “Yes”, and at the top a drop down will open. This is where we select our kit, meaning our tool chain. You should see at least one available called “Playdate Device”, select that.
After the kit has been selected, cmake-tools will invoke CMake to configure the project for us. If everything is working, there should be no errors in the output window (this is a warning popup from VS Code itself but it seems safe to ignore). All we need to do now is to try a build; F7 is a shortcut for CMake Build but it is a task you can run under the command palette using Ctrl+Shift+P. There are also CMake Clean/Rebuild/Configure/etc tasks under the command palette. Anyways, the build should finish pretty quickly and show no errors if everything is setup properly. You should now see a “c_template.pdx” folder in the workspace directory! You can install this using pdutil.exe, via pdutil install c_template.pdx
. This could be a task but I’ve been using VS Code as long as I’ve been hammering it to work for Playdate
After all that is said and done, run the CMake Clean task (again, Ctrl+Shift+P and start typing cmake clean and the task should pop up) and open up CMakeLists.txt and change the project name to something other than c_template. Your first C project for Playdate is now setup!
You’d guys be the first ones aside from myself using this, so I’ll try to stick around for questions.
EDIT: updated zip with a fixed arm_patched.cmake file and attached a task to the build hotkey (Ctrl+Shift+B, remember actual Build is on F7!) that will deploy and run the package on the Playdate. For this to work, the workspace folder must be named the same as your project name in CMakeLists.txt