stmdev avatar

Getting Started with Ada - Dockerized Programming Environment

stmdev

Published: 19 Apr 2020 › Updated: 19 Apr 2020Getting Started with Ada - Dockerized Programming Environment

Getting Started with Ada - Dockerized Programming Environment

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!

Leave Getting Started with Ada - Dockerized Programming Environment to:

Written by

Read more #ada posts


Best Posts From stmdev

We have not curated any of stmdev's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From stmdev