Skip to content
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

Create a build.rs script for forc-client to auto update proxy abi from file to source code #6527

Closed
kayagokalp opened this issue Sep 10, 2024 · 5 comments · Fixed by #6535
Closed
Labels
code quality enhancement New feature or request forc-client Everything related to the `forc-client` crate.

Comments

@kayagokalp
Copy link
Member

We have an interesting problem, abigen! macro from sdk needs either a file location, or a raw abi string. Using file location fails becuase cargo flattens all packages before releasing them and changing the location we hold our abi file in. Using raw str is troublesome and error prone. We discussed using include_str! macro from std but then the problem is the order of macro expansions. We cannot ensure that nclude_str! is expanded before abigen!.

We can create a build.rs file that updates the contents of the proxy abi raw str embedded in the code to come to a middle ground, where we use raw str for abigen macro but do not need to update it manually.

@kayagokalp kayagokalp added enhancement New feature or request forc-client Everything related to the `forc-client` crate. labels Sep 10, 2024
@kayagokalp kayagokalp changed the title Create a build.rs script for forc-client to auto read proxy abi from file, before rust macro expansion happens Create a build.rs script for forc-client to auto update proxy abi from file to source code Sep 10, 2024
@JoshuaBatty
Copy link
Member

Yep, this is one of the first problems I ran into after starting at fuel. There is any issue for this in the fuels repo here

From memory it is also one of the main blockers for why we don't support windows as we need relative paths to resolve in the abigen! macro. I'm not sure what the best approach here is still. Ideally we would could use the functionality for what include_str! provides. It could be worth searching if there are external crates that provide that functionality without being a macro, or looking at the source code of the macro itself to see if it can be ported to a regular function.

Utilising a build.rs file is not a bad last resort but it would be nice to try and see if we could avoid it.

@kayagokalp
Copy link
Member Author

Yep, this is one of the first problems I ran into after starting at fuel. There is any issue for this in the fuels repo here

From memory it is also one of the main blockers for why we don't support windows as we need relative paths to resolve in the abigen! macro. I'm not sure what the best approach here is still. Ideally we would could use the functionality for what include_str! provides. It could be worth searching if there are external crates that provide that functionality without being a macro, or looking at the source code of the macro itself to see if it can be ported to a regular function.

Utilising a build.rs file is not a bad last resort but it would be nice to try and see if we could avoid it.

Exactly 💯 I really want to do this without build.rs as well :) I wonder if ordered macro expansions possible without changing rust compiler, because with that we would be able to use include str 🤔

@sdankel
Copy link
Member

sdankel commented Sep 11, 2024

Related #6427

@alfiedotwtf
Copy link
Contributor

alfiedotwtf commented Sep 11, 2024

Could we force the ordering by making fuels-macros depend on something else? My thinking is that this new dependency (or even dev-dependency) would be expanded before fuels-macros, which could hopefully correct any path mangling?

@alfiedotwtf
Copy link
Contributor

alfiedotwtf commented Sep 11, 2024

It could be worth searching if there are external crates that provide that functionality without being a macro

If I'm reading this correctly, for file paths the evil way would be to inject a unique string into the source as a comment or attribute, then walk the filesystem looking for that unique string 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality enhancement New feature or request forc-client Everything related to the `forc-client` crate.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants