Why is this unrelated crate breaking my project? - rust

$ cargo build
Downloading pear_codegen v0.0.16
Compiling pear_codegen v0.0.16
Compiling ring v0.11.0
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
--> /.cargo/registry/src/github.com-1ecc6299db9ec823/pear_codegen-0.0.16/src/lib.rs:317:9
|
317 | ExprKind::Block(block) => {
| ^^^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 1
error: aborting due to previous error
For more information about this error, try `rustc --explain E0023`.
error: Could not compile `pear_codegen`.
warning: build failed, waiting for other jobs to finish...
error: build failed
When I try to compile my project I get an error that a crate that isn't in my cargo.toml is broken. Why is this unrelated crate breaking my project?

You're using Rust nightly, and the crate in question used to depend (in version 0.0.16) on the perma-unstable API of the Rust compiler, which was changed by a nightly you updated to (or just installed).
The author appears to have recently rewritten the crate to avoid that dependency, which means further breakage should be avoided, starting with version 0.0.17 of the crate.

cargo update
fixed the issue for me
https://github.com/SergioBenitez/Pear/issues/7
thanks to reddit user /u/usernamedottxt

Related

Why does cargo use a specific dependency version?

When trying to follow the instructions of the pathfinder library, i.e:
cd demo/native
cargo run --release
I get errors due to the compilation of the dependency winit version 0.19.3:
error[E0308]: mismatched types
--> /Users/yairchu/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.19.3/src/platform/macos/view.rs:209:9
|
205 | extern fn has_marked_text(this: &Object, _sel: Sel) -> BOOL {
| ---- expected `bool` because of return type
...
209 | (marked_text.length() > 0) as i8
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `i8`
If I try changing the version used to the latest (which works fine for me) by changing Cargo.toml:
--- a/demo/native/Cargo.toml
+++ b/demo/native/Cargo.toml
## -43,7 +43,7 ## rev = "f3df871ac8c3926fe9106d86a3e51e20aa50d3cc"
[dependencies.winit]
-version = "<0.19.4" # 0.19.4 causes build errors https://github.com/rust-windowing/winit/pull/1105
+version = "0.27.2"
I still get the same errors!
Interestingly, I notice this in cargo's output:
Compiling winit v0.19.3
Compiling winit v0.27.2
It appears to now be building both the version I specified and the old version.
I'm lost. Also using --verbose didn't help elucidate why cargo chooses to build this specific dependency.
Is it using two versions of the same library in one executable?
How can I find out why cargo chooses to build this library? (so that I can update it to the working version)
Thanks! Rust noob
How can I find out why cargo chooses to build this library?
cargo tree elaborates on whose dependency is each sub-dependency.
Is it using two versions of the same library in one executable?
It is.
You can depend on different versions of the the same crate. This can be useful if you want to use one version of the dependency, but one of your own dependencies uses another version.
(thanks #Masklinn for the answers in the comments!)

Could not compile `lazy_static`

I'm having a hard time cross-compiling an embedded Rust project that worked before for a raspberry pi. I have all the needed deps in Cargo.toml but on doing:
$ cargo build --target thumbv7m-none-eabi
I get the following error.
error[E0463]: can't find crate for `std`
--> /home/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0/src/inline_lazy.rs:9:1
|
9 | extern crate std;
| ^^^^^^^^^^^^^^^^^ can't find crate
|
= note: the `thumbv7m-none-eabi` target may not support the standard library
= help: consider building the standard library from source with `cargo build -Zbuild-std`
For more information about this error, try `rustc --explain E0463`.
error: could not compile `lazy_static` due to previous error
$ rustup show
installed targets for active toolchain
--------------------------------------
thumbv7m-none-eabi
x86_64-unknown-linux-gnu
active toolchain
----------------
nightly-x86_64-unknown-linux-gnu (default)
rustc 1.64.0-nightly (38b72154d 2022-07-11)
Compilation used to work previously without lazy_static as a dependency in cargo.toml,now I don't understand why this is happening.
By default lazy_static depends on the rust standard library, which as the compiler told you
may not be supported on the thumbv7m-none-eabi target
If you do not need the standard library in your project you can enable the no-std feature of lazy_static like this:
lazy_static = { version = "1.5.0", features = ["spin_no_std"] }
as described here.

Error adding Custom RPCs for custom pallet Substrate

I've been working with parity's contracts node (latest version) and the substrate template node (tag polkadot-v0.9.18), both present the same issue when compiling.
I have a very simple pallet that stores certain items. The main structure is the following:
#[pallet::storage]
#[pallet::getter(fn items)]
/// 'Mapping' Item ID -> Item Data
pub(crate) type Items<T: Config> = StorageMap<_, Twox64Concat, T::Hash, Item<T>>;
I was trying to add a simple RPC method following this guides https://core.tetcoin.org/recipes/custom-rpc.html#rpc-to-call-a-runtime-api and https://core.tetcoin.org/recipes/runtime-api.html
I also checked some projects that already have custom RPC calls implementations, like de subsocial node and I have pretty much the same structure and dependencies.
My rpc method does nothing but return a number 2 just to make sure it works, but it doesn't. This is what the pallets directory looks like:
pallets directory
When I try to compile, the following error shows
error: the wasm32-unknown-unknown target is not supported by default, you may need to
enable the "js" feature. For more information see:
https://docs.rs/getrandom/#webassembly-support
I don't even use that module, but I've read that it is used somewhere as an indirect dependency.
I'm compiling my project with the following command
cargo build --release
Checking the documentation regarding the 'getrandom' crate issue, I added the following dependency in the Cargo.toml (I tried adding it in every Cargo.toml within the project, individually, by pairs, ...)
getrandom = { version = "0.2", features = ["js"] }
Then another error shows up:
error: failed to run custom build command for secp256k1-sys v0.4.1
Which again, doesn't make any sense to me.
The project itself has nothing but the node template base and a new pallet that implements a create and transfer function. Without the RPC implementation, it works perfectly using the Polkadot App, but as soon as I include the custom rpc, it just doesn't compile.
This is my rust configuration (rustup show)
installed toolchains
--------------------
stable-x86_64-apple-darwin (default)
nightly-2021-11-04-x86_64-apple-darwin
nightly-x86_64-apple-darwin
active toolchain
----------------
stable-x86_64-apple-darwin (default)
rustc 1.59.0 (9d1b2106e 2022-02-23)
I haven't found anyone who is dealing with this kind of issue, and I don't know where the problem might be.
This is the first issue logs:
error: the wasm32-unknown-unknown target is not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support
--> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.5/src/lib.rs:229:9
|
229 | / compile_error!("the wasm32-unknown-unknown target is not supported by \
230 | | default, you may need to enable the \"js\" feature. \
231 | | For more information see: \
232 | | https://docs.rs/getrandom/#webassembly-support");
| |________________________________________________________________________^
error[E0433]: failed to resolve: use of undeclared crate or module `imp`
--> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.5/src/lib.rs:256:5
|
256 | imp::getrandom_inner(dest)
| ^^^ use of undeclared crate or module `imp`
For more information about this error, try `rustc --explain E0433`.
error: could not compile `getrandom` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: build failed
Current status (to reproduce error): https://github.com/andresvsm/substrate-pallet-rpc/tree/items-branch
Sometimes, you can get this error from a deep dependency of another dependency, e.g. when you really build for a wasm32-unknown-unknown target, and getrandom is linked but even not used. It can be fixed (worked around) with the following trick:
In Cargo.toml, add this line:
[dependencies]
getrandom = {version = "0.2", default-features = false, features = ["custom"]}
It tells the compiler to use a dummy implementation inside of getrandom.
Fixed for me when I added "default features = 'false'" into my Cargo.toml under the dependency in question.

Error running cargo build with clickhouse dependency

I added this to my cargo toml file, following the instructions here
[dependencies]
clickhouse = "0.6.3"
reflection = "0.1.3"
but when I run cargo build I get a failure saying:
Compiling clickhouse v0.6.3
error[E0433]: failed to resolve: could not find `test` in `tokio`
--> /Users/gudjonragnar/.cargo/registry/src/github.com-1ecc6299db9ec823/clickhouse-0.6.3/src/compression/lz4.rs:163:10
|
163 | #[tokio::test]
| ^^^^ could not find `test` in `tokio`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.
error: could not compile `clickhouse`
To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
I am quite new to Rust so I don't know what to do here, any thoughts?
I am running on MacOS BigSur if that is relevant.
I am getting this error on Linux as well. This appears to be an issue in the clickhouse crate, but it can be fixed in your Cargo.toml. #[tokio::test] refers to a macro which requires both the "rt" and "macros" features, but the Cargo.toml file in the clickhouse crate only includes the "rt" feature. In order to add this feature so that the crate will compile, you can add a line to your Cargo.toml for tokio that enables that feature:
tokio = { version = "1.0.1", features = ["rt", "macros"] }
Adding this line fixed the compiler error for me.
I noticed there is another clickhouse crate, which might also be helpful

Crate with diesel and mysql dependencies no longer compiles against mariadb after upgrading NixOS to 20.03

My crate, which depends on diesel with the mysql feature enabled, no longer compiles after upgrading my system from NixOS 19.09 to 20.03. It seems the only significant change is an update of the mariadb-server package from 10.2.17 to 10.3.18. There is no change to the Rust toolchain etc. (it's statically pinned in nix-shell to nightly 2020-04-20).
The very long compiler message starts with:
warning: build failed, waiting for other jobs to finish...
error: linking with `cc` failed: exit code: 1
What should I do?
This build script that tells Cargo to link the crate using the compiler's flag `-lmariadb solved the issue:
fn main() {
println!("cargo:rustc-link-lib=mariadb");
}
Update 2020-05-01
Actually the issue could be solved in mysqlclient-sys crate.

Resources