用 Alire 開始 Ada 專案 ── 從建立專案、加入相依、建置設定檔到 GNATprove

· · Ada, Alire, GNAT, SPARK, GNATprove, 套件管理器, 建置

分享到 X 分享到 LINE 分享到 Facebook
更新紀錄(僅初版,2026年11月01日 發布)
初次發布

開始用 Ada 寫程式時,常會卡在要從哪裡安裝編譯器 GNAT、要如何取得函式庫。Alire 是把這兩件事一起處理的 Ada 與 SPARK 套件管理器。指令 alr 負責建立專案、取得相依的函式庫、取得 GNAT 與 GPRbuild,以及建置與執行。

本文依序說明:用 alr init 建立專案、加入相依、切換建置設定檔,直到用 GNATprove 證明。途中也會用實際輸出確認預設的建置不會檢查前置條件。

指令與輸出是 2026 年 11 月 1 日在 Ubuntu(x86-64)上,以 alr 2.1.0 及撰寫時最新的 alr 2.1.1 執行的結果。兩個版本的結果相同。較長的輸出省略了一部分。Windows 的安裝程式與 MSYS2 的步驟沒有在這個環境中試過,因此只寫 Alire 文件中記載的內容。

Ada 本身在「Ada 語言的魅力」中介紹,SPARK 與 GNATprove 則在「SPARK形式驗證入門」中介紹。

Alire 負責的事

在 Alire 中,發布與相依的單位稱為 crate。crate 的根目錄有名為 alire.toml 的資訊清單,以 TOML 格式寫入名稱、版本、相依的 crate 等1。已公開的 crate 資訊彙集在社群索引(GitHub 上的 alire-index 儲存庫),alr 會從那裡尋找相依的候選版本2。

建置使用 GPRbuild。GPRbuild 是讀取專案檔(.gpr),建置以多種語言寫成之系統的工具3。alr build 會先設定 GPR_PROJECT_PATH 等環境變數,再呼叫 GPRbuild4。

構成 Alire 的元素表示 alr 指令讀取資訊清單,從索引取得相依 crate,並取得 Alire 發布的 GNAT 與 GPRbuild,再以 GPRbuild 建置的關係。開發者alr 指令alire.toml(資訊清單)社群索引相依 crateGNAT 與 GPRbuild以 GPRbuild 建置

圖 1: alr 讀取資訊清單,取得相依 crate 與工具鏈,再以 GPRbuild 建置。

圖中實線表示始終成立的關係,虛線表示附帶條件的關係(成立條件寫在詳細頁面中各關係的說明中)。關係的完整清單(共 11 條,附依據與可信度)以及主要概念的定義,彙整在知識地圖詳細頁面(日文)。資料:JSON-LD / Turtle

安裝 alr

Windows

Windows 版在 GitHub 的發行頁面有安裝程式(2.1.1 的話是 alr-2.1.1-installer-x86_64-windows.exe)。安裝程式會建立捷徑,以把 alr 加入 PATH 的狀態開啟 PowerShell4。

第一次執行 alr 時,會詢問是否安裝 MSYS2。MSYS2 是用來建置與執行 Windows 原生軟體的工具與函式庫集合,以 Pacman 管理套件5。Alire 會從 MSYS2 安裝 git、make 等必要工具,以及部分 crate 使用的外部函式庫。因此文件建議安裝 MSYS24。如果 pacman 已經在 PATH 中,就使用那個 MSYS2,不會重新安裝4。

Linux 與 macOS

在 Linux 與 macOS 上,解壓縮封存檔,並把 bin 資料夾加入 PATH4。本文使用的是 Linux(x86-64)版的 zip。

unzip alr-2.1.1-bin-x86_64-linux.zip -d ~/alire
export PATH="$HOME/alire/bin:$PATH"
alr --version
alr 2.1.1

在 macOS 上,有時會出現無法確認開發者的警告而無法啟動。文件列出了用 xattr -d com.apple.quarantine bin/alr 移除隔離屬性的方法4。

各 OS 的 alr 安裝方式表示 Windows 使用安裝程式並在第一次執行時決定是否安裝 MSYS2,Linux 與 macOS 則解壓縮封存檔並加入 PATH 的流程。安裝 alrWindowsLinux、macOS執行安裝程式第一次執行 alr 時詢問是否安裝 MSYS2pacman 在 PATH 中就使用既有的 MSYS2解壓縮封存檔把 bin 加入 PATH

圖 2: Windows 以安裝程式與 MSYS2 安裝,Linux 與 macOS 則解壓縮封存檔安裝。

用 alr init 建立專案

建立產生執行檔的專案時,使用 alr init --bin <名稱>。函式庫則用 --lib。

alr init --bin hello_alire

執行後,首先會詢問 crate 的說明。第一次使用時,接著還會詢問名稱、GitHub 登入名稱、電子郵件地址。這些可以省略,之後也能用 alr settings 變更。之後會詢問授權、標籤、網站。GitHub 登入名稱在公開到社群索引時用來表示管理者4。

產生的檔案如下。

hello_alire/.gitignore
hello_alire/alire.toml
hello_alire/alire/alire.lock
hello_alire/alire/build_hash_inputs
hello_alire/alire/settings.toml
hello_alire/config/hello_alire_config.ads
hello_alire/config/hello_alire_config.gpr
hello_alire/config/hello_alire_config.h
hello_alire/hello_alire.gpr
hello_alire/src/hello_alire.adb

.gitignore 中寫著以下 4 行。alire 與 config 資料夾會由 Alire 重新產生,因此不放進版本控制。放進儲存庫的是 alire.toml、.gpr 檔,以及 src 底下的原始碼。

/obj/
/bin/
/alire/
/config/
alr init 產生的檔案把 alr init 產生的檔案分成放進儲存庫的檔案,以及因 Alire 會重新產生而排除的檔案。alr init 產生的檔案放進儲存庫排除(.gitignore)alire.toml 與 .gprsrc 底下的原始碼alire 與 configobj 與 bin由 Alire 重新產生

圖 3: 把 alire.toml、.gpr 與原始碼放進儲存庫,排除 Alire 產生的資料夾。

資訊清單 alire.toml 如下。因為是用 -n(不互動)建立的,名稱等項目填入了預設值。

name = "hello_alire"
description = ""
version = "0.1.0-dev"

authors = ["Your Name"]
maintainers = ["Your Name <example@example.com>"]
licenses = "MIT OR Apache-2.0 WITH LLVM-exception"
website = ""
tags = []

executables = ["hello_alire"]

專案檔 hello_alire.gpr 以 with 讀入 config/hello_alire_config.gpr,從那裡取得編譯器參數。後面說明的建置設定檔設定,也是透過這個產生的檔案傳給編譯器。

with "config/hello_alire_config.gpr";
project Hello_Alire is

   for Source_Dirs use ("src/", "config/");
   for Object_Dir use "obj/" & Hello_Alire_Config.Build_Profile;
   for Create_Missing_Dirs use "True";
   for Exec_Dir use "bin";
   for Main use ("hello_alire.adb");

   package Compiler is
      for Default_Switches ("Ada") use Hello_Alire_Config.Ada_Compiler_Switches;
   end Compiler;

   package Binder is
      for Switches ("Ada") use ("-Es"); --  Symbolic traceback
   end Binder;

   package Install is
      for Artifacts (".") use ("share");
   end Install;

end Hello_Alire;

第一次 alr build 會安裝 GNAT

在沒有任何設定的狀態下執行 alr build,Alire 先選擇並下載工具鏈,然後才建置。

Note: Alire has selected automatically this toolchain:
   gprbuild=26.0.1
   gnat_native=16.1.0
You can select a different toolchain at any time with `alr toolchain --select`
Download will start now:
Note: Deploying gprbuild=26.0.1...
Note: gprbuild=26.0.1 installed successfully.
Note: Deploying gnat_native=16.1.0...
Note: gnat_native=16.1.0 installed successfully.
Note: Building hello_alire=0.1.0-dev/hello_alire.gpr...
...
Success: Build finished successfully in 0.61 seconds.

