This is a Bash script (macOS, Linux, ...) for building Flang-f18 and LLVM from source. It is adapted from Jeff Hammond
Ninja: recommended for best build efficiency and speed.
In general, a recent GCC would work. On macOS, system AppleClang compiler can be used as well.
bash build-flang-f18.sh
To specify the source URL, for example to build the latest LLVM 19.x release:
bash build-flang-f18.sh https://github.com/llvm/llvm-project/archive/refs/heads/release/19.x.zip
For a specific version of LLVM:
bash build-flang-f18.sh https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-19.1.0.zip
The source download is about 300 MB. LLVM takes about a half-hour to build on a powerful laptop or workstation.
To use the compiler after install:
source clang-latest.sh
lld
LLVM linkermlir
intermediate representationpstl
Parallel STL (optional)polly
Loop optimization (optional)
See ulimit settings if link failures occur.
The installed binaries take a few gigabytes of disk space.
du -sh ~/llvm-latest # the install prefix
3.5G
About 3.5 Gigabytes are used for the installed LLVM binaries.
The source directory can be deleted after the build / install is complete.
du -sh $TMPDIR/llvm-src
1.8G
The build directory can be deleted after the build / install is complete.
du -sh $TMPDIR/llvm-build
5.0G
Update that the script might need. When I tried running this I got:
when it tried to link together what seems to be a crazy number of files. If I got my awk right, somewhere over 1300.
Searching internet seems to show that this could be a
ulimit
issue and on my system:And, well, that is less than 1300!
So I then ran:
and I got past it.