Chapter 2 - Getting Set Up

The first thing to do with any programming environment is to install it and verify that it is working. So let’s do that now.


Supported Platforms

At the time of writing Volta, Volt’s compiler, has support for the following platforms:

The source code is all available, so the absence of a platform is certainly no indication that it does not or will not work, only that Volta is not supported or tested there by the core maintainers. Pull requests welcome.


Volta depends on dmd, llvm, and the NASM. We’ll also want git to fetch the code. The next sections will detail how to install these for each platform.

Linux Dependency Installation

If you are on Ubuntu or a derivative,

sudo apt-get install dmd llvm nasm git

will install what you need. If you’re on Arch Linux,

sudo pacman -S dmd llvm nasm git

will do it. Otherwise consult your OS documentation on how to install these packages.

OS X Dependency Installation

The easiest way of installing DMD on OS X is using Homebrew. With brew installed,

brew install dmd nasm

If you prefer not to use Homebrew, then download DMD from here, then just extract the contents of the dmd zip and set the DMD environmental variable to be /osx/bin/dmd or put the folder /osx/bin on the $PATH.

Volt needs LLVM version 3.9, brew install llvm should be up to date enough.

If it isn’t for some reason, you can try brew install homebrew/versions/llvm39, then add /usr/local/Cellar/llvm39/3.9.X/lib/llvm-3.9X/bin on your $PATH (replacing the Xs with the real version). The reason for doing so is, that Homebrew doesn’t properly link non-core-only versions - like LLVM v3.9? if it comes from homebrew/versions/llvm39. For example, llvm-config won’t be present, but only llvm-config-3.9.

If you’re not using Homebrew, download LLVM from the LLVM homepage, and put the bin folder inside the unpacked tarball on the $PATH.

You’ll also need to install git.

Windows Dependency Installation

Install DMD.

Install Microsoft Visual Studio Community, for free. Microsoft has a habit of changing URLs monthly, so you’ll have to click around for the download page. We believe in you!

Install Cmake. and use it to compile the LLVM source code. LLVM have more detailed documentation on how to do this. Be sure to compile in ‘Release’ mode; ‘Debug’ LLVM builds have a tendency to crash on Windows. Also compile with LLVM_BUILD_LLVM_C_DYLIB set to ON (LLVM 8 and up). Yes, DYLIB. It compiles a DLL on windows, don’t worry. Be sure to compile clang, too. Compiling LLVM and Clang might sound a bit scary, and this is something that we’re actively working towards removing from the process (we added the LLVM_BUILD_LLVM_C_DYLIB flag and script for Windows, and we’re going to try to ensure that it’ll be included with newer LLVM binary distributions, for example). But for now, this is what needs to be done. Building LLVM and Clang with Visual Studio is actually quite simple, as they don’t need much more than a C++ compiler and a Python 2.6 install.

Install NASM.. Ensure that it is available on your %PATH%.

Finally, download and install git. Make sure it’s on your %PATH%.

Getting Battery

Download Battery, Volt’s build tool. Make sure it’s on your PATH.

Getting The code

Now that the dependencies have been installed, let’s set up a place to build Volta and the tools it needs. For simplicity, this tutorial will assume this location is directly in your $HOME directory/User folder, but you can place it where you want.

mkdir volt
cd volt

Next, let’s get the code for Volta (the compiler), and Watt (the standard library).

git clone
git clone

Additional Windows Setup

At the moment, there are a few extra steps needed on Windows. As mentioned before, we’re working to make these go away in the future.

On the unix-like platforms, we call llvm-conf to figure out what version of LLVM we’re running (no need to get into details, but for various reasons Volta needs to know the version to work properly and to provide the most features). llvm-conf isn’t a thing on Windows, so we have to give the LLVM version explicitly.

To figure out the version of LLVM you’re using, pass the version you get from running clang --version with the clang you want to use with Volta. The version will be a number with three sections, separated by dots, like 3.8.0, or 7.0.0, immediately after the output clang version.

Then, in the cloned Volta directory, next to the battery.toml file, open your text editor and create a new file named llvm.toml. And fill it in with:

llvmVersion="X.Y.Z"  # This is the version you just got from clang --version.

Filling in the details as appropriate. For example, at the time of writing my llvm.toml is as follows:


Then, open battery.toml and at the bottom, if there isn’t one already, add a [platform.msvc] section and add the path to your LLVM-C.lib file.

libraries = ["D:/Path/To/LLVM-C.lib"]  # Replace this path!

Then, so long as the LLVM-C.DLL that you built is in your PATH somewhere, you should be good to go!

Hello World!

The Program

Create a new folder, hello. In this folder would go all the code and tests that make up the project. All we want to do is print a message to the screen.

Save this code into a file called main.volt, and put that in a src folder inside the hello folder.


fn main() i32
	writeln("hello, world");
	return 0;

Then save the following in the root of the folder in a file called battery.txt.


For more information on Battery, check out its documentation.

Compiling and Running

First, configure the build.

battery config /path/to/Volta /path/to/Watt .

Then, to build the hello executable,

battery build

If an error is produced, make sure your code matches what’s written above exactly. Otherwise, run ./hello (on Linux and OS X) or hello.exe (on Windows) to run your new program! The message hello, world should be printed onto the screen. If it worked, everything seems to be setup correctly. On to the next chapter! If you’re still confused, keep reading.

Finding Help

In programming, as in life, things often don’t work how you’d expect. Before you ask for help make sure you’ve tried to solve your problem on your own; problem solving is an important part of writing programs. But if you’re truly stumped, the best place to ask for help is on the #volt IRC chat channel, hosted on Freenode. You can connect with a desktop client, or follow that link to use Freenode’s own web client.