gnat_native 是代表該平台原生編譯器的 crate 名稱6。這個環境中也有用 apt 安裝的 GNAT 13.3.0,但 Alire 選擇了自己發布的 16.1.0。選用的版本會隨當時的索引而變。

接著改寫 src/hello_alire.adb,執行 alr run。alr run 會在需要時先建置,再啟動執行檔。Hello_Alire_Config 是產生在 config 資料夾中的套件,把所選的建置設定檔保存為常數。

with Ada.Text_IO;
with Hello_Alire_Config;

procedure Hello_Alire is
begin
   Ada.Text_IO.Put_Line ("Hello from Alire");
   Ada.Text_IO.Put_Line
     ("Build profile: "
      & Hello_Alire_Config.Build_Profile_Kind'Image
          (Hello_Alire_Config.Build_Profile));
end Hello_Alire;
$ alr run
Note: Building hello_alire=0.1.0-dev/hello_alire.gpr...
...
Success: Build finished successfully in 0.59 seconds.
Hello from Alire
Build profile: DEVELOPMENT
第一次建置的流程表示第一次 alr build 時若尚未選擇工具鏈,由 Alire 選擇並下載,產生設定檔後以 GPRbuild 建置,再以 alr run 執行的流程。否是alr build已選擇工具鏈?由 Alire 選擇並下載在 config 產生設定以 GPRbuild 建置bin 中的執行檔以 alr run 執行

圖 4: 第一次建置時取得工具鏈,產生設定後以 GPRbuild 建置。

用 alr with 加入相依的 crate

索引中的 crate 可以用 alr search --crates <關鍵字> 搜尋。

$ alr search --crates log
elogs             Embedded logging, proven absent of runtime errors
gnatcoll_syslog   GNAT Components Collection - syslog binding
journada          Simple and nice configurable logging
loga              Simple library for simple logging. Like npm package "debug", but for Ada
pico_ada_c04_pwm  Chapter 4: Analog LED with PWM
prolog            Simple Prolog library
simple_logging    Simple logging to console
testlog           Log test activity to support unit testing of Ada packages
utilada           Utility Library with streams, processes, logs, serialization, encoders

這裡加入把日誌輸出到主控台的 simple_logging。

$ alr with simple_logging
Requested changes:

   + simple_logging ^3.0.0 (add)

Changes to dependency solution:

   + simple_logging 3.0.0 (new)

Do you want to proceed?
Note: Deploying simple_logging=3.0.0...

資訊清單的末尾會加上相依。

[[depends-on]]
simple_logging = "^3.0.0"

^3.0.0 是接受 3.0.0 以上、主版本號相同之版本的指定。Alire 以語意化版本表示 crate 的版本,^ 接受同一主版本號內的新版本,~ 接受同一次版本號內的新版本7。不過,在 1.0 之前的版本中,^ 與 ~ 沒有特別的處理。^0.2 也表示所有低於 1.0 的版本,因此文件建議 1.0 之前的版本使用 ~0.x 的形式7。

加入相依後,產生的 config/hello_alire_config.gpr 開頭加入了 with "simple_logging.gpr";。因此不必改寫自己的 .gpr,就能在原始碼中 with Simple_Logging。

with Simple_Logging;
with Hello_Alire_Config;

procedure Hello_Alire is
   package Log renames Simple_Logging;
begin
   Log.Level := Log.Debug;
   Log.Info ("Hello from Alire");
   Log.Debug
     ("Build profile: "
      & Hello_Alire_Config.Build_Profile_Kind'Image
          (Hello_Alire_Config.Build_Profile));
end Hello_Alire;
$ alr run
...
Build Libraries
   [gprlib]       simple_logging.lexch
   [archive]      libsimple_logging.a
   [index]        libsimple_logging.a
...
Success: Build finished successfully in 4.58 seconds.
Hello from Alire
-->> Build profile: DEVELOPMENT

因為把 Log.Level 設為 Debug,Log.Debug 的訊息也顯示出來了。該行開頭加上了 -->>。

相依的解析結果可以用 alr with --solve 或 alr with --tree 確認。

