installing.rst 7.0 KB

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