Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(remappings): unable to import Solidity file using auto-remappings, missing src/ suffix #4717

Open
2 tasks done
Tracked by #9157
amusingaxl opened this issue Apr 10, 2023 · 4 comments · May be fixed by #9263
Open
2 tasks done
Tracked by #9157

bug(remappings): unable to import Solidity file using auto-remappings, missing src/ suffix #4717

amusingaxl opened this issue Apr 10, 2023 · 4 comments · May be fixed by #9263
Labels
A-compiler Area: compiler A-remappings Area: remappings C-forge Command: forge Cmd-forge-build Command: forge build P-normal Priority: normal T-bug Type: bug
Milestone

Comments

@amusingaxl
Copy link

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • 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:

# 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:

// 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:

# 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:

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.

@amusingaxl amusingaxl added the T-bug Type: bug label Apr 10, 2023
@gakonst gakonst added this to Foundry Apr 10, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Apr 10, 2023
@amusingaxl
Copy link
Author

Interesting... I deleted the repository from my local machine and cloned it again.

At first, git clone --recurse-submodules didn't work properly and didn't install lib-0_6_x/dss-vest.

I ran:

git submodule update --init --recursive

And the dependency was installed.

Now if I try to run:

FOUNDRY_PROFILE=0_6_x forge build

I get the same error as CI:

Failed to resolve file: "PROJECT_ROOT/lib-0_6_x/dss-vest/DssVest.sol": No such file or directory (os error 2).
 Check configured remappings..
    --> "PROJECT_ROOT/src-0_6_x/Imports.sol"
        "dss-vest/DssVest.sol"

Apparently the path is wrong: "PROJECT_ROOT/lib-0_6_x/dss-vest/DssVest.sol" should be "PROJECT_ROOT/lib-0_6_x/dss-vest/src/DssVest.sol".

@amusingaxl
Copy link
Author

Apparently there's something wrong with the auto-remappings:

FOUNDRY_PROFILE=0_6_x forge remappings gives me:

ds-test/=lib/forge-std/lib/ds-test/src/
dss-interfaces/=lib/dss-test/lib/dss-interfaces/src/
dss-test/=lib/dss-test/src/
dss-vest/=lib-0_6_x/dss-vest/
forge-std/=lib/forge-std/src/

Notice the src/ suffix is missing from dss-vest.

@amusingaxl amusingaxl changed the title Unable to use multiple profiles on CI Auto-remapping not working properly when using a different profile Apr 10, 2023
@mds1
Copy link
Collaborator

mds1 commented Apr 16, 2023

@mattsse I have noticed similar issues where sometimes the src/ suffix is missing, but I'm not sure why it happens. I know the auto-remappings feature is bit complex, so maybe best to just manually fix remappings in these cases?

@mds1 mds1 added C-forge Command: forge Cmd-forge-build Command: forge build A-compiler Area: compiler labels Apr 16, 2023
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy grandizzy added the A-remappings Area: remappings label Oct 29, 2024
@grandizzy grandizzy changed the title Auto-remapping not working properly when using a different profile bug(remappings): unable to import Solidity file using auto-remappings, missing src/ suffix Nov 5, 2024
@grandizzy
Copy link
Collaborator

libs remappings are using compilers Remapping::find_many fn

    /// Attempts to autodetect all remappings given a certain root path.
    ///
    /// This will recursively scan all subdirectories of the root path, if a subdirectory contains a
    /// solidity file then this a candidate for a remapping. The name of the remapping will be the
    /// folder name.

https://github.com/foundry-rs/compilers/blob/21617d05ae9bab42a509c8c2021977d31b93809a/crates/artifacts/solc/src/remappings.rs#L176-L180

@grandizzy grandizzy added the P-normal Priority: normal label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiler Area: compiler A-remappings Area: remappings C-forge Command: forge Cmd-forge-build Command: forge build P-normal Priority: normal T-bug Type: bug
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

4 participants