Skip to main content

revive_solc_json_interface/standard_json/input/settings/
mod.rs

1//! The `solc --standard-json` input settings.
2
3pub mod debug;
4pub mod libraries;
5pub mod metadata;
6pub mod metadata_hash;
7pub mod optimizer;
8pub mod polkavm;
9pub mod revert_strings;
10pub mod selection;
11#[cfg(feature = "resolc")]
12pub mod warning;
13
14use serde::Deserialize;
15use serde::Serialize;
16
17use self::debug::Debug;
18use self::libraries::Libraries;
19use self::metadata::Metadata;
20use self::optimizer::Optimizer;
21use self::polkavm::PolkaVM;
22use self::selection::Selection;
23#[cfg(feature = "resolc")]
24use self::warning::Warning;
25
26/// The `solc --standard-json` input settings.
27#[derive(Clone, Debug, Serialize, Deserialize)]
28#[serde(rename_all = "camelCase")]
29pub struct Settings {
30    /// The target EVM version.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub evm_version: Option<revive_common::EVMVersion>,
33    /// The linker library addresses.
34    #[serde(default, skip_serializing_if = "Libraries::is_empty")]
35    pub libraries: Libraries,
36    /// The list of remappings, in the order given.
37    #[serde(default, skip_serializing_if = "Vec::is_empty")]
38    pub remappings: Vec<String>,
39    /// The output selection filters.
40    #[serde(default)]
41    pub output_selection: Selection,
42    /// Whether to compile via IR. Only for testing with solc >=0.8.13.
43    #[serde(
44        rename = "viaIR",
45        skip_serializing_if = "Option::is_none",
46        skip_deserializing
47    )]
48    pub via_ir: Option<bool>,
49    /// The optimizer settings.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub optimizer: Option<Optimizer>,
52    /// The metadata settings.
53    #[serde(default)]
54    pub metadata: Metadata,
55    /// The debugging settings.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub debug: Option<Debug>,
58    /// The resolc custom PolkaVM settings.
59    #[serde(default, skip_serializing)]
60    pub polkavm: PolkaVM,
61
62    /// The suppressed warnings.
63    #[cfg(feature = "resolc")]
64    #[serde(default, skip_serializing)]
65    pub suppressed_warnings: Vec<self::warning::Warning>,
66
67    /// The extra LLVM arguments.
68    #[cfg(feature = "resolc")]
69    #[serde(default, alias = "LLVMOptions", skip_serializing)]
70    pub llvm_arguments: Vec<String>,
71
72    /// Whether to enable the missing libraries detection mode.
73    /// Deprecated in favor of post-compile-time linking.
74    #[serde(default, rename = "detectMissingLibraries", skip_serializing)]
75    pub detect_missing_libraries: bool,
76}
77
78#[cfg(feature = "resolc")]
79impl Settings {
80    /// A shortcut constructor.
81    pub fn new(
82        evm_version: Option<revive_common::EVMVersion>,
83        libraries: Libraries,
84        remappings: Vec<String>,
85        output_selection: Selection,
86        optimizer: Optimizer,
87        metadata: Metadata,
88        debug: Option<Debug>,
89        polkavm: PolkaVM,
90        suppressed_warnings: Vec<Warning>,
91        llvm_arguments: Vec<String>,
92        detect_missing_libraries: bool,
93    ) -> Self {
94        Self {
95            evm_version,
96            libraries,
97            remappings,
98            output_selection,
99            optimizer: Some(optimizer),
100            metadata,
101            via_ir: Some(true),
102            debug,
103            polkavm,
104            suppressed_warnings,
105            llvm_arguments,
106            detect_missing_libraries,
107        }
108    }
109
110    /// Extends the output selection with another one.
111    pub fn extend_selection(&mut self, selection: Selection) {
112        self.output_selection.extend(selection);
113    }
114
115    /// Returns flags that are going to be automatically added by the compiler,
116    /// but were not explicitly requested by the user.
117    ///
118    /// Afterwards, the flags are used to prune JSON output before returning it.
119    pub fn selection_to_prune(&self) -> Selection {
120        self.output_selection.selection_to_prune()
121    }
122
123    /// Removes unneeded selections.
124    pub fn retain_output_selection(&mut self) {
125        self.output_selection.retain();
126    }
127}