$ alr with --tree
hello_alire=0.1.0-dev
+-- simple_logging=3.0.0 (^3.0.0)
用 alr with 加入相依的流程表示 alr with 在資訊清單中加入相依,解析版本並取得原始碼,在產生的設定檔中加入 with,讓原始碼可以使用的流程。alr with simple_logging在 alire.toml 加入 depends-on解析版本(^3.0.0 → 3.0.0)取得原始碼在 config 的 .gpr 加入 with可在原始碼中 with

圖 5: alr with 把相依寫進資訊清單,解析版本後,透過設定檔讓它可以使用。

alire.lock 與版本的固定

解析出的版本記錄在 alire/alire.lock。不過這個檔案位於 alire 資料夾中,被 .gitignore 排除。Alire 的文件也說明 alire.lock 是內部用的檔案,會視需要重新產生,因此不必放進版本控制8。

因此,在儲存庫中共享的是寫在資訊清單中的 ^3.0.0 這類版本範圍。想把版本固定為一個時,使用 alr pin。固定內容會寫進資訊清單。

$ alr pin simple_logging
...
   . simple_logging 3.0.0 (pin=3.0.0)
[[depends-on]]
simple_logging = "^3.0.0"

[[pins]]
simple_logging = { version='3.0.0' }

alr update 會以設定的索引重新解析未固定的相依。加上 --online 則會先更新索引。固定也可以指向本機資料夾或 git 儲存庫7。例如以 alr with <名稱> --use=<路徑> 使用開發中的自製函式庫的情況。

版本範圍、固定與解析結果表示 alr 從資訊清單中的版本範圍與 pins 解析版本,把結果記錄在 alire.lock,而 alire.lock 不放進版本控制。只針對未固定的相依alire.toml 的 depends-on(版本範圍)alr 解析版本alire.toml 的 pins(固定)記錄在 alire/alire.lock不放進版本控制alr update

圖 6: 共享的是資訊清單中的範圍與固定,alire.lock 則在各自的環境中重新產生。

建置設定檔會改變什麼

Alire 的建置設定檔有 Development、Release、Validation 三種。預設情況下,自己的 crate 以 Development 建置,相依的 crate 以 Release 建置7。自己 crate 的設定檔可以用 alr build 的參數變更。

$ alr build --release
...
$ alr run --skip-build
Hello from Alire
-->> Build profile: RELEASE

alr run 會以最後一次 alr build 使用的設定檔建置8。

各設定檔的編譯器參數寫在 config/hello_alire_config.gpr 中。alr 2.1 寫出的內容如下(省略了樣式檢查的 -gnaty…)。

設定檔 主要參數
Development -Og -g -gnatwa -gnatVa
Release -O3 -gnatn
Validation -O3 -gnatn -g -gnato -gnatwa -gnatVa -gnatwe -gnata

只有 Validation 含有 -gnata。依 GNAT 的文件,-gnata 是啟用前置條件、後置條件、型別不變式、述詞等斷言的參數,未指定時這些斷言是停用的9。也就是說,用預設的 alr build 建置的程式,在執行時不會檢查寫在 Pre 中的條件。

試試前置條件是否會被檢查

用下面的程式確認。Half 以只接收偶數為前提,並在前置條件中這樣寫。呼叫端故意傳入奇數 7。

with Ada.Text_IO;

procedure Profile_Demo with SPARK_Mode is

   function Half (X : Integer) return Integer
     with Pre => X mod 2 = 0;

   function Half (X : Integer) return Integer is (X / 2);

