GNAT Community Editionの後継

A New Era For Ada/SPARK Open Source Community | The AdaCore Blog によりますと、 GNAT Community Edition は2021年版で終了のようで、代わりに Alire というパッケージマネージャに移行していくようです。

正直に申しましてこの手の処理系ごとにパッケージマネージャを再発明する流行どうにかならないかな……と思っているのですが、まあそれはそれとしまして。

Adaフロントエンド込みのgccを用意しようとするときGNAT Community Editionは貴重なビルド済みバイナリでした。 Linuxですとほぼ全てのディストリビューションのパッケージとして用意されていますのでバージョンを気にしないなら苦労はありませんが、macOSとWindowsではそもそも動作するバイナリをどこから持ってくるかという問題があります。 Linuxでもバージョンを気にするならば問題となります。 gccをAdaフロントエンド込みでビルドするにも同じかひとつ前のバージョンのgccをAdaフロントエンド込みで必要としますのでブートストラップのためには特定のバージョンのバイナリを用意できないといけません。

他の選択肢としましては、macOSではSimon Wrightさんが野良ビルドを配布してくださっています。 (私もこっそりと……)。 Windowsでは MSYS2Cygwin があります。 でも開発元が配布しているGNAT Community Editionの方が安心ですよね。

というわけでAlireを用いてビルド済みコンパイラを取ってくる方法をメモしておきます。

Alireのインストール

githubにビルド済みバイナリが置かれていますので、適当に展開してPATHを通すだけです。 現在のところ実行ファイルひとつで動作するようです。

gccとgprbuildのインストール

alr toolchain --select を実行しますとgnat_nativeとgprbuildのそれぞれについてどのバージョンを使用するか尋ねられますので、それぞれ選ぶだけでダウンロードと展開を行ってくれます。 1が最新版っぽいです。 コンパイラはアーキテクチャ指定版ではなくgnat_nativeを選びます。

% alr toolchain --select
Welcome to the toolchain selection assistant

In this assistant you can set up the default toolchain to be used with any crate
that does not specify its own top-level dependency on a version of gnat or
gprbuild.

If you choose "None", Alire will use whatever version is found in the
environment.

ⓘ gnat is currently not configured. (alr will use the version found in the environment.)

Please select the gnat version for use with this configuration
  1. gnat_native=11.2.4
  2. None
  3. gnat_arm_elf=11.2.4
  4. gnat_avr_elf=11.2.4
  5. gnat_riscv64_elf=11.2.4
  6. gnat_arm_elf=11.2.3
  7. gnat_native=11.2.3
  8. gnat_riscv64_elf=11.2.3
  9. gnat_arm_elf=11.2.2
  0. gnat_native=11.2.2
  a. (See more choices...)
Enter your choice index (first is default):
> 1 Selected tool version gnat_native=11.2.4

ⓘ Choices for the following tool are narrowed down to releases compatible with just selected gnat_native=11.2.4

ⓘ gprbuild is currently not configured. (alr will use the version found in the environment.)

Please select the gprbuild version for use with this configuration
  1. gprbuild=22.0.1
  2. None
  3. gprbuild=21.0.2
  4. gprbuild=21.0.1
Enter your choice index (first is default):
> 1 Selected tool version gprbuild=22.0.1
ⓘ Deploying gprbuild=22.0.1...
######################################################################### 100.0% gprbuild=22.0.1 installed successfully.
ⓘ Deploying gnat_native=11.2.4...
######################################################################### 100.0% gnat_native=11.2.4 installed successfully.

sparkのインストール

GNAT Community Editionには静的検証を行うspark(gnatproveコマンド)も付いてきていましたのでこれもインストールしたくなるかもしれません。 ツールチェインであれば alr toolchain コマンドでインストールできるのですがgnatproveはツールチェイン扱いではないようですので適当なAlire管理下のプロジェクトのディレクトリの中で依存関係としてインストールする必要があるようです。

gnatproveをインストールしたいだけですので作業用のAlireプロジェクトはなんでもいいのですけれども、チュートリアルにもあるHello Worldを使いましょうか。 alr get hello で取ってこれます。

後は中に cd して alr with gnatprove でインストールできます。

% cd /tmp
% alr get hello

ⓘ Deploying hello=1.0.1...
######################################################################### 100.0% Deploying libhello=1.0.0...
######################################################################### 100.0%

hello=1.0.1 successfully retrieved.
Dependencies were solved as follows:

   + libhello 1.0.0 (new)

% cd hello_1.0.1_dcc36a2f
% alr with gnatprove

Requested changes:

    gnatprove ^11.2.3 (add)

Changes to dependency solution:

   +♼ gnatprove 11.2.3 (new,installed)

Do you want to proceed?
[Y] Yes  [N] No  (default is Yes) Y
ⓘ Deploying gnatprove=11.2.3...
######################################################################### 100.0% gnatprove=11.2.3 installed successfully.

インストール先ディレクトリ

こうしてインストールしたgnat_native、gprbuild、gnatproveはAlireの外からでも使える形でインストールされています。 $HOME/.config/alire/cache/dependencies の中になります。 ディレクトリは cache という名前ですが所謂HTTPキャッシュではなく展開済みです。

% ls ~/.config/alire/cache/dependencies/
gnat_native_11.2.4_2f37a10b  gprbuild_22.0.1_24dfc1b5
gnatprove_11.2.3_f7ece6d3

それぞれの bin ディレクトリにPATHを通すだけです。

GNAT Studio

GNAT Community EditionにはIDEであるGNAT Studioも付いてきていました。 現在のところAlireのパッケージにはなっていないようですが、ビルド済みバイナリがgithubで配布されています

Visual Studio Code使いましょう。