Skip to content
This repository was archived by the owner on Apr 20, 2026. It is now read-only.

Commit b0c9baf

Browse files
authored
fix: re-enable yul settings sanitization (#122)
Closes foundry-rs/foundry#7869
1 parent 3c86fdc commit b0c9baf

3 files changed

Lines changed: 38 additions & 34 deletions

File tree

src/artifacts/mod.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub(crate) type VersionedSources<C> = Vec<(C, Version, Sources)>;
5454
/// A set of different Solc installations with their version and the sources to be compiled
5555
pub(crate) type VersionedFilteredSources<C> = Vec<(C, Version, FilteredSources)>;
5656

57-
const SOLIDITY: &str = "Solidity";
58-
const YUL: &str = "Yul";
57+
pub const SOLIDITY: &str = "Solidity";
58+
pub const YUL: &str = "Yul";
5959

6060
/// Input type `solc` expects.
6161
#[derive(Clone, Debug, Serialize, Deserialize)]
@@ -89,25 +89,6 @@ impl SolcInput {
8989
self
9090
}
9191

92-
/// Sets the settings for compilation
93-
#[must_use]
94-
pub fn settings(mut self, mut settings: Settings) -> Self {
95-
if self.is_yul() {
96-
if !settings.remappings.is_empty() {
97-
warn!("omitting remappings supplied for the yul sources");
98-
settings.remappings = vec![];
99-
}
100-
if let Some(debug) = settings.debug.as_mut() {
101-
if debug.revert_strings.is_some() {
102-
warn!("omitting revertStrings supplied for the yul sources");
103-
debug.revert_strings = None;
104-
}
105-
}
106-
}
107-
self.settings = settings;
108-
self
109-
}
110-
11192
/// Sets the EVM version for compilation
11293
#[must_use]
11394
pub fn evm_version(mut self, version: EvmVersion) -> Self {
@@ -122,16 +103,6 @@ impl SolcInput {
122103
self
123104
}
124105

125-
#[must_use]
126-
pub fn with_remappings(mut self, remappings: Vec<Remapping>) -> Self {
127-
if self.is_yul() {
128-
warn!("omitting remappings supplied for the yul sources");
129-
} else {
130-
self.settings.remappings = remappings;
131-
}
132-
self
133-
}
134-
135106
/// Sets the path of the source files to `root` adjoined to the existing path
136107
#[must_use]
137108
pub fn join_path(mut self, root: impl AsRef<Path>) -> Self {

src/compilers/solc/mod.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use super::{
1111
use crate::{
1212
artifacts::{
1313
output_selection::OutputSelection, Error, Settings as SolcSettings, SolcInput, Sources,
14+
SOLIDITY, YUL,
1415
},
1516
error::Result,
1617
remappings::Remapping,
@@ -88,13 +89,24 @@ impl CompilerInput for SolcInput {
8889
let mut res = Vec::new();
8990
if !solidity_sources.is_empty() {
9091
res.push(Self {
91-
language: "Solidity".to_string(),
92+
language: SOLIDITY.to_string(),
9293
sources: solidity_sources,
9394
settings: settings.clone(),
9495
});
9596
}
9697
if !yul_sources.is_empty() {
97-
res.push(Self { language: "Yul".to_string(), sources: yul_sources, settings });
98+
if !settings.remappings.is_empty() {
99+
warn!("omitting remappings supplied for the yul sources");
100+
settings.remappings = vec![];
101+
}
102+
103+
if let Some(debug) = settings.debug.as_mut() {
104+
if debug.revert_strings.is_some() {
105+
warn!("omitting revertStrings supplied for the yul sources");
106+
debug.revert_strings = None;
107+
}
108+
}
109+
res.push(Self { language: YUL.to_string(), sources: yul_sources, settings });
98110
}
99111
res
100112
}
@@ -104,7 +116,13 @@ impl CompilerInput for SolcInput {
104116
}
105117

106118
fn with_remappings(mut self, remappings: Vec<Remapping>) -> Self {
107-
self.settings.remappings = remappings;
119+
if self.language == YUL {
120+
if !remappings.is_empty() {
121+
warn!("omitting remappings supplied for the yul sources");
122+
}
123+
} else {
124+
self.settings.remappings = remappings;
125+
}
108126
self
109127
}
110128

tests/project.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3852,3 +3852,18 @@ fn can_compile_vyper_with_cache() {
38523852
assert!(compiled.find_first("Counter").is_some());
38533853
assert!(!compiled.is_unchanged());
38543854
}
3855+
3856+
#[test]
3857+
fn yul_remappings_ignored() {
3858+
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test-data/yul-sample");
3859+
// Add dummy remapping.
3860+
let paths = ProjectPathsConfig::builder().sources(root.clone()).remapping(Remapping {
3861+
context: None,
3862+
name: "@openzeppelin".to_string(),
3863+
path: root.to_string_lossy().to_string(),
3864+
});
3865+
let project = TempProject::<ConfigurableArtifacts>::new(paths).unwrap();
3866+
3867+
let compiled = project.compile().unwrap();
3868+
compiled.assert_success();
3869+
}

0 commit comments

Comments
 (0)