Ada

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

Ada is programming language designed for large, long-lived applications — and embedded systems in particular — where safety and security are essential.

Ada is used by a number of the packages in the Gentoo ebuild repository.

Installation

The Ada community has in recent years moved towards Alire, a language-specific package manager. AdaCore discontinued GNAT Community (packaged as dev-lang/gnat-gpl) in favor of this. However, GNAT Community still has value in Gentoo for bootstrapping a newer version of GNAT in sys-devel/gcc.

Following recent changes for bug #547358, installing GCC's Ada compiler (GNAT) should be far easier.

Emerge

Remove any legacy PATH hacks or configuration in /etc/portage/make.conf set from previous attempts to install/use GNAT.

First, enable ada for sys-devel/gcc:

FILE /etc/portage/package.use
sys-devel/gcc ada

Then rebuild GCC:

root #emerge --ask --oneshot --changed-use sys-devel/gcc

Alire setup

Alire can be used without installing the toolchain locally. If the external toolchain from Gentoo's repositories should be used gcc as to be recompiled as mentioned above and dev-ada/gprbuild has to be emerged.

Note
Make sure setting the variable ADA_TARGET according to Project:Ada.
Tip
If a project should be built without Alire or gprbuild only gcc, gnatbind and gnatlink can be used. gnatmake executes all three of them over the project. This is described at GNAT User's Guide for Native Platforms.

Emacs setup

As at 2024-03-13, ada-mode is effectively unmaintained, due to the primary developer having retired.[1]

A maintained alternative for users of Emacs 29 and above is ada-ts-mode, which uses Tree-sitter and the Language Server Protocol (LSP). Simon Wright has written a guide to setting up ada-ts-mode.

Otherwise, to set up ada-mode:

Install ada-mode via Alire; download and install the current Linux version of Alire if necessary.

If use of Alire is not possible for some reason, ensure dev-ada/gnatcoll-core is installed:

root #emerge --ask dev-ada/gnatcoll-core

Install the latest version of ada-mode, using your preferred method of managing Emacs packages. An app-emacs/ada-mode::gnu-elpa package is available via the gnu-elpa overlay.

On the command line, change to the directory in which ada-mode has been installed, e.g.:

user $cd ~/.config/emacs/elpa/ada-mode-8.1.0/

and then run:

user $./build.sh # This can be memory-intensive!

If the Alire alr binary is installed and configured correctly, it will be used for the build-and-install process. Otherwise, the install.sh will need to be run:

user $./install.sh

By default, files are installed into ${HOME}/.local/bin/, as the appropriate XDG directory. To specify a different location for the bin directory, pass it as the first argument to install.sh.

If not using Alire, version 8.1.0 of ada-mode requires copying the file ada_annex_p_lr1_re2c_parse_table.txt from the top level of the ada-mode-8.1.0 directory to the relevant installation location.

Add the installation location to the PATH, e.g. via .bash_profile:

FILE ~/.bash_profile
export PATH="${PATH}:${HOME}/.local/bin"

and restart the login session.

Depending on the installation method, ada-mode might need to be enabled manually in the Emacs configuration file:

FILE ~/.config/emacs/init.el
(require 'ada-mode)

By default, wisi is used for things like faces (ada-face-backend) and indentation (ada-indent-backend); however, the AdaCore ada_language_server (als) can be used for cross-references, via eglot. Refer to the ada customize-group and the ada-mode home page for further information.

Troubleshooting

can't find a native toolchain for language 'ada'

Depending on the language configuration Alire does find the external toolchain with alr toolchain --select, but gprbuild that is used under the hood, does not. That is because gprbuild depends on gprconfig to detect suitable compilers[2]. gprconfig uses regular expressions stored in /usr/share/gprconfig/compilers.xml to detect the toolchain. For ADA_TARGET=gcc_14 that would be, among others, the GNAT-section.

The relevant regular expressions are

  • gcc_version = ^[-\w]*gcc \S+ (\S+)
  • gcc_version_major = ^[-\w]*gcc \S+ (\d+)\.\d+\.\d+

that are matched on the output of gcc-14 -v.

user $gcc-14 -v

On the last line the gcc version is printed: gcc version 14.2.1 20241221 (Gentoo 14.2.1_p20241221 p7). gprconfig will scan that with the regular expressions and it will work fine. But image you are on a german system (LANG=de_DE gcc -v). In that case you will get gcc-Version 14.2.1 20241221 (Gentoo 14.2.1_p20241221 p7) and the regular expressions does not work anymore.

In fact that is a known issue on their issue tracker[3].

As a workaround the regular expression can be patched like this:

root #sed -i 's/gcc \\S/gcc[- ]\\S/g' /usr/share/gprconfig/compilers.xml

External resources

Learning and reference

Advanced examples

Groups

References