Skip to content

Working on Switch

Luiz Pestana edited this page Feb 17, 2024 · 8 revisions

To build your raylib game for Switch you need to have a fully devkitPro/devkitA64 working environment and download raylib git repository (or get the current release from here).

DevkitPro/devkitA64 Setup

There are two options to get the devkit environment:

  • You can install the devkit in your OS using this guide here.
  • I highly recommend you to use the devkit docker image which will require you to setup docker using this guide here.

Running devkit docker image

If you chose to setup the devkit in your OS, you can skip this part.

Having docker service running in your machine, to get a fully devkit environment, you just need to run the command:

Linux:

docker run -it --rm --entrypoint /bin/bash --name=switchdev --volume=/home:/home devkitpro/devkita64

OSX:

docker run -it --rm --entrypoint /bin/bash --name=switchdev --volume=/Users:/home devkitpro/devkita64

Windows

docker run -it --rm --entrypoint /bin/bash --name=switchdev --volume=/c/Users:/home devkitpro/devkita64

If you need another window, you can run the command:

docker exec -it -t switchdev /bin/bash

Any file in your home directory can be accessed in /home inside the docker machine.

Compiling raylib source code

Git clone this repository in your home directory, using your OS or inside the docker (it includes the git), so in docker it can be accessed by the path /home/[username]/raylib-nx.

Just navigate to raylib-nx/src directory and run:

make PLATFORM=PLATFORM_NX

Compiling raylib examples

Just move to folder raylib-nx/examples and run:

make PLATFORM=PLATFORM_NX

Alternatively you can now compile raylib and examples using Cmake:

On the raylib-nx root folder:

/opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -DPLATFORM=NX -DCMAKE_BUILD_TYPE=Release -S . -B cmake-build-switch
cmake --build cmake-build-switch

You can add the parameter -DBUILD_EXAMPLES=OFF to build only the library.

Running raylib examples

You can use the Switch emulator, not all features are implemented but it can be useful to fast test your code, download it here and open the nro generated file.

To run your app on the Switch, you need the Atmosphere CFW and then all your nro generated files and resources must be saved on the /switch folder of your SD card.

Creating your switch project

You can find a switch template for raylib here, its using the dekvitPro makefile with raylib required changes. Just run make to create the nro file.

Debugging via USB

Debugging Switch homebrews is not an easy task, so we have a flag that activates output over USB. You need to compile raylib activating the flag NX_USB_DEBUGGER. Then any applications compiled using this raylib build will wait for an USB connection to run.

Linux/OSX:

Connect your Switch over USB and then run this command (in your machine, not docker) to configure the raylib USB as a serial port (we need to run it again after restarting the OS):

sudo modprobe usbserial vendor=0x057e product=0x4000

Then after running a raylib app, we can watch the output running:

sudo cat /dev/ttyUSB0

Windows:

Connect your Switch over USB and you can use PuTTy to read the COM port.