multiversx_sc_meta_lib/contract/sc_config/
contract_variant_settings.rs1mod contract_allocator;
2mod stack_size;
3
4pub use contract_allocator::{parse_allocator, ContractAllocator};
5pub use stack_size::*;
6
7use crate::{
8 ei::EIVersion,
9 tools::{self, OpcodeVersion, RustcVersion},
10};
11
12use super::ContractVariantProfileSerde;
13
14#[derive(Clone, PartialEq, Eq, Debug)]
16pub struct ContractVariantSettings {
17 pub external_view: bool,
19
20 pub panic_message: bool,
23
24 pub check_ei: Option<EIVersion>,
26
27 pub allocator: ContractAllocator,
29
30 pub stack_size: usize,
31
32 pub features: Vec<String>,
34
35 pub default_features: Option<bool>,
37
38 pub kill_legacy_callback: bool,
40
41 pub profile: ContractVariantProfile,
42
43 pub std: bool,
45
46 pub rustc_version: RustcVersion,
48
49 pub rustc_target: String,
51
52 pub opcode_version: OpcodeVersion,
53
54 pub wasm_opt_version: Option<String>,
56}
57
58impl Default for ContractVariantSettings {
59 fn default() -> Self {
60 ContractVariantSettings {
61 external_view: Default::default(),
62 panic_message: Default::default(),
63 check_ei: Some(EIVersion::default()),
64 allocator: Default::default(),
65 stack_size: DEFAULT_STACK_SIZE,
66 features: Default::default(),
67 default_features: None,
68 kill_legacy_callback: false,
69 profile: Default::default(),
70 std: false,
71 rustc_version: RustcVersion::current_version(),
72 rustc_target: tools::build_target::default_target().to_owned(),
73 opcode_version: OpcodeVersion::default(),
74 wasm_opt_version: None,
75 }
76 }
77}
78
79#[derive(Clone, PartialEq, Eq, Debug)]
80pub struct ContractVariantProfile {
81 pub codegen_units: u8,
82 pub opt_level: String,
83 pub lto: bool,
84 pub debug: bool,
85 pub panic: String,
86 pub overflow_checks: bool,
87}
88
89impl Default for ContractVariantProfile {
90 fn default() -> ContractVariantProfile {
91 ContractVariantProfile {
92 codegen_units: 1u8,
93 opt_level: "z".to_owned(),
94 lto: true,
95 debug: false,
96 panic: "abort".to_owned(),
97 overflow_checks: false,
98 }
99 }
100}
101
102impl ContractVariantProfile {
103 pub fn from_serde(opt_serde_profile: &Option<ContractVariantProfileSerde>) -> Self {
104 let mut result = Self::default();
105 if let Some(serde_profile) = opt_serde_profile {
106 if let Some(codegen_units) = serde_profile.codegen_units {
107 result.codegen_units = codegen_units;
108 }
109 if let Some(opt_level) = &serde_profile.opt_level {
110 result.opt_level.clone_from(opt_level);
111 }
112 if let Some(lto) = serde_profile.lto {
113 result.lto = lto;
114 }
115 if let Some(debug) = serde_profile.debug {
116 result.debug = debug;
117 }
118 if let Some(panic) = &serde_profile.panic {
119 result.panic.clone_from(panic);
120 }
121 if let Some(overflow_checks) = serde_profile.overflow_checks {
122 result.overflow_checks = overflow_checks;
123 }
124 }
125 result
126 }
127}