mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-15 09:11:04 +00:00
Separate compilation and linker phases (#376)
Separate between compilation and linker phases to allow deploy time linking and back-porting era compiler changes to fix #91. Unlinked contract binaries (caused by missing libraries or missing factory dependencies in turn) are emitted as raw ELF object. Few drive by fixes: - #98 - A compiler panic on missing libraries definitions. - Fixes some incosistent type forwarding in JSON output (empty string vs. null object). - Remove the unused fallback for size optimization setting. - Remove the broken `--lvm-ir` mode. - CI workflow fixes. --------- Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com> Signed-off-by: xermicus <bigcyrill@hotmail.com> Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
@@ -7,24 +7,33 @@ use std::collections::BTreeMap;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use self::file::flag::Flag;
|
||||
use self::file::File as FileSelection;
|
||||
|
||||
/// The `solc --standard-json` output selection.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq)]
|
||||
pub struct Selection {
|
||||
/// Only the 'all' wildcard is available for robustness reasons.
|
||||
#[serde(rename = "*", skip_serializing_if = "Option::is_none")]
|
||||
all: Option<FileSelection>,
|
||||
#[serde(default, rename = "*", skip_serializing_if = "FileSelection::is_empty")]
|
||||
all: FileSelection,
|
||||
|
||||
#[serde(skip_serializing_if = "BTreeMap::is_empty", flatten)]
|
||||
pub files: BTreeMap<String, FileSelection>,
|
||||
}
|
||||
|
||||
impl Selection {
|
||||
/// Creates the selection with arbitrary flags.
|
||||
pub fn new(flags: Vec<Flag>) -> Self {
|
||||
Self {
|
||||
all: FileSelection::new(flags),
|
||||
files: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates the selection required by our compilation process.
|
||||
pub fn new_required() -> Self {
|
||||
Self {
|
||||
all: Some(FileSelection::new_required()),
|
||||
all: FileSelection::new_required(),
|
||||
files: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
@@ -32,76 +41,35 @@ impl Selection {
|
||||
/// Creates the selection required for test compilation (includes EVM bytecode).
|
||||
pub fn new_required_for_tests() -> Self {
|
||||
Self {
|
||||
all: Some(FileSelection::new_required_for_tests()),
|
||||
all: FileSelection::new_required_for_tests(),
|
||||
files: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Extends the user's output selection with flag required by our compilation process.
|
||||
pub fn extend_with_required(&mut self) -> &mut Self {
|
||||
self.all
|
||||
.get_or_insert_with(FileSelection::new_required)
|
||||
.extend_with_required();
|
||||
for (_, v) in self.files.iter_mut() {
|
||||
v.extend_with_required();
|
||||
}
|
||||
/// Creates the selection required by Yul validation process.
|
||||
pub fn new_yul_validation() -> Self {
|
||||
Self::new(vec![Flag::EVM])
|
||||
}
|
||||
|
||||
/// Extends the output selection with another one.
|
||||
pub fn extend(&mut self, other: Self) -> &mut Self {
|
||||
self.all.extend(other.all);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::SolcStandardJsonInputSettingsSelectionFile;
|
||||
|
||||
use super::Selection;
|
||||
|
||||
#[test]
|
||||
fn per_file() {
|
||||
let init = Selection {
|
||||
all: None,
|
||||
files: BTreeMap::from([(
|
||||
"Test".to_owned(),
|
||||
SolcStandardJsonInputSettingsSelectionFile::new_required(),
|
||||
)]),
|
||||
};
|
||||
|
||||
let deser = serde_json::to_string(&init)
|
||||
.and_then(|string| serde_json::from_str(&string))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(init, deser)
|
||||
/// Returns flags that are going to be automatically added by the compiler,
|
||||
/// but were not explicitly requested by the user.
|
||||
///
|
||||
/// Afterwards, the flags are used to prune JSON output before returning it.
|
||||
pub fn selection_to_prune(&self) -> Self {
|
||||
Self {
|
||||
all: self.all.selection_to_prune(),
|
||||
files: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all() {
|
||||
let init = Selection {
|
||||
all: Some(SolcStandardJsonInputSettingsSelectionFile::new_required()),
|
||||
files: BTreeMap::new(),
|
||||
};
|
||||
|
||||
let deser = serde_json::to_string(&init)
|
||||
.and_then(|string| serde_json::from_str(&string))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(init, deser)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_and_override() {
|
||||
let init = Selection {
|
||||
all: Some(SolcStandardJsonInputSettingsSelectionFile::new_required()),
|
||||
files: BTreeMap::from([(
|
||||
"Test".to_owned(),
|
||||
SolcStandardJsonInputSettingsSelectionFile::new_required(),
|
||||
)]),
|
||||
};
|
||||
|
||||
let deser = serde_json::to_string(&init)
|
||||
.and_then(|string| serde_json::from_str(&string))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(init, deser)
|
||||
/// Whether the flag is requested.
|
||||
pub fn contains(&self, flag: &Flag) -> bool {
|
||||
self.all.contains(flag)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user