Cannot compile the ring crate: file not found for module `montgomery` - rust

Cargo is not compiling with the following error:
$ cargo build
Compiling ring v0.12.1
error[E0583]: file not found for module `montgomery`
-->
C:\Users\jmccrae\.cargo\registry\src\github.com1ecc6299db9ec823\ring-0.12.1\src\arithmetic/arithmetic.rs:15:9
|
15 | pub mod montgomery;
| ^^^^^^^^^^
|
= help: name the file either arithmetic\montgomery.rs or arithmetic\montgomery\mod.rs inside the directory
"C:\\Users\\jmccrae\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\ring-0.12.1\\src\\arithmetic"
The project was a new project with Cargo.toml modified to include a dependency to the most recent version (0.12.1) of the ring crate. The Cargo.toml is as follows:
[package]
name = "testring"
version = "0.1.0"
authors = ["John McCrae <john#mccr.ae>"]
[dependencies]
ring = "0.12.1"
The required file seems to actually exist:
$ ls C:\\Users\\jmccrae\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\ring-0.12.1\\src\\arithmetic
arithmetic.rs montgomery.rs
The cargo version is cargo 0.25.0-nightly (930f9d949 2017-12-05) and it is running on MINGW.
Is there anything wrong with the compiler set-up?

This is an issue with Ring and Rust 1.24.0-nightly (2017-12-21). It also has an associated issue in the Rust repository.
To work around it, use an older version of Rust nightly (or avoid nightly if you can).

Related

What is the difference between [dependencies] and [dev-dependencies] in Cargo.toml?

In Rust, what is the difference between the two types of dependencies? It seems that the dev-dependency is conditional/ invoked at a certain time only.
If I include a crate in dev-dependencies, it gives me an error:
$ cargo build
Compiling <> ()
error[E0432]: unresolved import `uuid`
--> / |
28 | use uuid::Uuid;
| ^^^^ use of undeclared crate or module `uuid`
Cargo.toml content (clipped)
[package]
<clipped>
[dependencies]
<clipped>
[dev-dependencies]
uuid = { version = "1.0.0",features = ["serde", "v4"] }
But if I move it to the dependency section, then there is no error.
Closest related post: What is the difference between [dependencies] and [dependencies.dependency-name] in Cargo.toml?
Simple: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#development-dependencies
They are dependencies that only get included / built for examples, tests, and benchmarks.
Most importantly, they will not be included when you run a simple cargo build.

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!)

Problems installing Inari library

I am new to Rust, so this could be a stupid mistake, but I can't figure out how to fix it.
The problem
I tried to install Inari (a Rust implementation of interval arithmetic, https://crates.io/crates/inari). But when I try to compile the project, I get some errors:
Compiling inari v1.0.0
error: RUSTFLAGS='-Ctarget-cpu=haswell' or later is required. See https://doc.rust-lang.org/rustc/codegen-options/#target-cpu
--> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/inari-1.0.0/src/simd/x86_64.rs:174:9
|
174 | ... compile_error!("RUSTFLAGS='-Ctarget-cpu=haswell' or later is required. See https://doc.rust-lang.org/rustc/codegen-options/#target-cpu...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0425]: cannot find function `add_ru` in this scope
--> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/inari-1.0.0/src/arith.rs:25:21
|
25 | Self { rep: add_ru(x, y) }
| ^^^^^^ help: a function with a similar name exists: `add_rn`
|
...
The error says something about using Haswell, so I tried to add the following lines to Cargo.toml:
[build]
rustflags = ["-Ctarget-cpu=haswell"]
rustdocflags = ["-Ctarget-cpu=haswell"]
but it didn't change anything.
Steps to reproduce
Create a new project with cargo new project-name. Add inari as a dependancy cargo add inari. Run the project with cargo run.
Environment
cargo 1.62.1 (a748cf5a3 2022-06-08)
rustc 1.62.1 (e092d0b6b 2022-07-16)
Ubuntu 20.04.3 LTS (in WSL)
You need to put that in .cargo/config.toml, not in Cargo.toml. Alternatively, set the environment variable RUSTFLAGS before running Cargo.
See Configuration - build.rustflags - The Cargo Book.

Compile error when running cargo bench (criterion/serde)

I added following lines to the cargo.toml of my project in order to benchmark my code:
[dev-dependencies]
criterion = "0.3"
[[bench]]
name = "samples"
harness = false
After running cargo bench, I get a lot of errors similar to the following:
Compiling criterion v0.3.4
error[E0603]: module `export` is private
--> C:\Development\Rust\cargo\registry\src\github.com-1ecc6299db9ec823\criterion-0.3.4\src\connection.rs:201:17
|
201 | #[derive(Debug, Deserialize)]
| ^^^^^^^^^^^ private module
|
note: the module `export` is defined here
--> C:\Development\Rust\cargo\registry\src\github.com-1ecc6299db9ec823\serde-1.0.123\src\lib.rs:275:5
|
275 | use self::__private as export;
The error message looks to me that there is a problem between serde and criterion. But I did not find this error message in either project issues, so there may be a hidden reason in my workspace.
Some additional information:
the project is compiled using the nightly toolchain
there is just one explicit dependency (proc macros) in the cargo.toml which transitively references syn, quote and proc-macro2
The serde version and serde_derive version in your dependency graph are mismatched. You need to use cargo update to bring them in sync. The two must have the identical version number always.

Refactoring to workspace structure causes extern crate imports to not work

I need different parts of my project to use different versions of the same extern crate so I'm refactoring my Rust project to be divided into multiple packages via the workspaces system using this as a guide. Doing so is causing all my pub extern crate imports to not work.
This post is very similar to one I created very recently and then deleted - this version contains a minimal, complete, and verifiable example.
Here's my project structure
workspace_test/
root/
src/
main.rs
Cargo.toml
Cargo.toml
workspace_test/Cargo.toml:
[package]
name = "workspace_test"
version = "0.1.0"
authors = ["Phoenix <kahlo.phoenix#gmail.com>"]
[workspace]
members = [
"root"
]
[[bin]]
name = "root"
path = "root/src/main.rs"
workspace_test/root/Cargo.toml:
[package]
name = "root"
version = "0.1.0"
authors = ["Phoenix <kahlo.phoenix#gmail.com>"]
[dependencies]
time = "0.1"
workspace_test/root/src/main.rs:
pub extern crate time;
fn main() {
println!("Hello, world!");
}
This is also on github, so it can easily be cloned and cargo run'd.
This is the error:
error[E0463]: can't find crate for `time`
--> root/src/main.rs:1:1
|
1 | pub extern crate time;
| ^^^^^^^^^^^^^^^^^^^^^^ can't find crate
error: aborting due to previous error
error: Could not compile `workspace_test`.
In workspace_test/Cargo.toml you create a package with the binary root. If you execute cargo run, it runs the main.rs, but since you didn't state the dependencies in this manifest file, the error occurs. The dependency is only specified in workspace_test/root/Cargo.toml, which is not used at this point.
I assume you want to use the workspaces proposed by the RFC. You can create a workspace with virtual manifests, which must neither specify a [package] nor [[bin]], so just remove them. workspace_test/Cargo.toml now looks like this:
[workspace]
members = [
"root"
]
If you only have one executable, you can now pass the package: -p/--package
cargo run -p root
or specify the manifest path manually:
cargo run --manifest-path root/Cargo.toml
If root/Cargo.toml contains multiple targets, you can just append the --lib or --bin flags as usual. E.g. this would execute the abc-binary specified in workspace_test/root/Cargo.toml:
cargo run -p root --bin abc

Resources