foundry-rs / foundry-rs/foundry
bug(`remappings`): unable to import Solidity file using auto-remappings, missing src/ suffix
- Dominant language
- Rust
- Stars
- 10.6k
- Forks
- 2.6k
- Avg merge
- 18h 20m
- Merged PRs (30d)
- 510
Description
### Component
Forge
### Have you ensured that all of these are up to date?
- [X] Foundry
- [X] Foundryup
### What version of Foundry are you on?
forge 0.2.0 (388c3c0 2023-04-10T00:12:13.189631296Z)
### What command(s) is the bug in?
forge test
### Operating System
Linux
### Describe the bug
I need to compile contracts with multiple `solc` versions (0.6.x and 0.8.x).
I managed to do that successfully in my local environment like this:
```toml
# foundry.toml
[profile.default]
src = 'src'
out = 'out'
libs = ['lib']
compiler_version = '0.8.19'
optimizer = false
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
[profile.0_6_x]
# `src` must be different fot it to work.
# We also recommend putting all Solidity test files and scripts inside `src*/`.
src = 'src-0_6_x'
out = 'out'
# The order matters! When using `forge install` with FOUNDRY_PROFILE=0_6_x,
# it will use the first directory as the installation path.
# If the library is compatible with all versions,
# you can install it with the default profile.
libs = ['lib-0_6_x', 'lib']
optimizer = false
compiler_version = '0.6.12'
```
So my project root directory has a structure like this:
```
├── foundry.toml
├── lib
├── lib-0_6_x
├── src
└── src-0_6_x
```
My `.gitmodules` contains:
```
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/dss-test"]
path = lib/dss-test
url = https://github.com/makerdao/dss-test
[submodule "lib-0_6_x/dss-vest"]
path = lib-0_6_x/dss-vest
url = https://github.com/makerdao/dss-vest.git
```
And I have a `src-0_6_x/Imports.sol` file that imports the required files:
```solidity
// src-0_6_x/Imports.sol
pragma solidity =0.6.12;
import {DssVest, DssVestMintable} from "dss-vest/DssVest.sol";
```
When I run the following sequence of commands on my machine, it works flawlessly:
```bash
# build the 0.6.x contracts
FOUNDRY_PROFILE=0_6_x forge build
# build the 0.8.x contracts
forge build
# run the tests
forge test -vvv
```
---
I need this to run on CI through Github Actions, so I modified the sample `test.yml` file to look like this:
```yml
name: test
on:
push:
branches:
- master
pull_request:
branches:
- master
env:
FOUNDRY_PROFILE: ci
jobs:
check:
name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
###################################
# Additinal step added
###################################
- name: Run Forge build (solc 0.6.x)
env:
FOUNDRY_PROFILE: 0_6_x
run: |
forge --version
export FOUNDRY_PROFILE=0_6_x
FOUNDRY_PROFILE=0_6_x forge build --sizes
id: build_0_6_x
###################################
- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build
- name: Run Forge tests
run: |
forge test -vvv
id: test
```
The issue is that on CI the 0_6_x build step fails:
```
> Error:
> Failed to resolve file: "/home/runner/work/endgame-toolkit/endgame-toolkit/lib-0_6_x/dss-vest/DssVest.sol": No such file or directory (os error 2).
> Check configured remappings..
```
From the file above, you can see I tried to set `FOUNDRY_PROFILE` in 3 different ways. I tried them individually though and the result is the same. It seems to be picking the `src-0_6_x` directory as the source directory, but cannot find dependencies in `lib-0_6_x`.
Contributor guide
Assessment
This issue has not been assessed yet.