installing.rst 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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.2.1/solang-linux-x86-64>`_
  21. - `Linux arm64 <https://github.com/hyperledger/solang/releases/download/v0.2.1/solang-linux-arm64>`_
  22. - `Windows x64 <https://github.com/hyperledger/solang/releases/download/v0.2.1/solang.exe>`_
  23. - `MacOS intel <https://github.com/hyperledger/solang/releases/download/v0.2.1/solang-mac-intel>`_
  24. - `MacOS arm <https://github.com/hyperledger/solang/releases/download/v0.2.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.2.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 rust 1.63.0 or higher,
  57. and a build of LLVM based on the Solana LLVM tree. There are a few LLVM patches required that are not upstream yet.
  58. First, follow the steps below for installing LLVM and then proceed from there.
  59. If you do not have the correct version of rust installed, go to `rustup <https://rustup.rs/>`_.
  60. To install Solang from sources, do the following:
  61. 1. :ref:`Install LLVM <install-llvm>` from Solana's LLVM fork.
  62. 2. :ref:`Build Solang <build-from-source>` from its source files.
  63. Solang is also available on `crates.io`, so after completing step #1 from above, it is possible to :ref:`build it using the
  64. release <build-from-crates>` on crates.
  65. .. _install-llvm:
  66. Step 1: Install the LLVM Libraries
  67. _____________________________________
  68. Solang needs a build of
  69. `LLVM with some extra patches <https://github.com/solana-labs/llvm-project/>`_.
  70. These patches make it possible to generate code for Solana, and fixes
  71. concurrency issues in the lld linker.
  72. You can either download the pre-built libraries from
  73. `github <https://github.com/hyperledger/solang/releases/tag/v0.2.1>`_
  74. or :ref:`build your own from source <llvm-from-source>`. After that, you need to add the ``bin`` of your
  75. LLVM directory to your path, so that the build system of Solang can find the correct version of LLVM to use.
  76. Linux
  77. ~~~~~
  78. A pre-built version of LLVM, specifically configured for Solang, is available at
  79. `<https://github.com/hyperledger/solang/releases/download/v0.2.1/llvm14.0-linux-x86-64.tar.xz>`_ for x86 processors
  80. and at `<https://github.com/hyperledger/solang/releases/download/v0.2.1/llvm14.0-linux-arm64.tar.xz>`_ for ARM.
  81. After downloading, untar the file in a terminal and add it to your path.
  82. .. code-block:: bash
  83. tar Jxf llvm14.0-linux-x86-64.tar.xz
  84. export PATH=$(pwd)/llvm14.0/bin:$PATH
  85. Windows
  86. ~~~~~~~
  87. A pre-built version of LLVM, specifically configured for Solang, is available at
  88. `<https://github.com/hyperledger/solang/releases/download/v0.2.1/llvm14.0-win.zip>`_.
  89. After unzipping the file, add the bin directory to your path.
  90. .. code-block:: batch
  91. set PATH=%PATH%;C:\llvm14.0\bin
  92. Mac
  93. ~~~
  94. A pre-built version of LLVM for intel macs, is available at
  95. `<https://github.com/hyperledger/solang/releases/download/v0.2.1/llvm14.0-mac-intel.tar.xz>`_ and for arm macs there is
  96. `<https://github.com/hyperledger/solang/releases/download/v0.2.1/llvm14.0-mac-arm.tar.xz>`_. After downloading,
  97. untar the file in a terminal and add it to your path like so:
  98. .. code-block:: bash
  99. tar Jxf llvm14.0-mac-arm.tar.xz
  100. xattr -rd com.apple.quarantine llvm14.0
  101. export PATH=$(pwd)/llvm14.0/bin:$PATH
  102. .. _llvm-from-source:
  103. Building LLVM from source
  104. ~~~~~~~~~~~~~~~~~~~~~~~~~
  105. The LLVM project itself has a guide to `installing from source <http://www.llvm.org/docs/CMake.html>`_ which
  106. you may need to consult. First if all clone our LLVM repository:
  107. .. code-block:: bash
  108. git clone --depth 1 --branch solana-rustc/14.0-2022-03-22 https://github.com/solana-labs/llvm-project
  109. cd llvm-project
  110. 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:
  111. .. code-block:: bash
  112. cmake -G Ninja -DLLVM_ENABLE_ASSERTIONS=On '-DLLVM_ENABLE_PROJECTS=clang;lld' \
  113. -DLLVM_ENABLE_TERMINFO=Off -DCMAKE_BUILD_TYPE=Release \
  114. -DCMAKE_INSTALL_PREFIX=installdir -B build llvm
  115. cmake --build build --target install
  116. Once the build has succeeded, the *installdir*/bin has to be added to your path so the
  117. Solang build can find the ``llvm-config`` from this build:
  118. .. code-block:: bash
  119. export PATH=installdir/bin:$PATH
  120. And on Windows, assuming *installdir* was ``C:\Users\User\solang-llvm``:
  121. .. code-block:: batch
  122. set PATH=%PATH%;C:\Users\User\solang-llvm\bin
  123. .. _build-from-source:
  124. Step 2: Build Solang
  125. ____________________
  126. Once you have the correct LLVM version in your path, simply run:
  127. .. code-block:: bash
  128. git clone https://github.com/hyperledger/solang/
  129. cd solang
  130. cargo build --release
  131. The executable will be in ``target/release/solang``.
  132. .. _build-from-crates:
  133. Alternative step 2: Build Solang from crates.io
  134. _______________________________________________
  135. The latest Solang release is on `crates.io <https://crates.io/crates/solang>`_. Once you have the
  136. correct LLVM version in your path, simply run:
  137. .. code-block:: bash
  138. cargo install solang