foundry_compilers/compilers/vyper/
settings.rs

1use std::{collections::BTreeSet, path::PathBuf};
2
3pub use crate::artifacts::vyper::VyperSettings;
4use crate::{
5    compilers::{restrictions::CompilerSettingsRestrictions, CompilerSettings},
6    solc::Restriction,
7};
8use foundry_compilers_artifacts::{output_selection::OutputSelection, EvmVersion};
9
10#[derive(Clone, Copy, Debug, Default)]
11pub struct VyperRestrictions {
12    pub evm_version: Restriction<EvmVersion>,
13}
14
15impl CompilerSettingsRestrictions for VyperRestrictions {
16    fn merge(self, other: Self) -> Option<Self> {
17        Some(Self { evm_version: self.evm_version.merge(other.evm_version)? })
18    }
19}
20
21impl CompilerSettings for VyperSettings {
22    type Restrictions = VyperRestrictions;
23
24    fn update_output_selection(&mut self, f: impl FnOnce(&mut OutputSelection)) {
25        f(&mut self.output_selection)
26    }
27
28    fn can_use_cached(&self, other: &Self) -> bool {
29        let Self {
30            evm_version,
31            optimize,
32            bytecode_metadata,
33            output_selection,
34            search_paths,
35            experimental_codegen,
36        } = self;
37        evm_version == &other.evm_version
38            && optimize == &other.optimize
39            && bytecode_metadata == &other.bytecode_metadata
40            && output_selection.is_subset_of(&other.output_selection)
41            && search_paths == &other.search_paths
42            && experimental_codegen == &other.experimental_codegen
43    }
44
45    fn with_include_paths(mut self, include_paths: &BTreeSet<PathBuf>) -> Self {
46        self.search_paths = Some(include_paths.clone());
47        self
48    }
49
50    fn satisfies_restrictions(&self, restrictions: &Self::Restrictions) -> bool {
51        restrictions.evm_version.satisfies(self.evm_version)
52    }
53}