Open Veetaha opened 1 year ago
Is it maybe possible to change the target based on a cfg flag? That could be a neat option, but I haven't seen anything like that before.
There is an ability to override the crate type via cargo rustc --crate-type cdylib
. This way the lint crates could just omit the lib.crate-type
declaration in the Cargo.toml
. So cargo-marker
doesn't even need to rely on lint crate users to do that.
The downside is that cargo rustc
works only on one crate at a time. We can't pass multiple --package
parameters to cargo rustc
.
Summary
Today if you run
cargo test --doc
you'll see the following errorThere are no good solutions to this problem. Same problem is also described in https://github.com/paritytech/cargo-contract/issues/494.
We could recommend setting
crate-type = ["cdylib", "rlib"]
to make the doc tests work, but it means that the lint crates would be compiled as a static library in addition to a dynamic one. I suppose that it will influence the lint crates compilation performance by compiling an additional unnecessary library target.We could provide a command in
cargo-marker
that adds therlib
crate type temporarily for doc tests. But that will look ugly if we need to modify theCargo.toml
of the crate. What if the process is killed? The modifications to theCargo.toml
file will persist and be potentially committed to the version control. Copying the project to a temp directory would solve this, but it may have a bunch of edge cases on its own as well...