flang the compiler proves your program cannot hang 0.9.0 GitHub Try in the browserTry it Русский

Installing

How do you install flang on your machine and check that it works? There are five ways, listed in the table below. Latest release — 0.9.0 (release on GitHub).

WayWhat it installsNeeded on the machine
One linea prebuilt build into ~/.local, no sudocurl or wget, sha256sum or shasum
Homebrewflang, the library, the headers, man flangbrew
asdfflang alongside other versionsasdf
deb and rpma system packageapt or dnf
From sourceflang from a clonegit, cc, make

Prebuilt builds exist for Linux x86_64 and aarch64 (static, they run on any distribution) and for macOS arm64 and x86_64. The package is called flang-package; the command is flang. Every build has program checking, proofs, code generation for all ten target languages and the language server (flang lsp --stdio).

There is no native Windows build: install inside WSL.

The name flang is also used by LLVM Flang. LLVM's Fortran compiler installs a command with the same name. If both are installed, whichever comes first on PATH runs. Ours answers flang --version with flang <version> on the first line. Fix it by the order of directories on PATH or by calling the command by its full path.

One line

curl -fsSL https://raw.githubusercontent.com/digitable-lol/flang/main/install.sh | sh

The script picks the build for the system and the CPU and downloads it. It checks the checksum against the release's SHA256SUMS; when the checksum differs, nothing is installed. It installs into ~/.local. Its last line is the uninstall command.

Environment variableWhat it setsExample
FLANG_VERSIONa version instead of the latestFLANG_VERSION=0.9.0
PREFIXa directory instead of ~/.localPREFIX=/opt/flang

Homebrew

brew install digitable-lol/tap/flang-package

Installs flang, libcompiler_flang.a, the headers and the man flang page. brew install digitable-lol/tap/flang is another name of the same formula.

asdf

asdf plugin add flang https://github.com/digitable-lol/asdf-flang.git
asdf install flang latest
asdf set -u flang latest

The plugin downloads the prebuilt build and checks its checksum. With ASDF_FLANG_FROM_SOURCE=1 it builds from source, which needs cc and make. The same plugin works in mise: mise plugin add flang https://github.com/digitable-lol/asdf-flang.git.

deb and rpm

Download the package for your CPU from the latest release and install it:

sudo apt install ./flang-package_<version>_amd64.deb     # or _arm64.deb
sudo dnf install ./flang-package-<version>-1.x86_64.rpm   # or .aarch64.rpm

The rpm conflicts with Fedora's flang package (LLVM Flang): both own /usr/bin/flang.

From source

git clone https://github.com/digitable-lol/flang.git
cd flang
make -C bootstrap -j4
sudo make -C bootstrap install        # or PREFIX=$HOME/.local, no sudo

The build is slow: the compiler is one large C file, and -j does not speed it up. On the developers' machine it takes about 13 minutes. The last line of the output says where it went ("installed: … — check with flang --version"):

поставлено: /usr/local/bin/flang — проверьте: flang --version

PREFIX receives bin/flang, lib/libcompiler_flang.a, the headers in include/, the run-time libraries of the target languages in share/flang/<language>/ and the standard library in share/flang/stdlib/. The version is the one in the clone.

This way installs neither the man page nor checker, the program that re-checks proofs independently; the prebuilt builds have both. Where the compiler looks for the standard library is in the guide.

Without make, one call to cc is enough:

cd bootstrap
cc -std=c99 -Wall -Wextra -Werror -pedantic -O2 -o flang \
   flang_cli.c flang_repl.c flang_runtime.c compiler_flang.c -lm -lpthread

Checking the install

flang --version
flang 0.9.0
оболочка …: правит строку (стрелки, слова, история, Tab), цвет digitable

The second line is about the interactive shell, which starts when flang is called without arguments.

File two.flang:

module «Hello»

total function «Two»
  returns number
  2
flang check two.flang
модуль «Hello»: функций 1, из них с доказанным завершением 1; типов 0
two.flang: проверено — доказано 0, проверено только на тестах 0, не доказано 0 (постусловий и утверждений 0); замечаний нет

Exit code 0. The second line ends with "no errors". For a file with errors the last line is не проверено — замечаний N ("not checked — N errors") and the exit code is 1.

flang run two.flang --function Two
доказано: утверждений 0
2

The first line says how many postconditions are proved: this file has none. The second is the result of the function.

Uninstalling

WayCommand
One linerm -rf … — the script printed the ready command as its last line when it installed
Homebrewbrew uninstall flang-package
asdfasdf uninstall flang <version>, then asdf plugin remove flang
deb, rpmsudo apt remove flang-package, sudo dnf remove flang-package
From sourcemake -C bootstrap uninstall — with the same PREFIX=… you installed with

make -C bootstrap uninstall leaves the headers in include/ (compiler_flang.h, flang_runtime.h, tls_client.h) — remove them by hand.

What next