Cargo rand compilation errors - rust

This is a really basic question so please bear with me.
I have a project that needs to use an old build of Rust (cargo 0.19.0-nightly c995e9e 2017-03-17). It uses rand so I added rand="0.4.3" as a dependency. When the registry updates, rand 0.5.5 (latest) is automatically downloaded and it also runs into "break loop" error which was stabilized a while ago. I am not sure how to suppress this error or make it not install the latest version.
Cargo.toml:
[package]
name = "hello-world"
version = "0.0.0"
authors = [""]
[dependencies]
time = ">=0.1.0"
rand = "=0.4.3"
rustc-serialize ="0.3"
histogram = "*"
I get this error. The repository is not cloned locally so I cannot apply the patch rust-lang/rust#37339.
Compiling rand v0.5.5 error: break with a value is experimental (see
issue #37339)
--> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.5.5/src/distributions/uniform.rs:674:25
| 674 | break d; | ^^^^^^^ |
= help: add #![feature(loop_break_value)] to the crate attributes to enable
error: pub(restricted) syntax is experimental (see issue #32409)
--> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.5.5/src/distributions/float.rs:71:5
| 71 | pub(crate) trait IntoFloat { | ^^^^^ |
= help: add #![feature(pub_restricted)] to the crate attributes to enable
error: pub(restricted) syntax is experimental (see issue #32409)
--> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.5.5/src/rngs/mod.rs:174:27
| 174 | #[cfg(feature="std")] pub(crate) mod thread; | ^^^^^ |
= help: add #![feature(pub_restricted)] to the crate attributes to enable
error: aborting due to 3 previous errors
error: Could not compile rand.
What am i doing wrong? What is the right way to go about it?

Related

How do I fix my compatability errors when using plotters::CairoBackend with GTK

I am trying to draw an image on a very basic GUI. I am using GTK for the GUI and want to use the plotters crate for the drawing but am having issues initiating the Backend that plotters uses.
I have successfully managed to use the BitMapBackend to draw to a file - there is no shortage of examples on the internet for this. However, I cannot for the life of me find an example of how to use the CairoBackend to draw onto a gtk DrawingArea.
My issue arises when I try to connect the draw event to the GTK DrawingArea. I use the connect_draw method which works as expected returning a context to pass to the CairoBackEnd. The problem is that the type of context returned by connect_draw is not compatible with the type of context required by the CairoBackend. I receive context of type 'gtk::cairo::Context' (defined in cairo-rs v0.16.7) but the backend requires a context of 'cairo::context:Context' (defined in cairo-rs v0.15.12). Clearly my dependencies are using different versions of the cairo-rs crate. Presumably, the versions of my dependencies are not compatible with each other. How can I fix this? How do I find out what version of each dependency will work with the others? My cargo.toml file contains:
[package]
name = "testing3"
version = "0.1.0"
edition = "2021"
[dependencies]
gtk = "0.16.2"
plotters = "0.3.4"
plotters-cairo = "0.3.2"
My rust code is:
use gtk::prelude::*;
use plotters::prelude::*;
use gtk::{Application, ApplicationWindow};
fn main() {
let app = Application::builder().build();
app.connect_activate(build_gui);
app.run();
}
fn build_gui(app: &Application){
let win = ApplicationWindow::builder().application(app).default_width(320).default_height(200).title("Test").build();
let da: gtk::DrawingArea = gtk::DrawingArea::builder().build();
da.connect_draw(move|_, c|{
let root = plotters_cairo::CairoBackend::new(c, (1024, 768)).unwrap().into_drawing_area();
gtk::Inhibit(false)
});
win.add(&da);
win.show_all();
}
my error message is:
--> src/main.rs:21:49
|
21 | let root = plotters_cairo::CairoBackend::new(c, (1024, 768)).unwrap().into_drawing_area();
| --------------------------------- ^ expected struct `cairo::context::Context`, found struct `gtk::cairo::Context`
| |
| arguments to this function are incorrect
|
= note: struct `gtk::cairo::Context` and struct `cairo::context::Context` have similar names, but are actually distinct types
note: struct `gtk::cairo::Context` is defined in crate `cairo`
--> /home/maindesktop/.cargo/registry/src/github.com-1ecc6299db9ec823/cairo-rs-0.16.7/src/context.rs:72:1
|
72 | pub struct Context(ptr::NonNull<cairo_t>);
| ^^^^^^^^^^^^^^^^^^
note: struct `cairo::context::Context` is defined in crate `cairo`
--> /home/maindesktop/.cargo/registry/src/github.com-1ecc6299db9ec823/cairo-rs-0.15.12/src/context.rs:72:1
|
72 | pub struct Context(ptr::NonNull<cairo_t>);
| ^^^^^^^^^^^^^^^^^^
= note: perhaps two different versions of crate `cairo` are being used?
note: associated function defined here
--> /home/maindesktop/.cargo/registry/src/github.com-1ecc6299db9ec823/plotters-cairo-0.3.2/src/backend.rs:70:12
|
70 | pub fn new(context: &'a CairoContext, (w, h): (u32, u32)) -> Result<Self, CairoError> {
| ^^^
For more information about this error, try `rustc --explain E0308`.
error: could not compile `testing3` due to previous error
------------------
(program exited with code: 101)
So with more digging around I have found the solution.
As I identified from the error message, my code had a compatibility problem. The gtk v0.16.2 dependency in my toml file depended itself on cairo-rs v0.16.7 where as the plotters-cairo v0.3.2 depended on cairo-rs v15.12. Clearly, I had to use an earlier version of the gtk dependency - one that depended on cairo-rs v15.12. But which one.
On the Doc.rs website I could find the gtk crate documents on https://docs.rs/gtk/0.6.0/gtk/. A tab on top left, gtk-0.6.0, on being selected provided both dependency data and versioning options. I could see that the latest version of the gtk crate did indeed depend on cairo-rs 0.6.0. Selecting the various versions I was able to find the latest version that still depended on cairo-rs v15.xx. In this case it was gtk v0.15.5. Once I replaced my gtk dependency with that version, all was good. So my new toml was:
[package]
name = "testing3"
version = "0.1.0"
edition = "2021"
[dependencies]
gtk = "0.15.5"
plotters = "0.3.4"
plotters-cairo = "0.3.2"
Now by adding the code:
c.rectangle(10.0, 10.0, 70.0, 70.0);
c.fill().expect("Drawing failed");
root.fill(&RED).unwrap();
above my gtk::Inhibit(false) statement, I could indeed create a red rectangle

Why does adding graphql-client as dependency cause rover to break?

I am setting up this project to help me pass authorization data between each subgraphs. I have an authorization subgraph to gather the data so the router will have to make a graphql query to the authorization subgraph and then pass it along. I picked graphql_client dependency because it's the same one that Apollo uses and it seems to have a lot of support compare to the other Rust graphql clients however when I add this dependency, it breaks another dependency. These are the steps
set up context example project -> https://github.com/apollographql/router/tree/v0.1.0-preview.6/examples/context
add these as dependency in Cargo.toml
graphql_client = { version = "0.10.0", features = ["reqwest-blocking"] }
reqwest = { version = "0.11.10", features = ["blocking"] }
run cargo build
see error
Compiling launchpad v0.1.0 (https://github.com/apollographql/rover.git?rev=94141242ba34cf00cde9630fc4a6dcd05d4fa5da#94141242)
error[E0433]: failed to resolve: use of undeclared type `HeaderMap`
--> /Users/macuser/.cargo/git/checkouts/rover-efd9f422be37a06b/9414124/crates/launchpad/src/introspect/runner.rs:30:26
|
30 | let mut header_map = HeaderMap::new();
| ^^^^^^^^^ not found in this scope
|
help: consider importing this struct
|
1 | use reqwest::header::HeaderMap;
|
error[E0433]: failed to resolve: use of undeclared type `HeaderName`
--> /Users/macuser/.cargo/git/checkouts/rover-efd9f422be37a06b/9414124/crates/launchpad/src/introspect/runner.rs:33:13
|
33 | HeaderName::from_bytes(header_key.as_bytes())?,
| ^^^^^^^^^^ not found in this scope
|
help: consider importing this struct
|
1 | use reqwest::header::HeaderName;
|
error[E0433]: failed to resolve: use of undeclared type `HeaderValue`
--> /Users/macuser/.cargo/git/checkouts/rover-efd9f422be37a06b/9414124/crates/launchpad/src/introspect/runner.rs:34:13
|
34 | HeaderValue::from_str(&header_value)?,
| ^^^^^^^^^^^ not found in this scope
|
help: consider importing this struct
|
1 | use reqwest::header::HeaderValue;
|
error[E0659]: `reqwest` is ambiguous
--> /Users/macuser/.cargo/git/checkouts/rover-efd9f422be37a06b/9414124/crates/launchpad/src/introspect/runner.rs:6:5
|
6 | use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
| ^^^^^^^ ambiguous name
|
= note: ambiguous because of multiple potential import sources
= note: `reqwest` could refer to a crate passed with `--extern`
= help: use `::reqwest` to refer to this crate unambiguously
note: `reqwest` could also refer to the module imported here
--> /Users/macuser/.cargo/git/checkouts/rover-efd9f422be37a06b/9414124/crates/launchpad/src/introspect/runner.rs:5:5
|
5 | use graphql_client::*;
| ^^^^^^^^^^^^^^^^^
= help: use `self::reqwest` to refer to this module unambiguously
Dependency tree is apollo router -> uplink -> rover (branch = geal/launchpad)
I posted this same issue on apollo/router repo and they said it'll be fix soon
https://github.com/apollographql/router/issues/937#issuecomment-1114995491
You need to configure your subgraph to receive it.

Rust wasm module build error (x11-clipboard dependency)

Recently I knew about web assembly and was messing around with it in rust. Eventually I run into build problem. My toml file looks like this
[package]
name = "clipboard-manager"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["console_error_panic_hook"]
[dependencies]
x11-clipboard = "0.5.2"
wasm-bindgen = "0.2.63"
js-sys = "0.3.55"
console_error_panic_hook = { version = "0.1.6", optional = true }
#libc = "0.2.105"
# log = "0.4.14"
# x11 = "2.19.1"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
[lib]
crate-type = ["cdylib", "rlib"]
And when I want to build .wasm file with wasm-pack build --target web command I get bunch of errors like this
error[E0425]: cannot find function `malloc` in crate `libc`
--> /mnt/commondisk/filip/Development/personal/clipboard-manager/target/wasm32-unknown-unknown/release/build/xcb-64883900109c6e35/out/shape.rs:98:29
|
98 | let raw = libc::malloc(32 as usize) as *mut xcb_shape_notify_event_t;
| ^^^^^^ not found in `libc`
error[E0425]: cannot find function `malloc` in crate `libc`
--> /mnt/commondisk/filip/Development/personal/clipboard-manager/target/wasm32-unknown-unknown/release/build/xcb-64883900109c6e35/out/xfixes.rs:238:29
|
238 | let raw = libc::malloc(32 as usize) as *mut xcb_xfixes_selection_notify_event_t;
| ^^^^^^ not found in `libc`
error[E0425]: cannot find function `malloc` in crate `libc`
--> /mnt/commondisk/filip/Development/personal/clipboard-manager/target/wasm32-unknown-unknown/release/build/xcb-64883900109c6e35/out/xfixes.rs:330:29
|
330 | let raw = libc::malloc(32 as usize) as *mut xcb_xfixes_cursor_notify_event_t;
| ^^^^^^ not found in `libc`
I maneged to build wasm module by commenting out x11-clipboard dependency. I tried to build this module with x11-clipboard dependencies and it was also failing until I commented out xcb dependency. It also fails if I add x11 crate. For a while I thought libc could be a problem but I had not problem building module with this dependency.
Does anyone know why some dependencies cause building process failing and how to fix it? If it's impossible to fix can someone explain me why? Thanks in advance!

Use of Rust alignment feature (issue 33626)

RFC 1358 suggested an alignment attribute #[repr(align="N")] and it was accepted. Rust issue 33626 incorporated the feature into the nightly version.
I'm unable to use this feature with rustc 1.19.0-nightly (777ee2079 2017-05-01). If I compile without the feature gate (#![feature(repr_align)]):
#[repr(align="16")]
struct Foo {
bar: u32,
}
I get the following error statement:
error: the struct `#[repr(align(u16))]` attribute is experimental (see issue #33626)
--> foo.rs:3:1
|
3 | / struct Foo {
4 | | bar: u32,
5 | | }
| |_^
|
= help: add #![feature(repr_align)] to the crate attributes to enable
When I compile with the feature gate, the error message says:
error[E0552]: unrecognized representation hint
--> foo.rs:3:8
|
3 | #[repr(align="16")]
| ^^^^^^^^^^
I also tried the version suggested by the first error message (even though it does not comply with the issue), but still without success. What is the correct way to use the alignment feature?
You can make that feature work when combined with
attribute literals (Playground):
#![feature(repr_align)]
#![feature(attr_literals)]
#[repr(align(16))]
struct Foo {
bar: u32,
}
This is known to work in the latest development version (PR #41673). Searching "repr align" in the Rust compiler's codebase,
all occurrences rely on attribute literals, so it seems likely that the documented form repr(align="N") is not yet supported.

error: the `?` operator is not stable error when installing cargo-update

I am trying to update cargo: cargo install cargo-update, but I'm faced with the following error:
Compiling semver-parser v0.7.0
error: the `?` operator is not stable (see issue #31436)
--> /home/netlab/.cargo/registry/src/github.com-1ecc6299db9ec823/semver-parser-0.7.0/src/version.rs:56:26
|
56 | let (pre, pre_len) = common::parse_optional_meta(&s[i..], b'-')?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: the `?` operator is not stable (see issue #31436)
--> /home/netlab/.cargo/registry/src/github.com-1ecc6299db9ec823/semver-parser-0.7.0/src/version.rs:58:30
|
58 | let (build, build_len) = common::parse_optional_meta(&s[i..], b'+')?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: the `?` operator is not stable (see issue #31436)
--> /home/netlab/.cargo/registry/src/github.com-1ecc6299db9ec823/semver-parser-0.7.0/src/range.rs:133:26
|
133 | let (pre, pre_len) = common::parse_optional_meta(&s[i..], b'-')?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It depends on your Rust version — with versions of Rust before 1.13 you will receive the error because the operator wasn't stable in these versions.
Your error message refers to a GitHub issue number.

Resources