foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Fails to compile with vendored dependencies

Open happysalada opened this issue 1 year ago • 2 comments

Component

Other (please describe)

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

  • [ ] Foundry
  • [ ] Foundryup

What version of Foundry are you on?

latest master

What command(s) is the bug in?

cargo build

Operating System

macOS (Intel)

Describe the bug

using cargo vendor to vendor dependencies, the project fails to compile with errors like

error[E0433]: failed to resolve: use of undeclared crate or module `ethers`
   --> /Users/raphael/dev/foundry/vendor/ethers-contract/src/multicall/multicall_contract.rs:903:9
    |
903 |         ethers_contract :: EthAbiCodec,
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `ethers::core::abi`
    |
    = note: this error originates in the derive macro `ethers_contract::EthAbiCodec` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
    |
9   |     use crate::multicall::Token;
    |
9   |     use ethers_core::abi::Token;
    |
help: if you import `Token`, refer to it directly
    |
903 -         ethers_contract :: EthAbiCodec,
903 +         ethers_contract :: EthAbiCodec,
    |

it's quite easy to reproduce. Use cargo vendor then inside the .cargo/config.toml file just add the following

[source.crates-io]
replace-with = "vendored-sources"

[source."https://github.com/bluealloy/revm"]
git = "https://github.com/bluealloy/revm"
replace-with = "vendored-sources"

[source."https://github.com/gakonst/ethers-rs"]
git = "https://github.com/gakonst/ethers-rs"
replace-with = "vendored-sources"

[source."https://github.com/roynalnaruto/svm-rs"]
git = "https://github.com/roynalnaruto/svm-rs"
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"

Context: supporting vendored dependencies would enable forge to be added to nixos. Rust compilation on nixos can only be done through vendored dependencies.

I understand that this might not be a priority, no worries! Thanks again for making great software!

happysalada avatar Sep 17 '22 12:09 happysalada

oh this looks like an issue with how the ethers_core vs ethers path is determined in ethers derive macros here

I guess the manifest dir is something different when running cargo vendor?

https://github.com/gakonst/ethers-rs/blob/master/ethers-core/src/macros/ethers_crate.rs#L51

mattsse avatar Sep 17 '22 17:09 mattsse

vendor creates a vendor directory with all the dependencies. Judging by the logic of the link you posted, it seems that the CARGO_MANIFEST_DIR env var is not set when using cargo vendor. The "ethers-contract" crate fails to compile, because the cargo.toml file dependencies doesn't contain "ethers"

[dependencies]
ethers-providers = { version = "^0.17.0", path = "../ethers-providers", default-features = false }
ethers-core = { version = "^0.17.0", path = "../ethers-core", default-features = false }
ethers-contract-abigen = { version = "^0.17.0", path = "ethers-contract-abigen",  default-features = false, optional = true }
ethers-contract-derive = { version = "^0.17.0", path = "ethers-contract-derive", optional = true }
ethers-derive-eip712 = { version = "^0.17.0", path = "../ethers-core/ethers-derive-eip712", optional = true }

Adding it there however generates a cyclic dependency. hmmm I'm not sure how to solve this one.

it looks like the macro shouldn't return

 return ("ethers::core", "ethers::contract", "ethers::providers")

but not sure what it should return.

happysalada avatar Sep 18 '22 04:09 happysalada

Hi @happysalada, would be great if you could re-run this to see if this is still valid considering Ethers has been replaced by Alloy

cargo vendor runs without issue on my end now

zerosnacks avatar Jun 26 '24 12:06 zerosnacks

I was waiting for a stable release to try again packaging this for nixos. Any release on the horizon by any chance ?

happysalada avatar Jun 27 '24 00:06 happysalada

I was waiting for a stable release to try again packaging this for nixos. Any release on the horizon by any chance ?

Makes sense - hopefully within the next few months. Would it be OK if I close this ticket in favor of https://github.com/foundry-rs/foundry/issues/3895 + https://github.com/foundry-rs/foundry/issues/545?

zerosnacks avatar Jun 27 '24 07:06 zerosnacks

Sure go ahead !

happysalada avatar Jun 27 '24 10:06 happysalada