You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm assuming the canonical way to import .sol files from the instant project is by specifying either no relative import directory or by specifying "./", correct?
Well, it seems that if foundry.toml includes 'lib' in its libs = [...,'lib'] definition, then import resolution fails. I'm suspecting some kind of problem in the import resolution module that foundry may be providing to solc? Or some kind of remapping issue? Or a collision with the directory structure of some of the projects in lib/ ???
... something weird is happening where the import "./ImportedFile.sol"; fails as follows:
$ forge build --force
[⠊] Compiling...
[⠒] Compiling 51 files with 0.8.19
[⠆] Solc 0.8.19 finished in 28.34ms
Error:
Compiler run failed
error[6275]: ParserError: Source "lib/prb-contracts/src/ImportedFile.sol" not found: File not found. Searched the following locations: "/home/user/src/project/backend/contracts".
--> src/ContactDoingTheImport.sol:32:1:
|
32 | import "./ImportedFile.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... and after some spelunking, it appears that the issue is that prb-contracts contains a remappings.txt that defines:
src/=src/
So what I think is happening is that ./ImportedFile.sol is resolving to src/ImportedFile.sol relative to the project root, but then whatever foundry is doing with remapping.txt files is causing that to resolve to the prb-contracts content.
Should foundry be using remappings.txt from lib projects? Shouldn't those remappings be translated to be relative to lib/... if so?
Removing the src/=src/ from lib/prb-contacts/remappings.txt fixes the problem.
Also, I'm having trouble finding wherever it is that clarifies how the .toml remappings entry relates to remappings.txt, and how those may or may not be merged, which takes precedence etc. I might suggest that foundry generate a comment in the .toml about that, and/or support comments in remappings.txt and insert a similar comment there, so that noobs don't have to go searching for this information.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm assuming the canonical way to import .sol files from the instant project is by specifying either no relative import directory or by specifying "./", correct?
Well, it seems that if foundry.toml includes
'lib'
in itslibs = [...,'lib']
definition, then import resolution fails. I'm suspecting some kind of problem in the import resolution module that foundry may be providing to solc? Or some kind of remapping issue? Or a collision with the directory structure of some of the projects inlib/
???Basically, with
lib
defined in this toml:... something weird is happening where the
import "./ImportedFile.sol";
fails as follows:... and after some spelunking, it appears that the issue is that prb-contracts contains a
remappings.txt
that defines:So what I think is happening is that
./ImportedFile.sol
is resolving tosrc/ImportedFile.sol
relative to the project root, but then whatever foundry is doing with remapping.txt files is causing that to resolve to the prb-contracts content.Should foundry be using remappings.txt from lib projects? Shouldn't those remappings be translated to be relative to
lib/...
if so?Removing the
src/=src/
fromlib/prb-contacts/remappings.txt
fixes the problem.Also, I'm having trouble finding wherever it is that clarifies how the
.toml
remappings entry relates to remappings.txt, and how those may or may not be merged, which takes precedence etc. I might suggest that foundry generate a comment in the.toml
about that, and/or support comments in remappings.txt and insert a similar comment there, so that noobs don't have to go searching for this information.Filed as #4597
Beta Was this translation helpful? Give feedback.
All reactions