Getting Started with Ada - Dockerized Programming Environment

in Programming & Dev4 years ago

I recently came across software projects built with Ada - yep, that old programming language going back to the 1980s. I never used it before, so let's give it a try! :)

Screenshot_20200419_134424.png
Screenshot: https://learn.adacore.com/courses/courses.html

With a quick search, I came across learn.adacore.com, which seems (at least at my current state of knowledge) a very valuable starting point. In order to try things out, I need an Ada development environment.

Since I don't want to clutter my system with yet another development environment, I chose to use Docker to put all in a container. This way it doesn't install any new libs/tools on my machine, I can rebuild it at any time, and I can delete the whole thing with a single command if I'm fed up with it :)

Ada uses GNAT as compiler, which is available as package in most Linux Distributions. I'm using Debian 10 here, but most others should probably do as well.

Setting up the Container

  • Save the following snippet with the name Dockerfile:
FROM debian:10-slim
RUN apt-get update
RUN apt-get install -y gnat gprbuild
  • Build the container image:
docker build -t ada .
  • Spin up an instance of the container:
docker run -v $(pwd):/data -it --name ada ada /bin/bash

This mounts the current working directory in the host to the /data directory in the container and starts a bash shell.

Hello World

  • Source file: The following example is from the "Getting Started with Ada" tutorial on learn.adacore.com. With the working directory mapped to the container, you can create this file with your favourite editor on the host. Save this as greet.adb:
with Ada.Text_IO;

procedure Greet is
begin
   --  Print "Hello, World!" to the screen
   Ada.Text_IO.Put_Line ("Hello, World!");
end Greet;
  • Compilation
root@ac8354411312:/# cd /data/
root@ac8354411312:/data# gprbuild greet.adb 
using project file /usr/share/gpr/_default.gpr
Compile
   [Ada]          greet.adb
Bind
   [gprbind]      greet.bexch
   [Ada]          greet.ali
Link
   [link]         greet.adb
  • Run it
root@ac8354411312:/data# ./greet 
Hello, World!

Ready to go for more meaningful programs, but with a clean/portable development environment :)

Anyone else using this language? Let me know in the comments!

Sort:  

Oh no, my nemisis, the evil docker. LOL. I really don't get along with docker unfortunately. Eventually when I get time I should be able to spend a bit of time making peace with the technology as it does seem useful. Regarding ADA, I've never used it, but every language has a strong point so maybe it will be useful in a future project?

Thanks for posting in the programming community and sorry for the late reply.
~ CA

Haha, yes, took me a while as well to get familiar with docker. I really learned to like it to "try things out" without cluttering my system with yet another hundred dependency packages...