fix: enable alloc
feature on hex
crate
#3000
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I detected this issue while i was trying to run
unit test
under an individual cratebytes-hex
.I mean to execute
cargo build
orcargo test
right under./crates/bytes-hex
. well, asbytes-hex
is a crate, it's supposed to compile sucessfully & do unit tests independently. but it cannot even compile.with an error like:
but I also realized the unit tests working well in github Actions. then i forked the code and test a few more scenarios, for examples, if you modify the
Cargo.toml
in the root directory, changingmembers = ["crates/*"]
into
members = ["crates/bytes-hex"]
then the github actions will fail with the exact same error, here is the github action log from my forked repo FYI.
however, as long as i include some crates which including
bytes-hex
as dependency, likemembers = ["crates/model", "crates/bytes-hex"]
It works successfully as the default which including all crates. I mean
members = ["crates/*"]
To this point, i realised that these crates like
model
much have smuggled the feature intobytes-hex
somehow.I did a lot of research, in the official doc of rust, i learned that is a concept Feature unification. In short, in a workplace if multi crates/dependencies refer to the same crate, as long as these refers can be resolved to the same version, it will make an union of features from each reference. and the union of features will be available globally among the whole workplace.
for example,
web3
crate is commonly refered as a dependency in many crates, includingmodel
. if you step into the dependency ofweb3
crate . you can seehex
is included with default features, that is it comes withalloc
feature. because of this the featurealloc
is propogating tobytes-hex
. that's why it works if puttingbytes-hex
with other crates, it works fine.(N.B:
hex
is a commonly used crate with default feature in many dependencies from the crates in the workplace, you can usingcargo tree --all-features
to check.)Changes
As long as i can confirm the feature
alloc
ofhex
crate will be introduced by other dependencies into the workplace. so just updateCargo.toml
insidebytes-hex
. this can ensure tasks likebuild
,unit test
work insidebytes-hex
and in the workplace level. while introducing very less (or even no) impacts to the whole workplace.#How to test
now it can be tested freely either inside
bytes-hex
or in the workplace. in.devcontainer
or ingithub actions
.Why open this PR
I open this PR because this is the first time I learnt how
feature unification
in rust exactly works although it claimed a few hours of mine with which I planed to learn some CoW knowledge.