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

Add ability to alias cosmwasm_std when using #[entry_point] #1539

Closed
wants to merge 1 commit into from

Conversation

toml01
Copy link
Contributor

@toml01 toml01 commented Dec 11, 2022

Pretty basic Rust functionality that is not possible currently, since there's a hardcoded value in the entry_point macro.
This simple change gives you the ability to provide an optional alias.

Example:

// Cargo.toml

...

[dependencies]
cw-std = { package = "cosmwasm-std", version = "1.1" }

...

// contract.rs

use cw_std::entry_point;

#[entry_point(cw_std)]
pub fn instantiate(...) -> StdResult<Response> {
    ...
}

...

@webmaster128
Copy link
Member

Thank you for bringing this up and the PR. Two things:

  • Do you have an idea if we can unit test this such that the functionality does not break later on? Not sure if that works though since the renaming is done on the dependency level
  • Can we implement this without adding an attribute to entry_point? It does not feel very elegant. Is it possible to get the full namespace of entry_point, which is imported correctly already?

@toml01
Copy link
Contributor Author

toml01 commented Dec 11, 2022

  1. Yes this is what I thought.
  2. Was thinking the same thing. I tried to see if you could get the namespace easily but couldn't find a way. However, just stumbled upon this, might be helpful here. Will explore a little bit. It might be helpful for testing as well

@toml01
Copy link
Contributor Author

toml01 commented Dec 11, 2022

Thinking about it a bit more - this is a bit of a problem.
Since cosmwasm-derive is a dependency of cosmwasm-std, you need to search for the alias of the std.
While you can do that with cargo_metadata, what if cosmwasm-derive is a dependency of multiple packages in a contract?

And if that's not a concern, why not just move entry_point to std altogether?
@webmaster128

@webmaster128
Copy link
Member

And if that's not a concern, why not just move entry_point to std altogether?

We need cosmwasm-derive to be separate due to

[lib]
proc-macro = true

However, maybe it is possible to turn this re-export in cosmwasm_std into something clever that preserves the namespace?

// Re-exports

pub use cosmwasm_derive::entry_point;

@toml01
Copy link
Contributor Author

toml01 commented Dec 25, 2022

@webmaster128 couldn't find anything of that sort.
The only thing I could hack is to add this to lib.rs:

extern crate cw_std as cosmwasm_std;

This works with the current std.

Do you think it's a better solution for this?

@webmaster128
Copy link
Member

What's the motivation for renaming cosmwasm_std in the first place?

By the way, this was documented in #1420 for a different macro as well.

@toml01
Copy link
Contributor Author

toml01 commented Jan 3, 2023

Things like this.
Maintaining contracts deployed on different flavors for CosmWasm is a serious pain if you can't have everything in the same codebase. Especially assuming secret-cosmwasm-std will probably not be the only cosmwasm flavor in the future,

@webmaster128
Copy link
Member

Done in #2068. Thank you for bringing this up and proposing the solution which inspired the follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants