How best to pass features along to workspace members?

Hello.
Apologies for the length, but I don't know how else to explain.

I wrote a crate that exports a procedural macro as well as some helper tools. The exact functionality is-irrelevant, but, assuming the crate name is akete, it is laid out this way:

akete
|_ akete-proc_macro : The proc macro (uses akete-core)
|_ akete-helpers: Some internal and some user-facing utilities
|_ akete-core : Hooks into third-party libs, such as blas (heavily reliant on akete-helpers)
|_ akete: Reexports third party libraries, macros that use akete-proc_macro, and some akete-helpers

My problem

This is all good and the crate works fine, so what's the issue? Well, whilst upgrading to rust 2021 edition, I encountered some problems with the new resolver – Linker errors (that were solvable by explicitly passing features to the proc macro crate).

The akete-core crate uses blas and some other libs. The user can pick a blas variant with features. The problem, as far as I can gather, was that the features flags needed to execute the proc macro would formerly be unified when the akete-core crate was resolved anywhere.

My question

Is there a better way to pass features down to all of the crates that need them?

I copy-pasted features to the different sub crates via their Cargo.toml. The user can easily propagate a feature and it will pass on via all the copy-pasted feature, but this is really very confusing and so very easy to break, as I have learnt to my dismay.

By gum, it is a mess for sure! Is there a better way?

Thanks and I appreciate any insights anybody can shed.

Does/did cargo fix --edition mention the resolver change? If not, a bug report is probably in order.

As I understand it, you should be able to use resolver = "1" in the immediate term. This doesn't answer your question at all (assuming you'd like to know the best practice for resolver 2), sorry.

Thanks for your help. cargo fix --edition mentioned the errors until I fixed them. It seems that with resolver=2 active, I simply had to rewrite all of my dependencies to make them activate within the proc-macro subcrate instead of the main crate. I'm still not sure if I did it correctly but it seems to work.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.