Skip to content

forc-node build fails: ethers-contract abigen! macro cannot find ethers crate in Nix sandbox #209

@JoshuaBatty

Description

@JoshuaBatty

Summary

When building forc-node in the Nix sandbox, the build fails because fuel-core-relayer uses the ethers-contract::abigen! macro, which cannot locate the ethers crate.

Related Issue

This is related to but separate from #196. Issue #196 documents the fuel-core-wasm-executor network access problem. This issue documents a different blocker.

Root Cause

The abigen! macro from ethers-contract uses the proc-macro-crate library to detect crate names at compile time. It generates code with paths like ::ethers::core::types::*. However, fuel-core-relayer only depends on individual ethers sub-crates (ethers-contract, ethers-core, ethers-providers), not the umbrella ethers crate.

In a normal cargo build, proc-macro-crate can read Cargo.toml and detect the sub-crates. But in Nix's sandboxed/vendored build environment, this detection fails, causing compilation errors like:

error[E0433]: failed to resolve: could not find `ethers` in the list of imported crates

This is a known issue with the ethers ecosystem in sandboxed builds:

Attempted Fix

We attempted to fix this by:

  1. Adding ethers = { version = "2.0", default-features = false } to the forc workspace
  2. Patching Cargo.lock to include ethers and its dependencies
  3. Patching the vendored fuel-core-relayer Cargo.toml in preBuild

However, this led to cargo resolution errors looking for ethers-etherscan even with default-features = false, likely due to how cargo resolves features in offline/sandboxed mode.

Potential Solutions

  1. Patch fuel-core-relayer upstream to add the umbrella ethers crate as a dependency
  2. Vendor a pre-patched version of fuel-core-relayer
  3. Use Nix overlays to modify the ethers crate's feature resolution
  4. Patch the vendored crates more aggressively during the Nix build

Affects

  • forc-node >= 0.70.x (both sway and forc repo versions)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions