-
Notifications
You must be signed in to change notification settings - Fork 264
INSTALL
This page has instructions for installing Dafny:
- Using IDEs: VSCode, Emacs
- Installing a binary build (Windows, Linux, or Mac)
- Installing and building from source (Windows, Linux, or Mac)
- Installing the tools necessary to compile to other languages
- Installing the tools necessary to build the reference manual
- Build against a custom Boogie
The easiest way to get started with Dafny is using the Dafny IDEs, since they continuously run the verifier in the background. Be sure to check out the Dafny tutorial!
For most users, we recommend using Dafny with VS Code, which has an easy installation, as explained next:
- Install Visual Studio Code
- If you are on a Mac or Linux, install .NET 6.0, as described under those platforms below.
- In Visual Studio Code, press
Ctrl+P
(or⌘P
on a Mac), and enterext install dafny-lang.ide-vscode
. - If you open a
.dfy
file, Dafny VSCode will offer to download and install the latest Dafny. You can also browse extensions:
The README at https://github.com/boogie-org/boogie-friends has plenty of
information on how to set-up Emacs to work with Dafny. In short, it boils down
to running [M-x package-install RET boogie-friends RET]
and adding the following
to your .emacs
:
(setq flycheck-dafny-executable "[path to dafny]/dafny/Scripts/dafny")
Do look at the README, though! It's full of useful tips.
The following instructions tell you how to install Dafny so that you can run it from various operating systems or as a command-line tool.
If you wish to compile to target languages other than .NET, see the instructions in a subsequent section to install the correct dependencies for the desired language.
To install Dafny on your own machine,
- Install (if not already present) .NET Core 6.0:
https://dotnet.microsoft.com/download/dotnet/6.0
- download the windows zip file from the releases page and save it to your disk.
- Then, before you open or unzip it, right-click on it and select Properties; at the bottom of the dialog, click the Unblock button and then the OK button.
- Now, open the zip file and copy its contents into a directory on your machine. (You can now delete the zip file.)
Then:
- To run Dafny from the command line, simply run
Dafny.exe
.
To install a binary installation of dafny on Linux (e.g., Ubuntu), do the following:
- Install .NET 6.0. See:
https://docs.microsoft.com/dotnet/core/install/linux
orsudo apt install dotnet-sdk-6.0
- Install the Linux binary version of Dafny, from
https://github.com/dafny-lang/dafny/releases/latest
- Unzip the downloaded file in a (empty) location of your choice
Within the unzipped Linux distribution, the dafny executable is dafny/dafny
If you intend to use the Dafny compiler, install the appropriate tools as described here
After the compiler dependencies are installed, you can run a quick test of the installation by running the script
$INSTALL/dafny/quicktest.sh
To install a binary installation of dafny on Mac OS, do the following:
- Install .NET 6.0, either from Homebrew or the official MacOS installer.
- For Homebrew:
brew install dotnet@6
-
export PATH="/usr/local/opt/dotnet@6/bin:$PATH"
for Intel machines, orexport PATH="/opt/homebrew/opt/dotnet@6/bin:$PATH"
for ARM machines. -
export DOTNET_ROOT="/usr/local/opt/dotnet@6/libexec"
for Intel machines, orexport DOTNET_ROOT="/opt/homebrew/opt/dotnet@6/libexec"
for ARM machines.
- For the official installer:
- Download
.pkg
file from https://dotnet.microsoft.com/en-us/download - Open
.pkg
file and install
- Download
- For Homebrew:
- Install the Mac binary version of Dafny, from
https://github.com/dafny-lang/dafny/releases/latest
- Unzip the downloaded file in a (empty) location of your choice ($INSTALL)
- cd into the installation directory (
$INSTALL/dafny
) and runxattr -d com.apple.quarantine *.dylib dafny DafnyServer *.dll z3/bin/z3
or, more easily, run the script$INSTALL/dafny/allow_on_mac.sh
Alternatively, you can use Homebrew to install Dafny:
brew install dafny
though this version can lag the release on the Dafny github releases page
Within the unzipped Mac distribution, the dafny executable is dafny/dafny
If you intend to use the Dafny compiler, you'll need a few extra dependencies:
- For Javascript, you'll need Node and the
biginteger.js
package from NPM:brew install node && npm install bignumber.js
- For Go, you'll need the Go compiler:
brew install go
- For C#, the .NET SDK described above is sufficient
- For Java and C++, the standard macOS command-line tools for Xcode are sufficient
- For Python, the standard Python installation is sufficient
After the compiler dependencies are installed, you can run a quick test of the installation by running the script
$INSTALL/dafny/quicktest.sh
.
The .NET NuGet repository collects .NET libraries and tools for easy installation. Dafny is available on NuGet, and can be installed as follows:
- Install .NET 6.0 as described for your platform in one of the subsections above.
- Install a binary version of Z3 4.12.1 for your platform from its GitHub releases page and put the
z3
executable in yourPATH
. - Install Dafny using
dotnet tool install --global dafny
(or leave out the--global
to use withdotnet tool run
from the source directory of a .NET project).
If you want access to the very latest Dafny developments or you want to extend Dafny yourself, install the source code, as explained here.
Note that the Dafny integration tests are mainly written using the syntax defined by the LLVM Integrated Tester (LIT) tool, but are actually run using a custom xUnit adaptor in the IntegrationTests
package. The configuration files for LIT are still temporarily present in the Test
directory and therefore LIT is still likely to work, but its use is deprecated and will not be supported in the future. See here for more details.
First, install the following external dependencies:
- Visual Studio 2017 or newer, or the free Visual Studio Community Edition
- Visual Studio SDK extension
- Code contract extension
- NUnit test adapter
- Python 3 which should come bundled with pip, or manually install pip.
To install pre-commit checks to verify the style of C# files, run:
pip install pre-commit
pre-commit install
If you had any pre-commit scripts before, follow these steps to keep them.
Second, clone the Dafny source code.
git clone https://github.com/dafny-lang/dafny --recurse-submodules
Third, build the Dafny project, either on the command line:
dotnet build dafny\Source\Dafny.sln
or open Visual Studio, and open dafny/Source/Dafny.sln
, and click on Build > Build solution while the project Dafny Runtime
is still the startup project (in bold)
To run Dafny on a particular file, or to run the tests, you'll have to install a prover such as CVC4 or z3. For z3, do the following:
- Go to the release of version 4.12.1, download the zip according to your system
- Unzip the content of the Z3 folder into
dafny\Binaries\z3
so thatdafny\Binaries\z3\bin\z3.exe
exists. - (optional, depending on configuration) Make sure the
dafny\Binaries\z3\bin
folder is accessible from the command line by updating the PATH environment variable.
To run Dafny on a particular file:
- Right-click the project
DafnyDriver
, and set as startup project - Click Debug > DafnyDriver Debug properties...
- In the text area "Application arguments", write the path to the file you would like to run Dafny on, e.g.
"..\..\Test.dfy"
with the double quotes, if the fileTest.dfy
is next to thedafny
folder, and save - Now, press F5 to compile Dafny and run it on the specified file.
To run the integration tests, go to dafny/Source/IntegrationTests
and run dotnet test -v:n
.
Make sure you install all the dependencies to compile Dafny to other languages and run them.
-
Dependencies:
- Install .NET 6.0 as described above
- Install python3: e.g.,
sudo apt install python3 python3-pip
- If you intend to compile to Java, install Java and gradle
-
Download and build Dafny:
git clone https://github.com/dafny-lang/dafny.git --recurse-submodules cd dafny make exe
To install pre-commit checks to verify the style of the source code, perform
pip3 install pre-commit
pre-commit install
If you had any pre-commit scripts before, follow these steps to keep them.
-
Install Z3 version 4.12.1 (not the most recent version of Z3)
`make z3-ubuntu`
OR
cd dafny/Binaries wget https://github.com/Z3Prover/z3/releases/download/Z3-4.12.1/z3-4.12.1-x64-ubuntu-16.04.zip unzip z3-4.12.1-x64-ubuntu-16.04.zip mv z3-4.12.1-x64-ubuntu-16.04 z3
-
Install the compiler dependences as described here.
-
Run Dafny using the
dafny
shell script in the Scripts directory: dafny/Scripts/dafny You can run a quick test of the installation by executing dafny/Scripts/quicktest.sh -
To execute the integration tests:
cd dafny/Source/IntegrationTests; dotnet test -v:n
. Make sure you install all the dependencies to compile Dafny to other languages and run them. The tests take a while, depending on your machine, but emit progress output.
-
Dependencies:
- Install .NET (6.0):
brew install dotnet-sdk
- [python3 and pip3 are needed but they are likely already part of the Mac installation]
- (Optional) Install java (possibly use
brew install openjdk@8
) - (Optional) Install gradle (possibly use
brew install gradle
)
- Install .NET (6.0):
-
Download and build Dafny:
git clone https://github.com/dafny-lang/dafny.git --recurse-submodules cd dafny make exe
To install pre-commit checks to verify the style of the source code, perform
brew install pre-commit
pre-commit install
If you had any pre-commit scripts before, follow these steps to keep them.
-
Download and unpack Z3 (Dafny looks for
z3
in Binaries/z3/bin/) version 4.12.1 (note, this is not the latest version of Z3). You can usebrew install wget make z3-mac
or
cd dafny/Binaries
wget https://github.com/Z3Prover/z3/releases/download/Z3-4.12.1/z3-4.12.1-x64-osx-10.14.2.zip
unzip z3-4.12.1-x64-osx-10.14.2.zip
mv z3-4.12.1-x64-osx-10.14.2 z3
-
Install the compiler dependences as described here.
-
Run Dafny using the
dafny
shell script in the Scripts directory: dafny/Scripts/dafny You can run a quick test of the installation by executing dafny/Scripts/quicktest.sh -
To execute the integration tests:
cd dafny/Source/IntegrationTests; dotnet test -v:n
. Make sure you install all the dependencies to compile Dafny to other languages and run them. The tests take a while, depending on your machine, but emit progress output.
If you install pre-commit, it will rename any existing pre-commit hook (./git/hooks/pre-commit
) to a file namepre-commit.legacy
, and put a python script named pre-commit
instead.
To keep any previous pre-commit hooks along with the new hook:
- Rename
pre-commit
topre-commit-python
- Make
pre-commit-python
executable - Rename
pre-commit.legacy
topre-commit
- Add the line
./.git/hooks/pre-commit-python
to the filepre-commit
.
The reference manual is only buildable on Linux or Mac and requires some tools to be installed
On Mac:
brew install --cask basictex
brew install pandoc
eval "$(/usr/libexec/path_helper)"
sudo tlmgr update --self
sudo tlmgr install framed tcolorbox environ trimspaces
Then, in the top-level directory of the source distribution: make refman
Dafny is tightly integrated with Boogie. Sometimes we want to make Boogie changes and test those changes against Dafny. To do that, you must replace the Boogie NuGet package reference with project references to a locally checked out Boogie. We've added the git patch customBoogie.patch
to the Dafny repository to make this easier. The patch requires that a Boogie repository with directory boogie
is a sibling of the Dafny repository.
Steps to use:
git clone git@github.com:dafny-lang/dafny.git --recurse-submodules
cd dafny
git clone git@github.com:boogie-org/boogie.git
git apply customBoogie.patch
dotnet build Source/Dafny.sln
You can then use git checkout Source/Dafny.sln Source/Directory.Build.props
to return to the version of Boogie that Dafny regularly builds with.
Alternatively, you can build a local checkout of Boogie separately and copy the binaries into the Dafny Binaries
directory with the Scripts/use-local-boogie.sh
script:
-
ln -s <your checkout of Boogie> Source/boogie
(or clone it there directly) dotnet build Source/Dafny.sln
Scripts/use-local-boogie.sh
This can be useful for certain debugging scenarios in which you want to temporarily use a custom Boogie version, because cleaning and rebuilding automatically reverts to the standard version, and because Boogie can then easily be built with different compilation flags than Dafny.