Installing Solang¶
The Solang compiler is a single binary. It can be installed in different ways.
Download release binaries¶
For Linux x86-64, there is a binary available in the github releases:
https://github.com/hyperledger-labs/solang/releases/download/v0.1.7/solang-linux
For Windows x64, there is a binary available:
https://github.com/hyperledger-labs/solang/releases/download/v0.1.7/solang.exe
For MacOS, there is a binary available:
https://github.com/hyperledger-labs/solang/releases/download/v0.1.7/solang-mac
Using hyperledgerlabs/solang docker hub images¶
New images are automatically made available on docker hub. There is a release v0.1.7 tag and a latest tag:
docker pull hyperledgerlabs/solang
The Solang binary is stored at /usr/bin/solang
in this image. The latest tag
gets updated each time there is a commit to the main branch of the Solang git repository.
Build Solang using Dockerfile¶
First clone the git repo using:
git clone https://github.com/hyperledger-labs/solang
Then you can build the image using:
docker image build .
Building Solang from source¶
In order to build Solang from source, you will need rust 1.48.0 or higher, and a build of llvm based on our tree. There are a few patches which are not upstream yet First, follow the steps below for installing llvm and then proceed from there.
If you do not have the correct version of rust installed, go to rustup.
Installing the LLVM Libraries¶
Solang needs a build of llvm with some extra patches. You can either download the pre-built binaries or build your own from source. After that, You need to add the bin directory to your path, so that the build system of Solang can find the correct version of llvm to use.
Installing LLVM on Linux¶
A pre-built version of llvm, specifically configured for Solang, is available at https://solang.io/download/llvm10.0-linux.tar.gz. This version is built using the dockerfile for building llvm on linux. After downloading, untar the file in a terminal and add it to your path.
tar zxf llvm10.0-linux.tar.gz
export PATH=$(pwd)/llvm10.0/bin:$PATH
Installing LLVM on Windows¶
A pre-built version of llvm, specifically configured for Solang, is available at https://solang.io/download/llvm10.0-win.zip. This version is built using the dockerfile for building llvm on Windows.
If you want to use the dockerfile yourself rather than download the binaries above, then this
requires Docker Desktop installed, and then switched to
windows containers.
The result will be an image with llvm compressed in the file c:\llvm10.0-win.zip
. Docker on Windows needs Hyper-V
enabled. If you are running Windows 10 in a virtual machine, be sure to check
this blog post.
After unzipping the file, add the bin directory to your path.
set PATH=%PATH%;C:\llvm10.0\bin
Installing LLVM on Mac¶
A pre-built version of llvm, specifically configured for Solang, is available on https://solang.io/download/llvm10.0-mac.tar.gz. This version is built with the instructions below. After downloading, untar the file in a terminal and add it to your path.
tar zxf llvm10.0-mac.tar.gz
xattr -rd com.apple.quarantine llvm10.0
export PATH=$(pwd)/llvm10.0/bin:$PATH
Building LLVM from source¶
The llvm project itself has a guide to installing from source which you may need to consult. First if all clone our llvm repository:
git clone git://github.com/seanyoung/llvm-project
cd llvm-project
Now switch to the bpf branch:
git checkout bpf
Now run cmake to create the makefiles. Replace the installdir argument to CMAKE_INSTALL_PREFIX
with with a directory where you would like to have llvm installed, and then run the build:
cmake -G Ninja -DLLVM_ENABLE_ASSERTIONS=On '-DLLVM_ENABLE_PROJECTS=clang;lld' \
-DLLVM_ENABLE_TERMINFO=Off -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=installdir -B build llvm
cmake --build build --target install
Once the build has succeeded, the installdir/bin has to be added to your path so the
Solang build can find the llvm-config
from this build:
export PATH=installdir/bin:$PATH
And on Windows, assuming installdir was C:\Users\User\solang-llvm
:
set PATH=%PATH%;C:\Users\User\solang-llvm\bin
Building Solang from crates.io¶
The latest Solang release is on crates.io. Once you have the correct llvm version in your path, simply run:
cargo install solang
Building Solang from git¶
Once you have the correct llvm version in your path, simply run:
git clone https://github.com/hyperledger-labs/solang/
cd solang
cargo build --release
The executable will be in target/release/solang
.