Closed flavio closed 2 years ago
I'd bet cargo check --all-targets
works. cargo check
won't enable dev dependencies unless you're including tests.
Yes, it's expected that cargo build
/ cargo check
will not work. You'd need at least --tests
to pick up the dev dep that enables a version feature.
The only way I can think of is to define another env var like K8S_OPENAPI_CARGO_FEATURE=1.23
that mimics the actual feature, with the expectation that library users will only set it for local development.
Thanks for the quick answers. Using --tests
with cargo check
/cargo build
solves the problem, but I noticed this doesn't work with cargo doc
because this flag doesn't exist for it.
I think the environment variable approach could work :+1:
I think I've just found another workaround:
[package]
name = "k8s-openapi-lib-bug"
version = "0.1.0"
edition = "2021"
[features]
default = []
enable-k8s-openapi-version = [ "k8s-openapi/v1_23" ]
[dependencies]
k8s-openapi = { version = "0.14.0", default-features = false, features = ["api"] }
Now I can run the following commands just fine:
cargo check --features enable-k8s-openapi-version
cargo build --features enable-k8s-openapi-version
cargo doc --features enable-k8s-openapi-version
I think this solution is even better than the environment variable. How do you feel about that?
If you agree, I can document the "trick" inside of the official docs
I've just noticed that a Cargo.toml
file like this one, works just fine:
[package]
name = "k8s-openapi-lib-bug"
version = "0.1.0"
edition = "2021"
[dependencies]
k8s-openapi = { version = "0.14.0", default-features = false, features = ["api"] }
[dev-dependencies]
k8s-openapi = { version = "0.14.0", default-features = false, features = ["v1_23"] }
No changes are required to execute cargo test|check|build|doc
. This is great, but only works if the "main library" doesn't require k8s-openapi
to have the default features turned on.
About the workaround documented in https://github.com/Arnavion/k8s-openapi/issues/115#issuecomment-1109517795
I think this solution is even better than the environment variable. How do you feel about that?
I think this solution has a workaround: doc.rs will probably fail because it will not run cargo doc
with this feature enabled :thinking:
I think this solution has a workaround: doc.rs will probably fail because it will not run
cargo doc
with this feature enabled thinking
https://docs.rs/about/metadata
In any case, I don't think I'd want every k8s-openapi-using library to start adding dummy features just for this reason. That is, while a feature is a more "standard" solution than the ad-hoc build-time env var, at least the build-time env var is only noticeable to the library's devs and not to the library's users.
In any case, I don't think I'd want every k8s-openapi-using library to start adding dummy features just for this reason. That is, while a feature is a more "standard" solution than the ad-hoc build-time env var, at least the build-time env var is only noticeable to the library's devs and not to the library's users.
That's a good point :+1:
Also, thanks for the link to docs.rs metadata
I've create a Rust library that depends on
k8s-openapi
and I'm having troubles whenbuild
-ing andcheck
-ing it.As documented here:
Following the docs I created a
Cargo.toml
that looks like that:However, running
cargo check
results in the following error:How to reproduce the error:
cargo
:cargo new --lib k8s-openapi-lib-bug
Cargo.toml
with the ones pasted previouslycargo check
Am I doing something wrong? Thanks in advance!