running.rst 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. Using Solang on the command line
  2. ================================
  3. The Solang compiler is run on the command line. The solidity source file
  4. names are provided as command line arguments; the output is an optimized
  5. wasm or bpf file which is ready for deployment on a chain, and an metadata
  6. file (also known as the abi).
  7. The following targets are supported right now:
  8. `Solana <https://www.solana.com/>`_ and
  9. `Parity Substrate <https://substrate.io/>`_.
  10. Solang supports auto-completion for multiple shells. Use ``solang shell-complete --help`` to
  11. learn whether your favorite shell is supported. If so, evaluate the output of
  12. ``solang shell-complete <SHELL>`` in order to activate it. Example installation with ``bash``:
  13. .. code-block:: bash
  14. echo 'source <(solang shell-complete bash)' >> ~/.bashrc
  15. Compiler Usage
  16. ______________
  17. solang compile [OPTIONS]... [SOLIDITY SOURCE FILE]...
  18. This means that the command line is ``solang compile`` followed by any options described below,
  19. followed by one or more solidity source filenames.
  20. Options:
  21. -v, \-\-verbose
  22. Make the output more verbose. The compiler tell you what contracts have been
  23. found in the source, and what files are generated. Without this option Solang
  24. will be silent if there are no errors or warnings.
  25. \-\-target *target*
  26. This takes one argument, which can either be ``solana`` or ``substrate``. The target
  27. must be specified.
  28. \-\-address\-length *length-in-bytes*
  29. Change the default address length on Substrate. By default, Substate uses an address type of 32 bytes. This option
  30. is ignored for any other target.
  31. \-\-value\-length *length-in-bytes*
  32. Change the default value length on Substrate. By default, Substate uses an value type of 16 bytes. This option
  33. is ignored for any other target.
  34. -o, \-\-output *directory*
  35. This option takes one argument, which is the directory where output should
  36. be saved. The default is the current directory.
  37. -O *optimization level*
  38. This takes one argument, which can either be ``none``, ``less``, ``default``,
  39. or ``aggressive``. These correspond to llvm optimization levels.
  40. \-\-importpath *directory*
  41. When resolving ``import`` directives, search this directory. By default ``import``
  42. will only search the current directory. This option can be specified multiple times
  43. and the directories will be searched in the order specified.
  44. \-\-importmap *map=directory*
  45. When resolving ``import`` directives, if the first part of the path matches *map*,
  46. search the directory provided for the file. This option can be specified multiple times
  47. with different values for map.
  48. \-\-help, -h
  49. This displays a short description of all the options
  50. \-\-standard-json
  51. This option causes Solang to emulate the behaviour of Solidity
  52. `standard json output <https://solidity.readthedocs.io/en/v0.5.13/using-the-compiler.html#output-description>`_. No output files are written, all the
  53. output will be in json on stdout.
  54. \-\-emit *phase*
  55. This option is can be used for debugging Solang itself. This is used to
  56. output early phases of compilation.
  57. Phase:
  58. ast-dot
  59. Output Abstract Syntax Tree as a graphviz dot file. This can be viewed with xdot
  60. or any other tool that can visualize graphviz dot files.
  61. cfg
  62. Output control flow graph.
  63. llvm-ir
  64. Output llvm IR as text.
  65. llvm-bc
  66. Output llvm bitcode as binary file.
  67. asm
  68. Output assembly text file.
  69. object
  70. Output wasm object file; this is the contract before final linking.
  71. \-\-no\-constant\-folding
  72. Disable the :ref:`constant-folding` codegen optimization
  73. \-\-no\-strength\-reduce
  74. Disable the :ref:`strength-reduce` codegen optimization
  75. \-\-no\-dead\-storage
  76. Disable the :ref:`dead-storage` optimization
  77. \-\-no\-vector\-to\-slice
  78. Disable the :ref:`vector-to-slice` optimization
  79. \-\-no\-cse
  80. Disable the :ref:`common-subexpression-elimination` optimization
  81. \-\-log\-api\-return\-codes
  82. Disable the :ref:`common-subexpression-elimination` optimization
  83. Generating Documentation Usage
  84. ______________________________
  85. Generate documentation for the given Solidity files as a single html page. This uses the
  86. doccomment tags. The result is saved in ``soldoc.html``. See :ref:`tags` for
  87. further information.
  88. solang doc [OPTIONS]... [SOLIDITY SOURCE FILE]...
  89. This means that the command line is ``solang doc`` followed by any options described below,
  90. followed by one or more solidity source filenames.
  91. Options:
  92. \-\-target *target*
  93. This takes one argument, which can either be ``solana`` or ``substrate``. The target
  94. must be specified.
  95. \-\-address\-length *length-in-bytes*
  96. Change the default address length on Substrate. By default, Substate uses an address type of 32 bytes. This option
  97. is ignored for any other target.
  98. \-\-value\-length *length-in-bytes*
  99. Change the default value length on Substrate. By default, Substate uses an value type of 16 bytes. This option
  100. is ignored for any other target.
  101. \-\-importpath *directory*
  102. When resolving ``import`` directives, search this directory. By default ``import``
  103. will only search the current directory. This option can be specified multiple times
  104. and the directories will be searched in the order specified.
  105. \-\-importmap *map=directory*
  106. When resolving ``import`` directives, if the first part of the path matches *map*,
  107. search the directory provided for the file. This option can be specified multiple times
  108. with different values for map.
  109. \-\-help, -h
  110. This displays a short description of all the options
  111. .. _idl_command:
  112. Generate Solidity interface from IDL
  113. ____________________________________
  114. This command converts Anchor IDL into Solidity import files, so they can be used to call
  115. Anchor Programs from Solidity.
  116. solang idl [--output DIR] [IDLFILE]...
  117. For each idl file provided, a Solidity file is written. See :ref:`call_anchor`
  118. for an example of how to use this.
  119. .. note::
  120. There is only supported on Solana.
  121. Running Solang using a container
  122. ________________________________
  123. First pull the last Solang container from
  124. `solang containers <https://github.com/hyperledger/solang/pkgs/container/solang>`_:
  125. .. code-block:: bash
  126. docker image pull ghcr.io/hyperledger/solang
  127. And if you are using podman:
  128. .. code-block:: bash
  129. podman image pull ghcr.io/hyperledger/solang
  130. Now you can run Solang like so:
  131. .. code-block:: bash
  132. docker run --rm -it ghcr.io/hyperledger/solang --version
  133. Or podman:
  134. .. code-block:: bash
  135. podman container run --rm -it ghcr.io/hyperledger/solang --version
  136. If you want to compile some Solidity files, the source files need to be
  137. available inside the container. You can do this via the ``-v`` docker command line.
  138. In this example ``/local/path`` should be replaced with the absolute path
  139. to your solidity files:
  140. .. code-block:: bash
  141. docker run --rm -it -v /local/path:/sources ghcr.io/hyperledger/solang compile -o /sources /sources/flipper.sol
  142. On Windows, you need to specify absolute paths:
  143. .. code-block:: text
  144. docker run --rm -it -v C:\Users\User:/sources ghcr.io/hyperledger/solang compile -o /sources /sources/flipper.sol