revive_solc_json_interface/standard_json/input/settings/
mod.rs

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