You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
So I took a look into this. Originally I thought we could use the file!() macro but then we are back to square one with not being able to have a macro evaluate as an input to another macro. Further, the path returned by file!() is where the macro code lives not the file where the macro was called from.
I then started to look at using span to get this information out. Turns out you can use a span to get access to the calling file path, but currently it's an unstable feature. See this open issue
It provides a method on span pub fn source_file(&self) -> SourceFile; This would allow us to get relative paths working, but the issue has been open for over 3 years, so there is a chance it might not land. Still, might be worth periodically checking in to see if there is any movement towards stabilizing this feature.
Follow-up to #94.
Currently the path passed to the right hand side argument of
abigen!
is expected to be relative to thestd::env::current_dir
:fuels-rs/fuels-core/src/source.rs
Line 47 in f6d4cc0
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 oursrc
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:the
abigen!
macro could then be invoked within theproject/tests/harness.rs
withThe text was updated successfully, but these errors were encountered: