installing.rst 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. Installing Solang
  2. =================
  3. The Solang compiler is a single binary. It can be installed in different ways, listed below.
  4. 1. :ref:`Download from Homebrew <download-brew>` (MacOS only)
  5. 2. :ref:`Download binaries <download-binaries>`
  6. 3. :ref:`Download from a Docker container <download-docker>`
  7. 4. :ref:`Build using Dockerfile <build-dockerfile>`
  8. 5. :ref:`Build from source <build-source>`
  9. .. _download-brew:
  10. Option 1: Download from Brew
  11. ----------------------------
  12. Solang is available on Brew via a private tap. This works only for MacOS systems, both Intel and Apple Silicon.
  13. To install Solang via Brew, run the following command:
  14. .. code-block:: text
  15. brew install hyperledger/solang/solang
  16. .. _download-binaries:
  17. Option 2: Download binaries
  18. ---------------------------
  19. There are binaries available on github releases:
  20. - `Linux x86-64 <https://github.com/hyperledger/solang/releases/download/v0.3.1/solang-linux-x86-64>`_
  21. - `Linux arm64 <https://github.com/hyperledger/solang/releases/download/v0.3.1/solang-linux-arm64>`_
  22. - `Windows x64 <https://github.com/hyperledger/solang/releases/download/v0.3.1/solang.exe>`_
  23. - `MacOS intel <https://github.com/hyperledger/solang/releases/download/v0.3.1/solang-mac-intel>`_
  24. - `MacOS arm <https://github.com/hyperledger/solang/releases/download/v0.3.1/solang-mac-arm>`_
  25. Download the file and save it somewhere in your ``$PATH``, for example the bin directory in your home directory. If the
  26. path you use is not already in ``$PATH``, then you need to add it yourself.
  27. On MacOS, remember to give execution permission to the file and remove it from quarantine by executing the following commands:
  28. .. code-block:: bash
  29. chmod +x solang-mac-arm
  30. xattr -d com.apple.quarantine solang-mac-arm
  31. If you are using an Intel based Mac, please, exchange ``solang-mac-arm`` by ``solang-mac-intel`` in both of the above commands.
  32. On Linux, permission to execute the binary is also necessary, so, please, run ``chmod +x solang-linux-x86-64``. If you
  33. are using an Arm based Linux, the command is the following: ``chmod +x solang-linux-arm64``.
  34. .. _download-docker:
  35. Option 3: Use ghcr.io/hyperledger/solang containers
  36. ---------------------------------------------------
  37. New images are automatically made available on
  38. `solang containers <https://github.com/hyperledger/solang/pkgs/container/solang>`_.
  39. There is a release `v0.3.1` tag and a `latest` tag:
  40. .. code-block:: bash
  41. docker pull ghcr.io/hyperledger/solang:latest
  42. The Solang binary is stored at ``/usr/bin/solang`` in this image. The `latest` tag
  43. gets updated each time there is a commit to the main branch of the Solang git repository.
  44. .. _build-dockerfile:
  45. Option 4: Build Solang using Dockerfile
  46. ---------------------------------------
  47. First clone the git repo using:
  48. .. code-block:: bash
  49. git clone https://github.com/hyperledger/solang
  50. Then you can build the image using:
  51. .. code-block:: bash
  52. docker image build .
  53. .. _build-source:
  54. Option 5: Build Solang from source
  55. ----------------------------------
  56. In order to build Solang from source, you will need:
  57. * Rust version 1.68.0 or higher
  58. * A C++ compiler with support for C++17
  59. * A build of LLVM based on the Solana LLVM tree. There are a few LLVM patches required that are not upstream yet.
  60. First, follow the steps below for installing LLVM and then proceed from there.
  61. If you do not have the correct version of rust installed, go to `rustup <https://rustup.rs/>`_.
  62. Compatible C++17 compilers are recent releases of ``gcc``, ``clang`` and Visual Studio 2019 or later.
  63. To install Solang from sources, do the following:
  64. 1. :ref:`Install LLVM <install-llvm>` from Solana's LLVM fork.
  65. 2. :ref:`Build Solang <build-from-source>` from its source files.
  66. Solang is also available on `crates.io`, so after completing step #1 from above, it is possible to :ref:`build it using the
  67. release <build-from-crates>` on crates.
  68. .. _install-llvm:
  69. Step 1: Install the LLVM Libraries
  70. _____________________________________
  71. Solang needs a build of
  72. `LLVM with some extra patches <https://github.com/solana-labs/llvm-project/>`_.
  73. These patches make it possible to generate code for Solana, and fixes
  74. concurrency issues in the lld linker.
  75. You can either download the pre-built libraries from
  76. `github <https://github.com/hyperledger/solang-llvm/releases>`_
  77. or :ref:`build your own from source <llvm-from-source>`. After that, you need to add the ``bin`` of your
  78. LLVM directory to your path, so that the build system of Solang can find the correct version of LLVM to use.
  79. Linux
  80. ~~~~~
  81. A pre-built version of LLVM, specifically configured for Solang, is available at
  82. `<https://github.com/hyperledger/solang-llvm/releases/download/llvm15-1/llvm15.0-linux-x86-64.tar.xz>`_ for x86 processors
  83. and at `<https://github.com/hyperledger/solang-llvm/releases/download/llvm15-1/llvm15.0-linux-arm64.tar.xz>`_ for ARM.
  84. After downloading, untar the file in a terminal and add it to your path.
  85. .. code-block:: bash
  86. tar Jxf llvm15.0-linux-x86-64.tar.xz
  87. export PATH=$(pwd)/llvm15.0/bin:$PATH
  88. Windows
  89. ~~~~~~~
  90. A pre-built version of LLVM, specifically configured for Solang, is available at
  91. `<https://github.com/hyperledger/solang-llvm/releases/download/llvm15-1/llvm15.0-win.zip>`_.
  92. After unzipping the file, add the bin directory to your path.
  93. .. code-block:: batch
  94. set PATH=%PATH%;C:\llvm15.0\bin
  95. Mac
  96. ~~~
  97. A pre-built version of LLVM for intel macs, is available at
  98. `<https://github.com/hyperledger/solang-llvm/releases/download/llvm15-1/llvm15.0-mac-intel.tar.xz>`_ and for arm macs there is
  99. `<https://github.com/hyperledger/solang-llvm/releases/download/llvm15-1/llvm15.0-mac-arm.tar.xz>`_. After downloading,
  100. untar the file in a terminal and add it to your path like so:
  101. .. code-block:: bash
  102. tar Jxf llvm15.0-mac-arm.tar.xz
  103. xattr -rd com.apple.quarantine llvm15.0
  104. export PATH=$(pwd)/llvm15.0/bin:$PATH
  105. .. _llvm-from-source:
  106. Building LLVM from source
  107. ~~~~~~~~~~~~~~~~~~~~~~~~~
  108. The LLVM project itself has a guide to `installing from source <http://www.llvm.org/docs/CMake.html>`_ which
  109. you may need to consult. First of all clone our LLVM repository:
  110. .. code-block:: bash
  111. git clone --depth 1 --branch solana-rustc/15.0-2022-08-09 https://github.com/solana-labs/llvm-project
  112. cd llvm-project
  113. Now run cmake to create the makefiles. Replace the *installdir* argument to ``CMAKE_INSTALL_PREFIX`` with a directory where you would like to have LLVM installed, and then run the build:
  114. .. code-block:: bash
  115. cmake -G Ninja -DLLVM_ENABLE_ASSERTIONS=On '-DLLVM_ENABLE_PROJECTS=clang;lld' \
  116. -DLLVM_ENABLE_TERMINFO=Off -DCMAKE_BUILD_TYPE=Release \
  117. -DLLVM_ENABLE_ZSTD=Off \
  118. -DCMAKE_INSTALL_PREFIX=installdir -B build llvm
  119. cmake --build build --target install
  120. Once the build has succeeded, the *installdir*/bin has to be added to your path so the
  121. Solang build can find the ``llvm-config`` from this build:
  122. .. code-block:: bash
  123. export PATH=installdir/bin:$PATH
  124. And on Windows, assuming *installdir* was ``C:\Users\User\solang-llvm``:
  125. .. code-block:: batch
  126. set PATH=%PATH%;C:\Users\User\solang-llvm\bin
  127. .. _build-from-source:
  128. Step 2: Build Solang
  129. ____________________
  130. Once you have the correct LLVM version in your path, ensure you have GNU make installed and simply run:
  131. .. code-block:: bash
  132. git clone https://github.com/hyperledger/solang/
  133. cd solang
  134. cargo build --release
  135. The executable will be in ``target/release/solang``.
  136. .. _build-from-crates:
  137. Alternative step 2: Build Solang from crates.io
  138. _______________________________________________
  139. The latest Solang release is on `crates.io <https://crates.io/crates/solang>`_. Once you have the
  140. correct LLVM version in your path, ensure you have GNU make installed and simply run:
  141. .. code-block:: bash
  142. cargo install solang