Skip to content

fix: rename dependency cause error#426

Closed
ridesun wants to merge 1 commit into
gear-tech:masterfrom
ridesun:ri/package_alias_fetch
Closed

fix: rename dependency cause error#426
ridesun wants to merge 1 commit into
gear-tech:masterfrom
ridesun:ri/package_alias_fetch

Conversation

@ridesun
Copy link
Copy Markdown
Contributor

@ridesun ridesun commented Jul 27, 2024

Resolves #401 .

I've made some attempts and found that to get the aliases of imported dependencies in Cargo.toml, we need to use the cargo_metadata crate to obtain the alias information of dependencies from the project metadata of Cargo. Can we import this new crate?

for example:

#In Cargo.toml
rename_sails={package = "sails-rs"}
#scale_sails_path::gstd::msg::id() 
//Will be generated to 
rename_sails::gstd::msg::id()

@reviewer-or-team

@DennisInSky
Copy link
Copy Markdown
Contributor

@ridesun thanks for the idea. We have already implemented our own solution #427. This solution require manual actions, but it covers more possible cases like if one decides to re-export the sails-rs crate. Nevertheless, your solution is less demanding in terms of what a person needs to do if they just have a dependency on renamed sails-rs crate as well as it doesn't conflict with the solution provided by us. So if you want to go on with your solution, please update it from the dev branch

Comment thread Cargo.toml
thiserror-no-std = "2.0"
tokio = "1.39"
trybuild = "1"
cargo_metadata = "0.18"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the comment saying it has to be in alphabetical order. We also prefer crates to be named in kebab-case instead of snake one

Comment thread rs/macros/core/Cargo.toml
proc-macro2.workspace = true
quote.workspace = true
syn = { workspace = true, features = ["full", "extra-traits"] }
cargo_metadata.workspace = true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All dependencies are in alphabetical order

@ridesun
Copy link
Copy Markdown
Contributor Author

ridesun commented Jul 30, 2024

Thank you very much for your response. The solution you proposed is very ingenious and covers more possible cases. I will try to continue refining this solution in a new branch according to your requirements. The cargo_metadata crate may have more applications in this project.

@ridesun ridesun closed this Jul 30, 2024
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.

Provide a way for defining sails crate name in generated code

2 participants