If you're using Windows, you can also build a go plugin using Windows Subsystem for Linux.
The Windows Subsystem for Linux lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a virtual machine.
You can read more about it here.
In this guide, we will be using the Nakama server image provided by DigitalOcean on their marketplace, but you may use the Linux binary provided by HeroicLabs and set up your own. This guide assumes you have already followed the instructions for setting up a Nakama project.
In order to proceed, you will need to have Windows Subsystem for Linux installed as well as a Linux distribution that preferably matches your Nakama installation. It is important to make sure your plugin build environment is using the same toolchain as your Nakama server installation. If your distribution doesn't have the same toolchain as your server, you will get server errors complaining of version mismatches.
TIP: For example, Alpine uses musl, and Debian/Ubuntu uses glibc. If you build a Nakama plugin on Alpine, and then try to run it on a Nakama server built with Debian/Ubuntu, it will fail miserably.
-
Install the Go toolchain on WSL. If you are using Ubuntu, you can use the package manager instead, if you prefer.
Make sure your Go version matches your server's Go version!
Usego version
if you are unsure.
The process of building the go plugin in WSL is straightfoward. They are the same steps you would follow for building on native Linux.
-
Compile the plugin on Windows using WSL. Note that you must put
wsl
in front of each command to execute it using WSL.Open a Windows terminal and type these commands.
wsl cd /mnt/c/my-plugin-project #Note that the drive letter has no symbols. This mounts WSL directly to the Windows filesystem. wsl go build --buildmode=plugin -trimpath -o modules/my-plugin-project.so #Because we are mounted to the Windows filesystem, no copying is necessary afterwards.
TIP: It's possible to automate this process entirely by putting these commands into a script.
-
Run the nakama server. Make sure the plugin is uploaded to the correct location depending on your configuration.
sudo service nakama restart #if using DigitalOcean's Nakama droplet image
OR
./nakama --runtime.path $HOME/my-plugin-project
For more information on how the server loads modules have a look at these docs. For general instructions on how to run the server give these docs a read.