Sitelet https://github.com/foundry-rs/compilers/commit/baa5018a9b7656fe30c12baa7032d2459c6867b9
Skip to content
This repository was archived by the owner on Apr 20, 2026. It is now read-only.

Commit baa5018

Browse files
committed
fix and add tests
1 parent a21275d commit baa5018

3 files changed

Lines changed: 46 additions & 8 deletions

File tree

‎crates/artifacts/solc/src/remappings.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,18 @@ impl fmt::Display for Remapping {
143143
}
144144
s.push(':');
145145
}
146+
let name =
147+
if !self.name.ends_with('/') { format!("{}/", self.name) } else { self.name.clone() };
146148
s.push_str(&{
147149
#[cfg(target_os = "windows")]
148150
{
149151
// ensure we have `/` slashes on windows
150152
use path_slash::PathExt;
151-
format!("{}={}", self.name, std::path::Path::new(&self.path).to_slash_lossy())
153+
format!("{}={}", name, std::path::Path::new(&self.path).to_slash_lossy())
152154
}
153155
#[cfg(not(target_os = "windows"))]
154156
{
155-
format!("{}={}", self.name, self.path)
157+
format!("{}={}", name, self.path)
156158
}
157159
});
158160

‎crates/compilers/src/report/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ mod tests {
492492
Unable to resolve imports:
493493
"./src/Import.sol" in "src/File.col"
494494
with remappings:
495-
oz=a/b/c/d/"#
495+
oz/=a/b/c/d/"#
496496
.trim()
497497
)
498498
}

‎crates/compilers/tests/project.rs‎

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ fn can_flatten_on_solang_failure() {
716716
r#"// SPDX-License-Identifier: UNLICENSED
717717
pragma solidity ^0.8.10;
718718
719-
library Lib {}
719+
library Lib {}
720720
"#,
721721
)
722722
.unwrap();
@@ -748,7 +748,7 @@ pragma solidity ^0.8.10;
748748
749749
// src/Lib.sol
750750
751-
library Lib {}
751+
library Lib {}
752752
753753
// src/Contract.sol
754754
@@ -2980,17 +2980,17 @@ fn can_parse_notice() {
29802980
29812981
/**
29822982
* @notice hello
2983-
*/
2983+
*/
29842984
constructor(string memory _greeting) public {
29852985
greeting = _greeting;
29862986
}
2987-
2987+
29882988
/**
29892989
* @notice hello
29902990
*/
29912991
function xyz() public {
29922992
}
2993-
2993+
29942994
/// @notice hello
29952995
function abc() public {
29962996
}
@@ -3986,3 +3986,39 @@ fn test_can_compile_multi() {
39863986
assert!(compiled.find(&root.join("src/Counter.vy"), "Counter").is_some());
39873987
compiled.assert_success();
39883988
}
3989+
3990+
// This is a reproduction of https://github.com/foundry-rs/compilers/issues/47
3991+
#[cfg(feature = "svm-solc")]
3992+
#[test]
3993+
fn remapping_trailing_slash_issue47() {
3994+
use std::sync::Arc;
3995+
3996+
use foundry_compilers_artifacts::{EvmVersion, Source, Sources};
3997+
3998+
let mut sources = Sources::new();
3999+
sources.insert(
4000+
PathBuf::from("./C.sol"),
4001+
Source {
4002+
content: Arc::new(r#"import "@project/D.sol"; contract C {}"#.to_string()),
4003+
kind: Default::default(),
4004+
},
4005+
);
4006+
sources.insert(
4007+
PathBuf::from("./D.sol"),
4008+
Source { content: Arc::new(r#"contract D {}"#.to_string()), kind: Default::default() },
4009+
);
4010+
4011+
let mut settings = Settings::default();
4012+
settings.evm_version = Some(EvmVersion::Byzantium);
4013+
settings.remappings.push(Remapping {
4014+
context: None,
4015+
name: "@project".into(),
4016+
path: ".".into(),
4017+
});
4018+
let input = SolcInput { language: SolcLanguage::Solidity, sources, settings };
4019+
println!("{:?}", serde_json::to_string(&input));
4020+
let compiler = Solc::find_or_install(&Version::new(0, 6, 8)).unwrap();
4021+
let output = compiler.compile_exact(&input).unwrap();
4022+
println!("{:?}", output.errors);
4023+
assert!(!output.has_error());
4024+
}

0 commit comments

Comments
 (0)