How to install Pony on windows 10 using WSL 2

September 26, 2021 MrAnyx 6 min de lecture

Pony is a very young language compared to other pioneers like C/C++ or Python.

Its creation started in 2012 with a guy called Sylvan Clebsch but its popularity began to rise in 2017.

In general terms, Pony is an object oriented programming language which means that you can create classes, interfaces, traits, ...

But the main difference that Pony has, is that it also an Actor/Model oriented programming language. Actors are objects that look like classes except that their behaviours are asynchronous.

In other words, if you call the behaviour foo before another behaviour called bar, in some cases, depending on the body of these behaviours, bar can return a result before foo.

Well, we've talked enough about the technique. In this article, we'll learn how to install Pony on windows 10 using WSL 2.

Prerequisites

Well, in order to install Pony on Windows 10 using WSL 2, you will need to have an up and running WSL distro. If it is not the case, I recommend you to check this post : Enable Linux subsystem on Windows 10

I will show you how to enable WSL on Windows 10 and to install a linux distribution.

Once it's done, launch the distribution you've just installed and go to the next step.

Install the Pony toolchain multiplexer

Also known as Ponyup, this tool will help you install the compiler, perform updates, ... Without it, you won't be able to install anything.

Installing ponyup is very simple. The official Ponyup repository provides a command to automatically download the installation script.

sh -c "$(curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/ponylang/ponyup/latest-release/ponyup-init.sh)"

This command will automatically download the latest ponyup version and install it.

At the end of the installation, it should prompt something like this.

ponyup placed in /home/user/.local/share/ponyup/bin
You should add /home/user/.local/share/ponyup/bin to $PATH:
export PATH=/home/user/.local/share/ponyup/bin:$PATH
setting default platform to x86_64-unknown-linux-gnu

Indeed, the ponyup command is, for the moment, not accessible globally. So, i order to be able to compile file wherever we want, we need to make it executable globally.

Make it executable globally

There are 2 ways to make the ponyup script executable globally :

  • By updating the $PATH global variable,
  • By creating a symbolic link in the /usr/bin folder.

They are both equivalent, so you can choose either the first or the second option.

Update the $PATH global variable

The command below will simply update the $PATH global variable.

export PATH=/home/user/.local/share/ponyup/bin:$PATH

But in order to refresh this variable, you have to either restart your terminal or execute the following command. It will manually refresh the $PATH variable.

source ~/.bashrc

But for some reason, after updating the $PATH variable, I wasn't able to access the ponyup scriptp globally. That's why I recommend you to choose the option below.

Create a symbolic link

As we've seen earlier, the ponyup script has been installed in the ~/.local/share/ponyup/bin folder.

We'll create a symbolic link between ~/.local/share/ponyup/bin/ponyup and /usr/bin/ponyup. This link will act as a bridge between these 2 files.

sudo ln -s /home/user/.local/share/ponyup/bin/ponyup /usr/bin/ponyup

By calling the ponyup script from the /usr/bin folder, it will call the ponyup script from the original folder which is ~/.local/share/ponyup/bin.

Now, if you execute the following command, you should have a result.

ponyup --help

Set default platform

The next step is to define the default platform. It will depend on the linux distribution you've chosen. In my case, because i'm running on Ubuntu 20.04, i'll need to choose : ubuntu20.04.

ponyup default ubuntu20.04

You can choose between multiple platform. For more details, you can check the official documentation.

As mentionned in the documentation, if you can't find your platform in the list in the official documentation, you can skip this part.

Install a C compiler

This step is crutial. Because Pony in built using C, you need to install a C compiler such as Clang. This is the one recommended by the official docimentation.

To install the Clang library, you can just call the apt install command.

sudo apt install clang

On other distributions such as Fedora or CentOS, the command might change.
On Fedora : sudo dnf install clang
On CentOS : sudo yum install clang

For distribution other than Debian based, you need to install additional libraries. Here is the list of additional requirements provided by the official documentation

Install the latest ponyc release

The last step to have an up and running Pony environment is to install the Pony compiler, also know as ponyc.

ponyup update ponyc release

As fr the ponyup script, you'll need to make it executable globally. In the same way, you can update the $PATH variable but I recommend you to create a symbolic link with the command below.

sudo ln -s /home/user/.local/share/ponyup/bin/ponyc /usr/bin/ponyc

Usage

Now, everything should be good to use the Pony language. Let's try it out.

In the WSL terminal, will create a very simple Pony project.

cd
mkdir helloworld && cd helloworld
touch main.pony

It is important to note that the file name is not important. At least, it needs to end with the .pony extension.

Then, we will modify this file.

nano main.pony

You can type anything you want but for the purpose of this article, we will only copy and paste the code example provided by the official Pony tutorial website.

actor Main
  new create(env: Env) =>
    env.out.print("Hello, world!")

To save the file and exit, you can press ctrl+s and ctrl+x.

Now, you can compile the file we've just created.

ponyc -o bin

The -o flag means that i want to specify the output folder. In this case, every files created by this command will be located in /bin or your project folder.

To run it, just type :

./bin/helloworld

You should come up with something like this :

Hello, world!

Conclusion

The Pony language is very promising. It aim to be as fast as other languages like C or C++. It is also type safe, memory safe, exception safe, ...

It is also an Actor/Model language like Erlang.

The next step is to create a development environment where you can easily edit and compile your code. We'll cover this part in another post later on.

Cover by Soledad Lorieto


Cette œuvre est mise à disposition selon les termes de la licence Licence Creative Commons