Skip to content

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

@amusingaxl

Description

@amusingaxl

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Next Up

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions