Dev Environment – Windows

What we will try to accomplish

We will walk step by step through setting up your Windows machine to have a development environment similar to the one I use.

For windows, we will be leaning heavily on WSL (Windows Subsystem for Linux) as it is much much easier to get the toolchain setup that way than attempting to compile everything natively in Windows. As such the instructions past a certain point are very similar to the linux ones.

What are we installing, actually?

  • WSL
  • Ubuntu 20.04 for WSL (the rest is inside WSL unless specified)
  • basic build tools
  • Lua 5.1
  • LuaRocks
  • Luaformatter
  • Visual Studio Code (native and WSL)
  • Docker
  • muddler

Let’s get started!

I recommend doing this while your OS is up to date, though it isn’t required necessarily it’s just a good idea generally speaking. I will reuse screenshots from the Linux install instructions where they apply to both, in part because it’s essentially the same and in part because I forgot to get them while setting it up on my windows boot partition.

Install WSL

I am not going to detail how to install WSL for your windows machine here, rather I will link you to the official instructions from Microsoft. I recommend you install WSL2 if you can, but if you do not have the proper KVM/SVM cpu support then WSL1 is your only option. The only thing WSL1 changes is the docker and muddler installs at the end, and I will highlight those differences then.

So, follow the instructions at THIS LINK and preferably go for the full WSL 2 install. I would get the Ubuntu 20.04 image.

Build tools and dependencies

From here the instructions very closely mirror the Linux dev environment, but I will repeat them here with the minor differences. You will want to open the Ubuntu 20.04 terminal by going to Start->Ubuntu 20.04 LTS or opening it in Windows Terminal if you installed that.

# Make sure you have the latest package information
sudo apt-get update
# Install dependencies. Up to cmake are for luarocks/luaformatter. After that will be needed by docker's install later. Unzip was not needed for linux but is in wsl
sudo apt-get install build-essential gcc git libreadline-dev lua5.1 liblua5.1-0-dev unzip cmake apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Installing system dependencies (pic from linux instructions)

LuaRocks

We will install from LuaRocks itself and not the system, as the system version is too old for our purposes.

*Note: when I wrote this, 3.5.0 was latest. I’ve bumped it to 3.9.0 to deal with GitHub turning off the git:// protocol on their servers, which causes LuaFormatter not to install.

cd ~ # move to the homedir.
# the wget is to download the archive file
wget https://luarocks.github.io/luarocks/releases/luarocks-3.9.0.tar.gz
# this extracts the file into its directory
tar zxvf luarocks-3.9.0.tar.gz
# Then we move into the directory
cd luarocks-3.9.0
# The provided configure script will determine where all the pieces luarock needs to build are kept on your system
./configure
download
extract and configure
# now we build
make
# and install it
sudo make install
build luarocks
install luarocks

You will now need to edit your .bashrc file. If you are using a shell other than bash, this filename will be different, use the file appropriate to your shell. Add the following line to the end of the file, save, and quit.

PATH=$PATH:/usr/local/bin:$HOME/luarocks-3.5.0/lua_modules/bin

LuaFormatter

Open a new terminal to pick up the pathing change above, and then run the following to download and install LuaFormatter

sudo luarocks install --server=https://luarocks.org/dev luaformatter

It will take a moment or two while it goes through everything. Don’t worry about any warnings it shows during the build, it’s not a problem unless it’s an error. The pictures below show the process in bare metal Ubuntu 20.04

I recommend downloading and using my .luaformatter file with the commands below, but you can obviously tune it to your own liking.

cd $HOME
wget https://raw.githubusercontent.com/demonnic/MDK/master/.luaformatter
getting .luaformatter file

VSCode

You can download VSCode from https://code.visualstudio.com/Download and do the basic install. Then open VSCode and install the wsl remote extension

first open
installed WSL remote extension

You will then want to open VSCode from within WSL by opening the WSL terminal and typing “code .”

Then we want to install the Lua language server.

install lua language server (note it says ‘install in WSL…’)

Then install the koihik.vscode-lua-format (picture not shown, same as above though.)

To make it use the optional .luaformatter file you downloaded earlier, you should hit ctrl+shift+p and type ‘settings’, then selecting ‘Preferences: Open Remote Settings (WSL: <your image>)’ as this opens the settings for inside your WSL setup. You’ll want to do this for all preferences except for things like your color themes, which get installed on the Windows side.

WSL remote settings

You want to add the following line to it at the top, just below the first {, with <user> replaced by your username.

"vscode-lua-format.configPath": "/home/<user>/.luaformatter",

The order of the entries doesn’t really matter, but this way it should definitely be in the right place.

Docker

If you were only able to install WSL1, you can skip this section as Docker only works in WSL2.

First, we add the GPG key for their repo and the repo itself to our sources.

# Download and install the GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# add Docker repository to repository list
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# update package information
sudo apt-get update

And then we install docker itself, setup the docker group if necessary, and add ourselves to it

# install docker
sudo apt-get install docker-ce docker-ce-cli containerd.io
# add docker group - this failed for me because the group
# already existed, but it doesn't hurt to run it if the group
# already exists, so I included it.
sudo groupadd docker
# and add yourself to it
sudo usermod -aG docker $USER

You can verify it’s working by running their hello world image. You may need to use a new WSL terminal so it sees your new group membership.

docker run hello-world
docker’s hello-world (from the linux instructions)

There are some reports that the service may not start, so if the docker run command asks if the daemon is running, try “sudo service docker start” and then try the docker run again.

If this still doesn’t work, I have had someone tell me they were able to succeed by installing Docker Desktop for windows and enabling the WSL2 options in there. And if that still fails, you can follow the java instructions below.

Muddler

With Docker

If you did the WSL2 install with docker, then this becomes quite simple really.

# pull the image
docker pull demonnic/muddler
# get the convenience wrapper (this step optional but recommended)
wget https://raw.githubusercontent.com/demonnic/muddler/master/muddle
chmod +x muddle
sudo mv muddle /usr/local/bin

To upgrage, you can just run “docker pull demonnic/muddler” again.

Without Docker

If you were only able to install WSL1, then you’ll need to install java8 and download the muddler distribution yourself. It’s still not difficult though.

# update the repo info
sudo apt-get update
# install java jre 8
sudo apt-get install openjdk-8-jre
installing jre-8 in WSL

And now we download muddler itself. At the time of writing 0.8 is the latest version, but you should check https://github.com/demonnic/muddler/releases for the latest version and replace the 0.8 with the current latest version

cd $HOME
wget https://github.com/demonnic/muddler/releases/download/0.8/muddle-shadow-0.8.tar
tar xvf muddle-shadow-0.8.tar
# next line only necessary if you are upgrading muddler. If it says no such file directory this is ok.
rm muddler
ln -s muddle-shadow-0.8 muddler

And then add the following line to the end of your .bashrc file (or appropriate file for your shell)

PATH=$PATH:$HOME/muddler/bin

Now you can open a new terminal and use muddler by simply typing ‘muddle’

To upgrade, just follow the instructions above again, replacing 0.8 with the new version you’re downloading. You can clean up the old directory using ‘rm -rf muddle-shadow-0.8’ or whatever version you’re moving from, but they’re only ~20m each so this is entirely optional and you’re unlikely to fill your hdd up with muddler versions.

Fin

Congratulations, you’ve got the basic setup done! As with the Linux setup, if you want to improve your experience even more you should look into adding Delwing’s Mudlet Docs to VSCode, and you may also get some use out of the snippets for VSCode HERE. You will want to open VSCode from the WSL terminal to ensure the remote WSL extension is used, at least the first time for any given directory. It claims it will remember this decision in future but I have not tested this myself in all honesty. I would run muddler from within the VSCode terminal, which can be accessed using ctrl+` , as this will ensure it is being run in WSL.