First of all, you need a compiler with decent C11 support. We officially support Clang on Unix and MSVC on Windows; the following are known to work:
- Clang >= 3.4
- XCode Clang >= 6.0
- MSVC >= 2017
- GCC >= 4.7
You also need CMake version 3.15 or higher.
The build system uses CMake, and includes a helper wrapper that will automatically set up your out-of-source build directories and libraries for you.
The build system is divided into several stages:
-
Build the vendored LLVM libraries that are included in the
lib/llvm/srcGit submodule by runningmake libs(.\make.ps1 libson Windows). This stage only needs to be run once the first time you build (or if the vendored LLVM submodule changes, or if you runmake distclean).- This can take a while. To ensure it's using all cores, try
make libs build_flags="-j6", replacing6with the number of CPU cores available.
- This can take a while. To ensure it's using all cores, try
-
make configureto configure the CMake build directory. Usemake configure config=debug(.\make.ps1 configure -Config Debug) for a debug build. -
make buildwill build ponyc and put it inbuild/release. Usemake build config=debug(.\make.ps1 build -Config Debugon Windows) for a debug build that goes inbuild/debug. -
make testwill run the test suite. -
make installwill install ponyc to/usr/localby default (make install prefix=/footo install elsewhere;make install -Prefix fooon Windows). -
make cleanwill clean your ponyc build, but not the libraries. -
make distcleanwill delete the entirebuilddirectory, including the libraries.
The build system defaults to using Clang on Unix. In order to use GCC, you must explicitly set it in the configure step: make configure CC=gcc CXX=g++.
pkg install -y cmake gmake libunwind git
gmake libs
gmake configure
gmake build
sudo gmake installNote that you only need to run make libs once the first time you build (or if the version of LLVM in the lib/llvm/src Git submodule changes).
pkg install -y cxx_atomicsThen continue with the same instructions as FreeBSD.
make libs
make configure
make build
sudo make installAdditional Requirements:
| Distribution | Requires |
|---|---|
| Alpine | cmake, g++, libexecinfo, make |
| CentOS 8 | clang, cmake, diffutils, libatomic, libstdc++-static, make, zlib-devel |
| Fedora | cmake, gcc-c++, libatomic, libstdc++-static, make |
| Ubuntu | cmake, g++, make |
Note that you only need to run make libs once the first time you build (or if the version of LLVM in the lib/llvm/src Git submodule changes).
make libs
make configure
make build
sudo make installNote that you only need to run make libs once the first time you build (or if the version of LLVM in the lib/llvm/src Git submodule changes).
Building on Windows requires the following:
- CMake version 3.15.0 or higher needs to be in your PATH.
- Visual Studio 2019 or 2017 (available here) or the Visual C++ Build Tools 2019 or 2017 (available here).
- If using Visual Studio, install the
Desktop Development with C++workload. - If using Visual C++ Build Tools, install the
Visual C++ build toolsworkload, and theVisual Studio C++ core featuresindividual component. - Install the latest
Windows 10 SDK (10.x.x.x) for Desktopcomponent.
- If using Visual Studio, install the
In a PowerShell prompt, run:
.\make.ps1 libs
.\make.ps1 configure
.\make.ps1 buildFollowing building, to make ponyc.exe globally available, add it to your PATH either by using Advanced System Settings->Environment Variables to extend PATH or by using the setx command, e.g. setx PATH "%PATH%;<ponyc repo>\build\release"
Note that you only need to run .\make.ps1 libs once the first time you build (or if the version of LLVM in the lib/llvm/src Git submodule changes).
You can specify the CPU architecture to build Pony for via the arch make option:
make configure arch=arm7
make buildLink-time optimizations provide a performance improvement. You should strongly consider turning on LTO if you build ponyc from source. It's off by default as it comes with some caveats:
-
If you aren't using clang as your linker, we've seen LTO generate incorrect binaries. It's rare but it can happen. Before turning on LTO you need to be aware that it's possible.
-
If you are on MacOS, turning on LTO means that if you upgrade your version of XCode, you will have to rebuild your Pony compiler. You won't be able to link Pony programs if there is a mismatch between the version of XCode used to build the Pony runtime and the version of XCode you currently have installed.
LTO is enabled by setting lto to yes in the build command line like:
make configure lto=yes
make buildIf you're compiling with Clang, you can build the Pony runtime as an LLVM bitcode file by setting runtime-bitcode to yes in the build command line:
make configure runtime-bitcode=yes
make buildThen, you can pass the --runtimebc option to ponyc in order to use the bitcode file instead of the static library to link in the runtime:
ponyc --runtimebcThis functionality boils down to "super LTO" for the runtime. The Pony compiler will have full knowledge of the runtime and will perform advanced interprocedural optimisations between your Pony code and the runtime. If you're looking for maximum performance, you should consider this option. Note that this can result in very long optimisation times.
To ease development and support LSP tools like clangd, create a compile_commands.json file with the following steps:
- Run the
make configurestep for building ponyc with the following variable defined:CMAKE_FLAGS='-DCMAKE_EXPORT_COMPILE_COMMANDS=ON' - symlink the generated
compile_commands.jsonfiles into the project root directory:
ln -sf build/build_debug/compile_commands.json compile_commands.jsonReplace build_debug with build_release is you are using a release configuration for compilation.
Now clangd will pick up the generated file and will be able to respond much quicker than without compile_commands.json file.