Procedural Generation in Rust Part 1: Setting up your Environment

So here I decided to create a program that creates a 3d map for a roguelike. Procedural generation, according to wikipedia, “is generating content algorithmically rather than manually”, which is great right? Less work for me in the long run! I’m also going to build this map creator on Windows because I’m curious about the state of Rust for Windows. When I first started using Rust Windows was an orphan child but Mozilla claims that Windows will be a first class system once they hit 1.0 so if it’s unusable we’ll switch to a Linux build.

First’s things first, I have to set up Rust for Windows. This process is considerable more involved than a Linux install which is a simple curl | sh command. First we download the compiler itself, simple enough. Since Windows is a fairly uniform system I just download the nightly build binaries from the main website. It even automatically adds it to your Path variable for you. Awesome, we’re done with the compiler already.

EDIT: reddit user /u/Quxxy informed me that you do not need to run install.sh, the binaries come pre-compiled so feel free to skip the next two paragraphs. I’ll keep them here because it’s what I did but it is a good time saver if you just want to get started with Rust.

Next up is Rust’s package/dependency manager. It’s called Cargo and I would not recommend a big project in Rust without it. Now last time I tried this Cargo was not avaliable to windows so let’s hope it’s made available and usable now. I go to the cargo website, click the download link and I see a Windows option! A quick download reveals that it’s a tar.gz file and not a .exe or .msi so that usually means some work. After some googling I found this page which says “Note that if you’re using the windows snapshot you will need Mingw-w64 installed as well as MSYS. The installation script needs to be run inside the MSYS shell,”. I happen to have MSYS installed on my system but if you do not than you can google it, it’s pretty involved and I’m not going to cover it here.

Now you unzip the Cargo tar.gz file into the home/YourUserName in the MSYS root folder so you can access it from your MSYS console. Open up the MSYS console and type “cd cargo*” then “./install.sh” and your console should look like this. Notice the “Cargo is ready to roll” if you see that you’re good to go. If you want to change the location of the cargo folder you should do that now.Screenshot 2014-11-24 09.46.49

Next step is to add cargo to your path variable, the Rust compiler took care of this automatically for us but for cargo we have to do it ourselves. Go to where you put your cargo folder and in there you’ll find a folder called bin, enter it and it should have Cargo.exe in there. Copy and paste the path in the address bar, as you can see mine is E:\Dev\cargo\bin but yours is probably different.Screenshot 2014-11-24 09.52.47

Open up the start menu and right click “Computer” and go into properties. On the left there’s 4 options, we need “Advanced system settings” and on the bottom of that windows click “Environment Variables”. Now you’ll see two tables right? The top one is your personal user variables and the bottom on is system wide, if you share the PC you’re on than use your personal one but if you do not share than you can set both to be safe. look for path in the tables you’re going to set and click edit. See all that stuff? You don’t have to worry about any of it, great huh?  All you have to do is go all the way to the end of the text and add a semi-colon (IT IS VERY IMPORTANT TO ADD THE SEMI-COLON). Remember the window with cargo in it? well now’s the time to copy and paste that path at the end of the path text. We’re done installing!Screenshot 2014-11-24 14.45.11

Now I personally use Windows Powershell because I hate it when my compiler feedback wraps on the console and the default command prompt is really bad when it comes to that. You can see the difference below and decide for yourself if you want to go searching for that. Either way enter into your prompt “rustc -v” and “cargo -V” if they both come up with versions than you did it! Congrats you now have a fully functional Rust compilation pipeline!

Comparison

In the next post we’ll talk about actually coding stuff!