Skip to content

Model abigen!s Source::Path behaviour after include_str! #97

Open
@mitchmindtree

Description

@mitchmindtree

Follow-up to #94.

Currently the path passed to the right hand side argument of abigen! is expected to be relative to the std::env::current_dir:

let root = env::current_dir()?.canonicalize()?;

This evaluates to whatever happens to be the current directory at the time of macro expansion. This means that the necessary path given to abigen! can change when the project is moved to a different subdirectory of the same workspace, or if its moved from a workspace into its own project, or vice versa. Ideally, we want our src not to be dependent on the directory that the project happens to be executed within.

To fix this, we could model our behaviour after the std include_str! macro. include_str! accepts a path that is relative to the file in which it is invoked. For example if we have:

project/my-contract-abi.json
project/tests/harness.rs

the abigen! macro could then be invoked within the project/tests/harness.rs with

abigen!(MyContract, "../my-contract-abi.json");

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions