installing.rst 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.0/solang-linux-x86-64>`_
  21. - `Linux arm64 <https://github.com/hyperledger/solang/releases/download/v0.2.0/solang-linux-arm64>`_
  22. - `Windows x64 <https://github.com/hyperledger/solang/releases/download/v0.2.0/solang.exe>`_
  23. - `MacOS intel <https://github.com/hyperledger/solang/releases/download/v0.2.0/solang-mac-intel>`_
  24. - `MacOS arm <https://github.com/hyperledger/solang/releases/download/v0.2.0/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.0` 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.0>`_
  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.0/llvm13.0-linux-x86-64.tar.xz>`_.
  80. After downloading, untar the file in a terminal and add it to your path.
  81. .. code-block:: bash
  82. tar Jxf llvm13.0-linux-x86-64.tar.xz
  83. export PATH=$(pwd)/llvm13.0/bin:$PATH
  84. Windows
  85. ~~~~~~~
  86. A pre-built version of LLVM, specifically configured for Solang, is available at
  87. `<https://github.com/hyperledger/solang/releases/download/v0.2.0/llvm13.0-win.zip>`_.
  88. After unzipping the file, add the bin directory to your path.
  89. .. code-block:: batch
  90. set PATH=%PATH%;C:\llvm13.0\bin
  91. Mac
  92. ~~~
  93. A pre-built version of LLVM for intel macs, is available at
  94. `<https://github.com/hyperledger/solang/releases/download/v0.2.0/llvm13.0-mac-intel.tar.xz>`_ and for arm macs there is
  95. `<https://github.com/hyperledger/solang/releases/download/v0.2.0/llvm13.0-mac-arm.tar.xz>`_. After downloading,
  96. untar the file in a terminal and add it to your path like so:
  97. .. code-block:: bash
  98. tar Jxf llvm13.0-mac-arm.tar.xz
  99. xattr -rd com.apple.quarantine llvm13.0
  100. export PATH=$(pwd)/llvm13.0/bin:$PATH
  101. .. _llvm-from-source:
  102. Building LLVM from source
  103. ~~~~~~~~~~~~~~~~~~~~~~~~~
  104. The LLVM project itself has a guide to `installing from source <http://www.llvm.org/docs/CMake.html>`_ which
  105. you may need to consult. First if all clone our LLVM repository:
  106. .. code-block:: bash
  107. git clone --depth 1 --branch solana-rustc/13.0-2021-08-08 https://github.com/solana-labs/llvm-project
  108. cd llvm-project
  109. 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:
  110. .. code-block:: bash
  111. cmake -G Ninja -DLLVM_ENABLE_ASSERTIONS=On '-DLLVM_ENABLE_PROJECTS=clang;lld' \
  112. -DLLVM_ENABLE_TERMINFO=Off -DCMAKE_BUILD_TYPE=Release \
  113. -DCMAKE_INSTALL_PREFIX=installdir -B build llvm
  114. cmake --build build --target install
  115. Once the build has succeeded, the *installdir*/bin has to be added to your path so the
  116. Solang build can find the ``llvm-config`` from this build:
  117. .. code-block:: bash
  118. export PATH=installdir/bin:$PATH
  119. And on Windows, assuming *installdir* was ``C:\Users\User\solang-llvm``:
  120. .. code-block:: batch
  121. set PATH=%PATH%;C:\Users\User\solang-llvm\bin
  122. .. _build-from-source:
  123. Step 2: Build Solang
  124. ____________________
  125. Once you have the correct LLVM version in your path, simply run:
  126. .. code-block:: bash
  127. git clone https://github.com/hyperledger/solang/
  128. cd solang
  129. cargo build --release
  130. The executable will be in ``target/release/solang``.
  131. .. _build-from-crates:
  132. Alternative step 2: Build Solang from crates.io
  133. _______________________________________________
  134. The latest Solang release is on `crates.io <https://crates.io/crates/solang>`_. Once you have the
  135. correct LLVM version in your path, simply run:
  136. .. code-block:: bash
  137. cargo install solang