alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
764 stars 139 forks source link

[Bug] using alloy with git rev requires patche.crates-io #584

Closed ryandotsmith closed 5 months ago

ryandotsmith commented 6 months ago

Component

sol-types

What version of Alloy are you on?

ff339696fa9b490698cb3edec3d4647fae0bd332

Operating System

macOS (Apple Silicon)

Describe the bug

Hi. I'm not entirely sure what kind of bug this is since I'm new to Rust and this codebase. But, I was trying to get this example to work in a fresh cargo project and for the longest time i was getting a compiler error [1]. I then saw that the examples repo had the following lines:

[patch.crates-io]
    alloy-core       = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }
    alloy-primitives = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }
    alloy-sol-types  = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }

Adding these patch lines made the error go away. Here is my complete Cargo.toml file. I am guessing that if I add the alloy crate via git that I then have to patch all of the core crates via git too?

[package]
    edition = "2021"
    name    = "test"
    version = "0.1.0"

    # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
    alloy = { git = "https://github.com/alloy-rs/alloy", "features" = [
        "contract",
        "network",
        "providers",
        "rpc",
        "rpc-types",
        "rpc-types-eth",
        "sol-types",
    ], "rev" = "0f8491e" }
    tokio = { version = "1.36.0", features = ["full"] }
    url = "2.5.0"

[patch.crates-io]
    alloy-core       = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }
    alloy-primitives = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }
    alloy-sol-types  = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }

[1]: the compiler error:

error[E0107]: missing generics for trait `Provider`
   --> src/main.rs:30:1
    |
30  | / sol! {
31  | |     #[sol(rpc)]
32  | |     contract Store {
33  | |         function getFieldLayout(bytes32 tableId) internal view returns (bytes32);
34  | |     }
35  | | }
    | |_^ expected at least 1 generic argument
    |
note: trait defined here, with at least 1 generic parameter: `N`
   --> /Users/r/.cargo/git/checkouts/alloy-805bdb2c8d2cb5fa/0f8491e/crates/provider/src/provider.rs:178:11
    |
178 | pub trait Provider<N: Network, T: Transport + Clone = BoxTransport>: Send + Sync {
    |           ^^^^^^^^ -
    = note: this error originates in the macro `$crate::sol_types::sol` which comes from the expansion of the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add missing generic argument
   --> /Users/r/.cargo/git/checkouts/alloy-805bdb2c8d2cb5fa/0f8491e/crates/alloy/src/lib.rs:67:10
    |
67  |         }<N>
    |          +++
ryandotsmith commented 6 months ago

I found this in the examples too: https://github.com/alloy-rs/examples/blob/main/Cargo.toml#L51-L54

It didn't impact my test project so long as I had the patch.crates-io sections setup.

onbjerg commented 5 months ago

You can use 0.7 which removed the patches, they will also be removed from the examples

ryandotsmith commented 5 months ago

You can use 0.7 which removed the patches, they will also be removed from the examples

ty!