How to deal with unresolved import 'concrete' issues in RUST - rust

I am new to RUST, and I am trying to use this concrete library: https://github.com/zama-ai/concrete/tree/master/concrete. I am trying to create a simple "Hello World" in RUST to see if concrete imports correctly. I followed the instructions in the aforementioned link.
Specifically, I:
Cloned the GitHub repo.
Cd into concrete folder (/concrete/concrete)
ran "cargo new play_with_fhe"
Updated the "Cargo.toml" file with the new member "play_with_me"
[workspace]
members = [
"concrete",
"concrete-npe",
"concrete-core",
"concrete-csprng",
"concrete-commons",
"concrete-tasks",
"concrete-boolean",
"play_with_fhe",
]
[profile.bench]
opt-level = 3
debug = true
lto="fat"
[patch.crates-io]
concrete = {path="concrete"}
concrete-npe = {path="concrete-npe"}
concrete-core = {path="concrete-core"}
concrete-csprng = {path="concrete-csprng"}
concrete-commons = {path="concrete-commons"}
concrete-boolean = {path= "concrete-boolean"}
play_with_fhe = {path= "play_with_fhe"}
Cd into "/concrete/concrete/play_with_fhe" and updated the "Cargo.toml" file with
[package]
name = "play_with_fhe"
version = "0.1.11"
authors = ["FHE Curious"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
concrete = "^0.1.11"
Cd into /concrete/concrete/play_with_fhe_/src and created a main.rs file running a simple code:
use concrete::*;
fn main() {
println!("Hello, world!");
}
When I try compiling it with rustc main.rs, I get told that:
error[E0432]: unresolved import `concrete`
--> main.rs:2:5
|
2 | use concrete::*;
| ^^^^^^^^ maybe a missing crate `concrete`?
error: aborting due to previous error
For more information about this error, try `rustc --explain E0432`.
How can I address this issue? Any advice would be appreciated.

Since you're trying to create your own hello world project, you don't need to clone the repository. You just need to create a project, include concrete as a dependency, and then import it. Those instructions are on the concrete page (as Stargateur notes):
% cargo new play_with_fhe
% cd play_with_fhe
Add concrete to your dependencies in Cargo.toml:
[package]
name = "play_with_fhe"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
concrete = "^0.1" # <--- This is the only change you make. The rest is template.
Then add use cargo::* to the top of your main.rs, and build it:
% cargo build
This will install everything. For more on Cargo, see Dependencies in Rust By Example.
Note that this package likely won't build correctly unless you're on an x86 architecture. For example, it won't run on an Apple M1 without Rosetta2.

Related

Problem trying to convert a rust project into a rust workspace

I am trying to create a rust workspace, having multiple binaries to build from same project
Actually I prepared structure as follow
Where external Cargo.tml contains only
[workspace]
members = ["itris-console", "autolearn" ]
And itris-console/Cargo.toml contains
[package]
name = "itris"
version = "0.1.0"
edition = "2021"
[dependencies]
rand = "0.8.5"
arr_macro = "0.1.3"
[[bin]]
name = "itris"
path = "src/main.rs"
test = false
bench = false
And autolearn/Cargo.toml is
[package]
name = "autolearn"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
I am trying to build it all from project root (the itris2 directory)
I got this problem
cargo build
error: failed to load manifest for workspace member `C:\Progetti\rust\itris2\itris-console`
Caused by:
failed to read `C:\Progetti\rust\itris2\itris-console\Cargo.toml`
Caused by:
Impossibile trovare il percorso specificato. (os error 3)
I consulted what follows but I cannot make it works
https://doc.rust-lang.org/cargo/reference/cargo-targets.html#binaries
https://stackoverflow.com/a/57630418/1055279
The itris-console and autolearn directories should not be in a src directory.
Currently path to your itris-console directory is C:\Progetti\rust\itris2\src\itris-console while it should be C:\Progetti\rust\itris2\itris-console. Remove the unnecessary src directory from the path and you are almost good to go.
Since you are on windows you also need to use escaped forward-slashes while defining the path to the bin in itris-console\Cargo.toml ("src/main.rs" -> "src\\main.rs").

Why can't Rust find the "js_sys" crate?

I'm new to rust. I'm trying to use the crate js_sys which contains a Math::log. I have included js_sys = 0.3.48 as the crate website tells me, and then use js_sys::Math::log; in main.rs. I get an error that rust cannot find the crate.
Steps to replicate:
In Cargo.toml
[package]
name = "sim"
version = "0.1.0"
authors = ["Excluded for privacy"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
js_sys = "0.3.48"
rand = "0.8.3"
In the top of my main.rs
// Luke Anglin and Tobi Solarin
use js_sys::Math::log;
use rand::prelude::*; // For the rng
const n: i32 = 1_000; // The number of trials
Error
error: no matching package named `js_sys` found
location searched: registry `https://github.com/rust-lang/crates.io-index`
perhaps you meant: js-sys
required by package `sim v0.1.0 (/Users/lukeanglin/Desktop/Probability/Project2/simulator/sim)`
Change js_sys to js-sys in your Cargo.toml and it should work. (As stated in the error you posted but easily overlooked)

Rust .exe fails to open on Windows

I'm building an app with rust. Using --cargo run --release successfully compiles the app and runs it, bringing up the GUI window for the app. However, when I manually open target/release/MyApp.exe, nothing happens. Checked when myapp.exe was last modifies shows that running --cargo run --release is updating the app.
I'm on windows 10 so I added "x86_64-pc-windows-msvc" as the build target.
[package]
name = "MuTexAlpha"
version = "0.1.0"
authors = ["Webb Hinton <wyhinton189#gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
fltk = "0.15.1"
serde = "1.0.118"
texture-synthesis = "0.8.0"
rand = "0.7.3"
num_cpus = "1.13.0"
uuid = { version = "0.8", features = ["serde", "v4"] }
image = "0.23.12"
glob = "0.3.0"
dyn-clone = "1.0.4"
colored = "2.0.0"
arboard = "1.1.0"
id_tree = "1.7.0"
id_tree_layout = "2.0.1"
typetag = "0.1"
serde_json = "1.0.61"
snafu = "0.6.10"
palette = "0.5.0"
indicatif = "0.14.0"
[build]
target = "x86_64-pc-windows-msvc"
Isn't the .exe in release the same program being executed with --cargo run --release?
I have some file dependencies in my app, might this be the cause of the issue? (compiling the app gives no errors, however)
Could this be something specifically related to windows?
Might just be a shot in the dark, but are you opening the exe using Windows Explorer?
Open up a cmd.exe window and try running it from there.

Rust: Cargo.toml error: expected item, found `[`, when trying to include nalgebra

[package]
name = "my package"
version = "0.1.0"
authors = ["me"]
edition = "2018"
[dependencies]
nalgebra = "0.18.1"
I tried to compile rust with above Cargo.toml but it gave me following error:
error: expected item, found `[`
--> Cargo.toml:1:1
|
1 | [package]
| ^ expected item
error: aborting due to previous error
I can fix this if I remove nalgebra = "0.18.1", but I can't use nalgebra package so it doesn't help me.
I think there are multiple issues with your Cargo.toml
This is not allowed:
name = "my package"
Suggestion:
name = "my-package"
There is also missing parts:
error during execution of `cargo metadata`: error: failed to parse manifest at `test/Cargo.toml`
Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present
Could you post the entire file here?
A minimum viable setup:
[package]
name = "my-package"
version = "0.1.0"
authors = ["me"]
edition = "2018"
[[bin]]
name = "radkilla"
path = "src/main.rs"
doc = false
[dependencies]
nalgebra = "0.18.1"
src/main.rs
fn main() {}
Running fmt and build:
➜ test cargo fmt ; cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.11s
The error disappeared after closing the cargo.toml file which was opened on the visual studio.

How to conditionally compile in Rust [duplicate]

I've followed quite a bit of the documentation and tried to reuse an example, but I can't get my code to work.
My Cargo.toml looks like this:
[package]
name = "Blahblah"
version = "0.3.0"
authors = ["ergh <derngummit#ahwell.com"]
[dependencies]
[[bin]]
name = "target"
path = "src/main.rs"
[features]
default=["mmap_enabled"]
no_mmap=[]
mmap_enabled=[]
I'd like to test my code locally with a different buffer origin than mmap based on what feature configuration I pass to the cargo build command. I have this in my code:
if cfg!(mmap_enabled) {
println!("mmap_enabled bro!");
...
}
if cfg!(no_mmap) {
println!("now it's not");
...
}
The compiler doesn't see the code in either of the if statement bodies, so I know that both of the cfg! statements are evaluating to false. Why?
I've read Conditional compilation in Rust 0.10? and I know it's not an exact duplicate because I'm looking for a functioning example.
The correct way to test for a feature is feature = "name", as you can see in the documentation you linked if you scroll a bit:
As for how to enable or disable these switches, if you’re using Cargo,
they get set in the [features] section of your Cargo.toml:
[features]
# no features by default
default = []
# Add feature "foo" here, then you can use it.
# Our "foo" feature depends on nothing else.
foo = []
When you do this, Cargo passes along a flag to rustc:
--cfg feature="${feature_name}"
The sum of these cfg flags will determine which ones get activated,
and therefore, which code gets compiled. Let’s take this code:
#[cfg(feature = "foo")]
mod foo {
}
In your case using the cfg! macro, this would map to cfg!(feature = "foo").

Resources