begin
   Ada.Text_IO.Put_Line (Integer'Image (Half (7)));
end Profile_Demo;

以 Development 建置時,前置條件沒有被檢查,直接顯示 3,並以結束代碼 0 結束。

$ alr build
$ ./bin/profile_demo
 3

以 Validation 建置時,因違反前置條件而引發 Assertion_Error,結束代碼為 1。

$ alr build --validation
$ ./bin/profile_demo

raised ADA.ASSERTIONS.ASSERTION_ERROR : failed precondition from profile_demo.adb:6

測試寫有契約的 crate 時,可以用 Validation 建置,或在資訊清單的 [build-profiles] 指定設定檔。照下面這樣寫,不加參數的 alr build 也會變成 Validation。

[build-profiles]
profile_demo = "validation"

相依 crate 的設定檔也能在同一個表中指定。也可以像 alr build --profiles='*=development' 這樣,從命令列指定全部8。

建置設定檔與前置條件的檢查表示在 Development、Release、Validation 三種建置設定檔中,只有含 -gnata 的 Validation 會在執行時檢查前置條件,另外兩種不會檢查。建置設定檔Development(預設)ReleaseValidation沒有 -gnata有 -gnata執行時不檢查 Pre違反 Pre 時引發 Assertion_Error

圖 7: 只有含 -gnata 的 Validation 會在執行時檢查前置條件。

選擇工具鏈

alr toolchain 會顯示手邊的工具鏈,以及預設使用哪一個。

$ alr toolchain
CRATE         VERSION         STATUS    NOTES
gprbuild      18.0.0          Available Detected at /usr/bin/gprbuild
gprbuild      26.0.1          Default
gprbuild      2024.1.20231009 Available Provided by system package: gprbuild
gnat_native   16.1.0          Default
gnat_external 13.3.0          Available Detected at /usr/bin/gnat

alr toolchain --select 沒有引數時會顯示互動選擇畫面,指定版本時則把該版本設為預設。加上 --local,就不是設定整體,而是只決定在該工作資料夾中使用的版本6。

$ alr toolchain --select --local gnat_native=15.2.1
Note: Deploying gnat_native=15.2.1...
Note: gnat_native=15.2.1 installed successfully.
Note: gnat_native=15.2.1 set as default in local configuration.

--local 的選擇寫進了 alire/settings.toml。這個資料夾被 .gitignore 排除,因此這個選擇不會分享給其他人。當 crate 能運作的編譯器版本有限制時,文件說明可以像 gnat = ">=13" 這樣寫成對 gnat 的相依6。

Alire 選擇的工具鏈可以在透過 alr exec 執行的指令中使用。即使是同一個終端機,是否透過 alr exec,呼叫到的 GNAT 也不同。

$ gnat --version
GNAT 13.3.0
$ alr exec -- gnat --version
GNAT 15.2.0

gnat_native 的 15.2.1 是 crate 的版本,編譯器本身顯示為 15.2.0。alr exec 會先設定 GPR_PROJECT_PATH 與 PATH,再啟動指令。同樣的環境變數可以用 alr printenv 顯示,因此從編輯器執行 GPRbuild 時可以使用4。

Alire 選擇編譯器的順序表示若相依要求目標專用的編譯器就使用它,否則使用使用者選擇的編譯器,再沒有的話就使用使用者環境中已有的編譯器的順序。是否是否相依要求目標專用的編譯器?使用該編譯器使用者選擇了預設?使用選擇的編譯器使用使用者環境中已有的編譯器

圖 8: 編譯器依相依要求的、使用者選擇的、環境中已有的順序選出。

這個順序依據 Alire 的文件。不論在哪一階段,都會優先使用已下載的編譯器,只有沒有合適的才會重新下載6。在本文的環境中,第一次建置時 Alire 自動選擇了預設,因此符合第二階段。

把 GNATprove 加入相依並證明

證明 SPARK 程式碼的 GNATprove 也可以作為 crate 安裝。

$ alr with gnatprove
...
   +b gnatprove 16.1.0 (new,binary)
...
Note: Deploying gnatprove=16.1.0...

alr gnatprove 作為 alr exec -P1 -- gnatprove 的別名內建在 alr 中(顯示在 alr help 的 ALIASES)。-P1 是把 crate 的 .gpr 以 -P 作為第 1 個引數傳入的指定。證明先前的 Profile_Demo,就指出了傳入奇數的呼叫。

$ alr gnatprove
Phase 1 of 3: generation of data representation information ...
Phase 2 of 3: generation of Global contracts ...
Phase 3 of 3: flow analysis and proof ...
 medium: precondition might fail
--> profile_demo.adb:11:41
   11 |       Ada.Text_IO.Put_Line (Integer'Image (Half (7)));
      |                                            ^~~~~~~
      + provers gave up before completing the proof

在 Development 建置中沒有錯誤、顯示 3 的那個呼叫,不用執行就找到了。不過,此時 alr gnatprove 的結束代碼是 0。GNATprove 即使有無法證明的檢查,預設也回傳結束代碼 0,只有加上 --checks-as-errors=on 時才回傳非 0 的值10。

$ alr gnatprove --checks-as-errors=on
...
gnatprove: unproved check messages considered as errors
ERROR: Command ["gnatprove", "-P", "profile_demo.gpr", "--checks-as-errors=on"] exited with code 1

把呼叫改為 Half (8) 後,所有檢查都被證明了。

$ alr gnatprove --checks-as-errors=on --report=all
...
 info: precondition proved
--> profile_demo.adb:11:41

Success: all checks proved (4 checks).

要在有無法證明的檢查時讓 CI 工作失敗,就加上 --checks-as-errors=on。GNATprove 的證明等級與契約的寫法,在「SPARK形式驗證入門」中說明。

alr gnatprove 的結果與結束代碼表示 alr gnatprove 有無法證明的檢查時,預設結束代碼為 0,加上 checks-as-errors 則為 1,全部證明時為 0。沒有有否是alr gnatprove有無法證明的檢查?all checks proved,結束代碼 0有 --checks-as-errors=on?顯示指出內容,結束代碼 0顯示指出內容,結束代碼 1

圖 9: 即使有無法證明的檢查,預設結束代碼也是 0。在 CI 中要加上 –checks-as-errors=on。

alr test 確認的是什麼

alr test 不是執行單元測試的指令。在工作中的 crate 不帶引數執行時,資訊清單中有測試用的動作就執行它,沒有就執行 alr build --release(alr help test)。給予 crate 名稱作為引數時,會一次試驗能否取得索引中的版本並建置。

測試用的動作以 type = "test" 寫在資訊清單中。有動作時不會先建置 crate,因此需要建置的話,要把建置指令也放進動作7。下面的例子把證明當作測試來執行。

[[actions]]
type = "test"
command = ["alr", "gnatprove", "--checks-as-errors=on"]
$ alr test
Note: Synchronizing workspace...
Nothing to update.

Success: Test ended successfully.

改回 Half (7) 後,alr test 以結束代碼 1 結束。

$ alr test
ERROR: Local test of profile_demo=0.1.0-dev failed:
ERROR:    Check alire/alr_test_local.log for details.

在這個環境中,alr test 呼叫的 alr 是從 PATH 尋找的。起初 PATH 中用 apt 安裝的另一個版本的 alr 排在前面,執行的是那一個而失敗了。安裝了多個版本時,要先確認 PATH 的順序。

關於撰寫單元測試時的構成,文件說明在主體下建立測試用的 crate,並以相對路徑固定主體 crate 的形式。這樣只在測試中使用的 AUnit 等相依,就不必放進主體的資訊清單7。

# tests/alire.toml
[[depends-on]]
my_crate = "*"
aunit = "*"

[[pins]]
my_crate = { path = ".." }
alr test 執行的內容表示不帶引數的 alr test,在資訊清單中有 type test 的動作時就執行它,沒有則執行 alr build --release。有沒有alr test(不帶引數)有 type = test 的動作?執行動作(不建置)alr build --release以結束代碼判斷成敗

圖 10: alr test 執行測試用的動作,或以 Release 建置。

公開 crate 時

要把做好的 crate 公開到社群索引,使用 alr publish。本文的環境中沒有試過,因此只說明文件中記載的流程2。

  1. 提交要公開的版本,推送到 GitHub 等受信任網站上的 git 儲存庫。工作目錄保持沒有變更的狀態。
  2. 以 public_repo 權限建立 GitHub 的 Personal Access Token(classic)。放進環境變數 GH_TOKEN,或在 alr 詢問時輸入。
  3. 在儲存庫的根目錄執行 alr publish。alr 會確認內容,fork alire-index,並建立 pull request。
用 alr publish 公開 crate 的流程表示提交並推送要公開的版本,準備 Personal Access Token 後執行 alr publish,alr 會 fork alire-index 並建立 pull request,第一次登錄由人員確認後核准的流程。提交並推送版本準備 Personal Access Token執行 alr publishfork alire-index建立 pull request第一次登錄由人員確認後核准

圖 11: alr publish 從已推送的版本建立對索引的 pull request。

新 crate 的第一次登錄,會在人員確認後核准。之後的版本只有資訊清單 maintainers-logins 中列出的管理者能登錄2。只在公司內部使用的 crate,加上 --for-private-index 就能不提交到社群索引,而是建立自有索引用的資訊清單8。

相關文章

參考連結

  1. Alire, Documentation. 資訊清單 alire.toml、建置環境、目錄格式的說明。 ↩

  2. Alire, Publishing your projects in Alire. alr publish、Personal Access Token、索引登錄的確認。 ↩ ↩2 ↩3

  3. AdaCore, Building with GPRbuild. GPRbuild 的定位與專案檔。 ↩

  4. Alire, Getting Started. 各 OS 的安裝方式、MSYS2、alr init 的問題、alr printenv。 ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8

  5. MSYS2, MSYS2. MSYS2 與 Pacman。 ↩

  6. Alire, Toolchain management. gnat_native、alr toolchain --select、編譯器的選擇順序、對 gnat 的相依。 ↩ ↩2 ↩3 ↩4

  7. Alire, Catalog format specification. depends-on 的版本指定、動作、固定(pins)、建置設定檔與參數、測試用 crate 的構成。 ↩ ↩2 ↩3 ↩4 ↩5 ↩6

  8. Alire, User-facing changes log. alire.lock 的位置與處理、alr build --profiles、alr run 使用最後的設定檔。 ↩ ↩2 ↩3 ↩4

  9. GCC, Alphabetical List of All Switches (GNAT User’s Guide). -gnata 啟用的斷言,以及未指定時的預設。 ↩

  10. AdaCore, How to Run GNATprove (SPARK User’s Guide). 結束代碼與 --checks-as-errors=on。 ↩

共用相同標籤的最新文章。能以相近的主題延伸理解。

與本文相近的主題頁面。以本文為起點,可進一步連到相關服務與其他文章。

本文連結到以下服務頁面,歡迎從最接近的入口查看。

常見問題

整理諮詢這個主題時常見的問題。

Alire 是什麼?
它是 Ada 與 SPARK 的套件管理器。指令是 alr,統一處理專案(crate)的建立、相依 crate 的取得、GNAT 與 GPRbuild 的取得與選擇,以及建置與執行。
使用 Alire 需要另外安裝 GNAT 嗎?
在 x86-64 的 Linux、Windows、macOS 上,Alire 會在第一次建置時下載並使用 GNAT 與 GPRbuild。在本文的 Linux 環境中,沒有手動安裝任何東西,就選用了 gnat_native 16.1.0 與 gprbuild 26.0.1。也可以設定成使用系統中已安裝的 GNAT。
alire.lock 應該放進版本控制嗎?
Alire 的文件說明 alire.lock 是內部用的檔案,會視需要重新產生,因此不必放進版本控制。alr init 產生的 .gitignore 也排除了存放它的 alire 資料夾。想固定相依的版本時,使用 alr pin,固定內容會寫進資訊清單 alire.toml。
用 alr build 建置的程式會檢查前置條件(Pre)嗎?
在預設的 Development 設定檔中沒有檢查,因為 Development 的參數不含 -gnata。在 Validation 設定檔(alr build --validation)中會加上 -gnata,不滿足前置條件的呼叫引發了 Assertion_Error。
alr test 是執行單元測試的指令嗎?
它沒有自己的測試機制。資訊清單中有 type = "test" 的動作時就執行該動作,沒有時則執行 alr build --release 來確認能否建置。至於單元測試,Alire 的文件建議另外建立測試用的 crate,並以相對路徑固定主體 crate 的構成。

作者檔案

本文作者的個人檔案頁面。

Go Komura

小村軟體有限公司 代表

以 Windows 軟體開發、技術諮詢與故障調查為中心,擅長處理仍留有既有資產的專案,以及原因難以看清的故障調查。

回到部落格一覽