installing.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. Installing Solang
  2. =================
  3. The solang compiler is a single binary. It can be installed in many different
  4. ways, so please pick whatever method suits your needs.
  5. Using hyperledgerlabs/solang docker hub images
  6. ----------------------------------------------
  7. Simply pull the latest docker image using::
  8. docker pull hyperledgerlabs/solang
  9. And if you are using podman::
  10. podman image pull hyperlederlabs/solang
  11. The solang binary is in ``/usr/bin/solang`` in this image. The latest tag
  12. gets updated each time there is a commit to the master branch of the solang
  13. git repository.
  14. Build solang from source using Dockerfile
  15. -----------------------------------------
  16. First clone the git repo using::
  17. git clone https://github.com/hyperledger-labs/solang
  18. Then you can build the image using::
  19. docker build .
  20. Alternatively this will work with podman too::
  21. podman image build .
  22. Building solang from source using cargo
  23. ---------------------------------------
  24. solang is listed on `crates.io <https://crates.io/crates/solang>`_. Only
  25. releases are pushed to cargo. Do install using cargo::
  26. cargo install solang
  27. You will need the llvm libraries for this to work, see
  28. `Getting the right version of LLVM`_.
  29. Building solang from source
  30. ---------------------------
  31. In order to build solang from source, you will need rust 1.33.0 or higher,
  32. and llvm version 8 or higher with the WebAssembly target enabled.
  33. So see if you have the correct version of rust, simply execute::
  34. rustc --version
  35. If you do not have the correct version of rust installed, go to `rustup <https://rustup.rs/>`_.
  36. To make sure you have the correct version of the llvm libraries installed, first run::
  37. llvm-config --version
  38. The output should be 8.0 or higher. Then check if the WebAssembly target is enabled by running::
  39. llc --version
  40. You should see wasm32 listed under the target. Lastly check that the static libraries are installed::
  41. llvm-version --link-static --libs
  42. If there is no output, there are no static llvm libraries and building will fail.
  43. After making sure llvm and rust are installed, just run::
  44. cargo build --release
  45. The executable will be in ``target/release/solang``.
  46. Getting the right version of LLVM
  47. ---------------------------------
  48. If you did not have the llvm libraries installed then you can either install
  49. your systems llvm packages or compile your own. Compiling your own is helpful
  50. if you want to do solang development.
  51. Any version from llvm 8.0 will do. Note that you will also need clang; the
  52. Solidity standard library is written in C, and is compiled to wasm by
  53. clang. For this to work, the version of clang **must** be the same as the
  54. version of llvm.
  55. Installing LLVM on Ubuntu
  56. _________________________
  57. You will need ubuntu 18.04 with backports or later. Just run::
  58. sudo apt install curl llvm clang git zlib1g-dev cargo
  59. Installing LLVM on Fedora
  60. _________________________
  61. You will need Fedora 30 or later. Running the following::
  62. sudo dnf install cargo llvm8.0-static llvm8.0-devel zlib-devel clang
  63. Installing LLVM from source
  64. ___________________________
  65. If your system does not come with llvm, then you have to build your own.
  66. Building your own llvm libraries does not interfere with any llvm libraries
  67. installed by your distribution.
  68. The llvm project is a large code base so it will take some time to build.
  69. If you are planning to do development on solang itself, then having your
  70. own built llvm is very helpful. The distributions build llvm without
  71. assertions enabled. These assertions check that the IR that solang builds
  72. is correct. If the IR is not correct, then faults might happen when llvm
  73. runs compiler passes on the IR and the stack trace will not be useful
  74. to debug this problem.
  75. The llvm project itself has a guide to `installing from source <http://www.llvm.org/docs/CMake.html>`_ which you may need to consult.
  76. First if all clone the llvm repository::
  77. git clone https://github.com/llvm/llvm-project
  78. cd llvm-project
  79. Now switch to the 8.0 release branch::
  80. git checkout -b release_8.x origin/release/8.x
  81. Ensure that clang will built::
  82. ln -s clang llvm/tools/clang
  83. Create a directory where the build and intermediate files will be stored::
  84. mkdir build
  85. cd build
  86. 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::
  87. cmake -G Ninja -DLLVM_TARGETS_TO_BUILD=WebAssembly -DLLVM_ENABLE_ASSERTIONS=On -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=installdir ../llvm
  88. cmake --build . --target install
  89. Once the build has succeeded, the *installdir*/bin has to be added to your path so the solang build can find this llvm config:
  90. export PATH=*installdir*/bin:$PATH