Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read compiler configurations from toml #1347

Merged
merged 13 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ scale-info = "2.4"
petgraph = "0.6.3"
wasmparser = "0.106.0"
wasm-encoder = "0.28"
toml = "0.7"
wasm-opt = { version = "0.112.0", optional = true }
contract-build = { version = "3.0.1", optional = true }

Expand Down
35 changes: 35 additions & 0 deletions docs/running.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ Options:
\-\-release
Disable all debugging features for :ref:`release`

\-\-config-file
Read compiler configurations from a ``.toml`` file. The minimal fields required in the configuration file are:

.. code-block:: toml

[package]
input_files = ["flipper.sol"] # Solidity files to compile

[target]
name = "solana" # Target name


Fields not explicitly present in the .toml acquire the compiler's default value.
If any other argument is provided in the command line, for example, ``solang compile --config-file --target substrate``, the argument will be overridden.
The priority for the args is given as follows:
1. Command line
2. Configuration file
3. Default values.
The default name for the toml file is "solang.toml". If two configuration files exist in the same directory, priority will be given to the one passed explicitly to this argument.

\-\-wasm-opt
wasm-opt passes for Wasm targets (0, 1, 2, 3, 4, s or z; see the wasm-opt help for more details).

Expand All @@ -142,6 +162,21 @@ Options:
Solang will not give a warning about this problem.



Starting a new project
______________________________


solang new \-\-target solana my_project

A solang project is a directory in which there are one or more solidity files and a ``solang.toml`` file where
the compilation options are defined. Given these two components, a user can run ``solang compile`` in a similar fashion as ``cargo build``.

The ``solang new`` command creates a new solang project with an example `flipper <https://github.com/hyperledger/solang/blob/main/examples/solana/flipper.sol>`_ contract,
and a default ``solang.toml`` configuration file.



Generating Documentation Usage
______________________________

Expand Down
2 changes: 1 addition & 1 deletion examples/solana/flipper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ contract flipper {

/// Constructor that initializes the `bool` value to the given `init_value`.
@payer(payer)
constructor(address payer, bool initvalue) {
constructor(bool initvalue) {
value = initvalue;
}

Expand Down
29 changes: 29 additions & 0 deletions examples/solana/solana_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
input_files = ["flipper.sol"] # Files to be compiled. You can define multiple files as : input_files = ["file1", "file2", ..]
contracts = ["flipper"] # Contracts to include from the compiled files
import_path = []
import_map = {} # Maps to import. Define as import_map = {map = "path/to/map1", map2 = "path/to/map2"}


[target]
name = "solana" # Valid targets are "solana" and "substrate"

[debug-features]
prints = true # Log debug prints to the environment.
log-runtime-errors = true # Log runtime errors to the environment.
generate-debug-info = false # Add debug info to the generated llvm IR.

[optimizations]
dead-storage = true
constant-folding = true
strength-reduce = true
vector-to-slice = true
common-subexpression-elimination = true
llvm-IR-optimization-level = "default" # Set llvm optimizer level. Valid options are "none", "less", "default", "aggressive"

[compiler-output]
verbose = false # show debug messages
#emit = "llvm-ir" # Emit compiler state at early stage. Valid options are: "ast-dot", "cfg", "llvm-ir", "llvm-bc", "object", "asm".
#output_directory = "path/to/dir"
#output_meta = "path/to/dir" # output directory for metadata
std_json_output = false # mimic solidity json output on stdout
32 changes: 32 additions & 0 deletions examples/substrate/substrate_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
input_files = ["flipper.sol"] # Files to be compiled. You can define multiple files as : input_files = ["file1", "file2", ..]
contracts = ["flipper"] # Contracts to include from the compiled files
import_path = []
import_map = {} # Maps to import. Define as import_map = {map = "path/to/map1", map2 = "path/to/map2"}


[target]
name = "substrate" # Valid targets are "solana" and "substrate"
address_length = 32
value_length = 16


[debug-features]
prints = true # Log debug prints to the environment.
log-runtime-errors = true # Log runtime errors to the environment.
generate-debug-info = false # Add debug info to the generated llvm IR.

[optimizations]
dead-storage = true
constant-folding = true
strength-reduce = true
vector-to-slice = true
common-subexpression-elimination = true
llvm-IR-optimization-level = "default" # Set llvm optimizer level. Valid options are "none", "less", "default", "aggressive"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not apply to llvm-IR only, also to target specific machine code. This should be called llvm-optimization-level


Comment on lines +25 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIY I just merged #1365, could you include that here too?

[compiler-output]
verbose = false # show debug messages
#emit = "llvm-ir" # Emit compiler state at early stage. Valid options are: "ast-dot", "cfg", "llvm-ir", "llvm-bc", "object", "asm".
#output_directory = "path/to/dir"
#output_meta = "path/to/dir" # output directory for metadata
std_json_output = false # mimic solidity json output on stdout
Loading
Loading