Alire - Ada Library Repository

Sadly, there has been a loooong pause in my journey to learn Ada. I was kind of surprised to see that it has been already almost three years since the last post, incredible!

I think one of the major obstacle in my quest was the fact that I wasn't accustomed to look for and install all the libraries I'd need for a project, manually. I wasn't accustomed to do that, as most of the other languages I've used before have some sort of dependency management system, pip for Python, sbt for Scala etc. Call it laziness, if you will, but nowadays I'd say it's something that is kind of expected to be available. It's part of the modern on-boarding experience.

So, a while back I was lucky to find the Alire, a new project to bring just that missing piece of infrastructure to the Ada world. My motivation to learn Ada increased ten fold!

The Alire project lives in GitHub Alire (github.com) and is most actively developed by Alejandro R. Mosteo and Fabien Chouteau, who are also the most friendly and helpful fellows when some one like me pops up with their rookie questions. The Alire community has chat room in Gitter.im. Ada Programming Language/Alire - Gitter

After installing Alire, alr is the actual command which to use.

Alire as new project initiator

For a beginner, it might not be obvious how to create a new project. So Alire is the perfect solution for this too. 

alr init --bin first_project

This will ask you some questions about your project and then create a folder first_project with an initial project configuration file and the folder structure. In that folder, you can fire up alr edit which will launch GNAT Studio, if you have it installed. The --bin flag tells the compilation will be an executable, where as you could use --lib flag to tell it to be a library project.

Alire as library package/dependency manager

This is kind of the main purpose of the tool, as the name might reveal. When you have started your code project, the odds are that pretty soon you'll start to look for some utility library. The available library units are called crates. I guess this naming has been borrowed from the Rust world. You can search for the available crates through a search command:

alr search <search string>

show command will present you more details of a specific crate and list command lists all the  available crates. Pretty self explanatory and familiar from other package managers. You can see this information also from the https://alire.ada.dev/ website and there you have also very nice graphical view of the dependency structure of each crate as a network graph.

After finding your crate to be used, using it in your project is easy as:

alr with <crate name>

Alire will fetch the library source code under the project folder and you can then with it in your code. Easy!

When developing a library, I'm using such a pattern that I have a test app project inside the library project folder. It doesn't have to be inside, but I find it convenient. How to use the library you are developing, from the test app? You can add the dependency locally:

alr with --use <path_to_the_library_crate_folder>

Alire has many more commands, take a look at the website for more on those.

Alire as a distribution channel

Alire works in the source code domain, but the crates don't have to be plain libraries. Nothing really prevents you from distributing your software through it, in similar way that you can distribute scripts through pip in Python world. The user just needs to compile it first, so probably the typical target audience for that software is someone who has Ada compiler infrastructure set up...

Alire is very welcomed addition to the Ada world, in my opinion, as a complete novice. There's so much more into it, that I don't even know yet, so check it out now, if you haven't already!

Comments

Popular posts from this blog

Ada web development

First post