-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider removing support for paths in abigen!
in favour of Rust's include_str!
#94
Comments
Love this idea, let's do it! |
This may also solve #93 as a side effect. |
True, |
Just been taking a look into this issue with @mitchmindtree. Unfortunately, I don't think rust will let us expand an expression given to the second argument into a string at the time of procedural macro expansion. grrrrr shakes fist at rust Perhaps another solution is to find the logic that |
Yeah 🤦 Unfortunately it looks like we can't evaluate an expression given to the second argument to a string that we can actually use to generate the There's some writing on this limitation on expanding macros in argument position of other macros here. Barring that, I think @JoshuaBatty's suggestion of modelling our "path" source behaviour after |
Damn you Rust! But yeah, fair enough, #97 sounds like a good option too. |
We might be able to simplify the implementation of
abigen!
a little and add a little flexibility by only accepting expressions that evaluate to astr
in the right-hand side argument.For example, as an alternative to:
which involves some custom path and file handling, we could potentially accept an
Expr
in the right-hand side argument (instead ofLitStr
) and offload the path and file-handling work to the Rustinclude_str
macro from std:Currently, even though we technically accept full contract ABI JSON strings in the right argument, we are unable to use macros that evaluate to a
str
like above as the parser for the right hand side argument expects aLitStr
(string literal) rather than anExpr
(expression). By taking anExpr
, I believe users would be free to use both literal strings and macros that expand to astr
, e.g.include_str
, or an alternative toinclude_str
that accepted absolute paths rather than relative, etc.Motivation
I ran into this while moving an example out of The Sway Book into a standalone project within the sway repo examples directory as a part of solving FuelLabs/sway#544.
I noticed that currently the path accepted in the right-hand side of
abigen!
seems to be relative to the root of the current workspace (rather than the project). This makes the invocation ofabigen!
within the test harnesses of the examples that are nested within the sway repo a little awkward as they must specify the path relative to the sway workspace root, rather than the example's own project root. E.g. inexamples/hello_world/tests/harness.rs
currently we have to dorather than ideally
or
Ideally we'd be able to write one of the latter as we'd like to include these examples into the book verbatim with
Addressing this issue should allow for the latter.
The text was updated successfully, but these errors were encountered: