Rust compiler can't find crate for 'std' - rust

I recently downloaded and unpacked the Rust Language from this site (Linux 64-bit).
I then installed Rust using the given script in the download install.sh:
root#kali:~# /root/rust-1.9.0-x86_64-unknown-linux-gnu/install.sh
install: uninstalling component 'rustc'
install: creating uninstall script at /usr/local/lib/rustlib/uninstall.sh
install: installing component 'rustc'
install: installing component 'rust-std-x86_64-unknown-linux-gnu'
install: installing component 'rust-docs'
install: installing component 'cargo'
Rust is ready to roll.
I am trying to install a crate with cargo, but I keep running into this error:
root#kali:~# cargo install racer
Updating registry `https://github.com/rust-lang/crates.io-index`
Compiling winapi v0.2.7
Compiling bitflags v0.5.0
error: can't find crate for `std` [E0463]
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
error: can't find crate for `std` [E0463]
error: aborting due to previous error
error: failed to compile `racer v1.2.10`, intermediate artifacts can be found at `/root/target-install`
cargo install cargo-edit failed with the same result as above, so it's not limited to one particular package.
Even putting a simple program:
fn main() {
println!("Hello, world!");
}
in a file named hello.rs and running rustc hello.rs does not compile; it gives the same error: error: can't find crate for 'std' [E0463].
The download came with a directory named rust-std-x86_64-unknown-linux-gnu, which I assume is the std crate. How do I instruct rustc to find this directory when trying to locate the std crate?

The following will work for the simplest of compilations.
Assuming you extracted the tar file to, say
$HOME/rust-1.10.0-x86_64-unknown-linux-gnu
Then run
arch=x86_64-unknown-linux-gnu
dl=$HOME/rust-1.10.0-$arch
$dl/rustc/bin/rustc -L $dl/rustc/lib \
-L $dl/rust-std-$arch/lib/rustlib/$arch/lib \
hello.rs
But I'm sure a better way would be to run rustup as Chris Morgan suggest.
Coupla more points
You shouldn't compile code as root.
You may have to relogin or run bash -l to get the environment setup by rustup.
(Fellow rust newb here)

For me (Arch Linux) removing system's Rust fixed the issue.
pacman -Rc rust
I think there was a conflict among user installed Rust and system installed one.

Related

Rust flo_draw graphics library is not building

The issue I'm having are regarding a copy-pasted flo_draw example program. I am using vscode and the rust-anylizer extension. It tells me failed to run build scripts, check server logs for more information apon copying the code in. I don't know how to check these or what they are. Using cargo run from the terminal yields no better results.
I tried to copy in the code below:
// src.main.rs
use flo_draw::*;
use flo_draw::canvas::*;
fn main() {
with_2d_graphics(|| {
let canvas = create_canvas_window("Hello, world");
});
}
$ cargo run
Compiling futures v0.3.25
Compiling semver v0.11.0
Compiling flo_render_gl_offscreen v0.3.0
Compiling allsorts v0.5.1
Compiling winit v0.24.0
error: failed to run custom build command for `flo_render_gl_offscreen v0.3.0`
Caused by:
process didn't exit successfully: `/<path to program>/target/debug/build/flo_render_gl_offscreen-9d539a79f1cb257c/build-script-build` (exit status: 101)
\--- stderr
thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: \['libclang.so', 'libclang-*.so', 'libclang.so.*', 'libclang-*.so.*'\], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: \[\])"', /<path to home>/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.54.0/src/lib.rs:1959:31
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
flo_draw, or, more specifically, one of its dependencies, links to the external C library and therefore have to generate the matching API. This is done using bindgen, which requires clang to be installed in your system.
Installation instructions from the linked page:
Debian-based Linuxes
# apt install llvm-dev libclang-dev clang
Ubuntu 18.04 provides the necessary packages directly.
Arch
# pacman -S clang
Fedora
# dnf install clang-devel

rust glium compile error missing package on ubuntu

I try compile this in Rust with glium on an Ubutnu machine.
#[macro_use]
extern crate glium;
fn main() {
println!("Hello, world!");
}
It results in this error:
--- stderr
thread 'main' panicked at '`"pkg-config" "--libs" "--cflags" "fontconfig" "fontconfig >= 2.11.1"` did not exit successfully: exit status: 1
error: could not find system library 'fontconfig' required by the 'servo-fontconfig-sys' crate
--- stderr
Package fontconfig was not found in the pkg-config search path.
Perhaps you should add the directory containing `fontconfig.pc'
to the PKG_CONFIG_PATH environment variable
No package 'fontconfig' found
Package fontconfig was not found in the pkg-config search path.
Perhaps you should add the directory containing `fontconfig.pc'
to the PKG_CONFIG_PATH environment variable
No package 'fontconfig' found
', /home/matej/.cargo/registry/src/github.com-1ecc6299db9ec823/servo-fontconfig-sys-5.1.0/build.rs:34:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error[E0554]: `#![feature]` may not be used on the stable release channel
--> /home/matej/.cargo/registry/src/github.com-1ecc6299db9ec823/thiserror-1.0.38/src/lib.rs:238:34
|
238 | #![cfg_attr(provide_any, feature(provide_any))]
| ^^^^^^^^^^^
The first error says it cannot find the fontconfig library. What should I do here? How do I get that library installed? I do not know what to do with the second error, either.
OS: Ubuntu 22.04 LTS
I have added glium = "*" to cargo dependencies.
Addendum
The first error is solved after running cargo clean -
but the second error still persists. Any ideas?
Using this command in the terminal, install the required dependency:
sudo apt install libfontconfig1-dev

Build fails with Error: Pear requires a 'dev' or 'nightly' version of rustc even after a successful rustup override set nightly

Windows 10
rustup 1.23.1 (3df2264a9 2020-11-30)
default rustc 1.50.0 (cb75ad5db 2021-02-10)
project rustc 1.52.0-nightly (4a8b6f708 2021-03-11)
rocket = "0.4.4"
I'm trying to build a rust project with rocket but I always get this error when compiling, even after successfully overwriting the project's toolchain:
D:\GitHub\Learning-Rust\poke_api> rustup override set nightly
info: using existing install for 'nightly-x86_64-pc-windows-msvc'
info: override toolchain for 'D:\GitHub\Learning-Rust\poke_api' set to 'nightly-x86_64-pc-windows-msvc'
nightly-x86_64-pc-windows-msvc unchanged - rustc 1.52.0-nightly (4a8b6f708 2021-03-11)
PS D:\GitHub\Learning-Rust\poke_api> cargo build
Compiling winapi v0.3.9
Compiling serde_derive v1.0.124
Compiling rocket v0.4.7
Compiling pear_codegen v0.1.4
Compiling rocket_codegen v0.4.7
Compiling proc-macro2 v1.0.24
Compiling pq-sys v0.4.6
Compiling aho-corasick v0.6.10
Compiling serde_json v1.0.64
error: failed to run custom build command for `pear_codegen v0.1.4`
Caused by:
process didn't exit successfully: `D:\GitHub\Learning-Rust\poke_api\target\debug\build\pear_codegen-e182711746033ac9\build-script-build` (exit code: 101)
--- stderr
Error: Pear requires a 'dev' or 'nightly' version of rustc.
Installed version: 1.48.0 (2020-11-16)
Minimum required: 1.31.0-nightly (2018-10-05)
thread 'main' panicked at 'Aborting compilation due to incompatible compiler.', C:\Users\gabre\.cargo\registry\src\github.com-1ecc6299db9ec823\pear_codegen-0.1.4\build.rs:24:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
I had a similar issue while using rocket. Same error message too, Error: Pear requires a 'dev' or 'nightly' version of rustc.
If you get to the get-started page on rocket framework website. It says, "Rocket makes abundant use of Rust's syntax extensions and other advanced, unstable features. Because of this, we'll need to use a nightly version of Rust."
My issue was I was not using a nightly version of rust. Running this on my terminal in my project directory did it for me.
rustup override set nightly
If you check the cargo version for that directory after,
cargo version
you will confirm it has switched to nightly version
Failed compilation even with nightly
It looks like you have some outdated dependencies (pear-codegen probably being the one that causes trouble), updating these may resolve the compilation issues.
General notes on how to override the toolchain
Using rustups override works fine, but it is bound to your local rustup configuration and not specified inside the project.
In order to achieve this, thereby making the project more portable and allowing others to always use the correct toolchain, I would recommend the toolchain file. It can look something like this (example taken from linked page) and will accurately specify the required toolchain only for the containing project.
# rust-toolchain.toml
[toolchain]
channel = "nightly-2020-07-10"
components = [ "rustfmt", "rustc-dev" ]
targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]
profile = "minimal"
For your purposes a simple configuration like this will most likely be all you need, although adding the components you want to use would be beneficial.
[toolchain]
channel = "nightly"
My issue was with rust-analyser that wouldn't start because multiple rocket dependencies needed nightly or dev version of rustc.
These steps fixed my issue:
Switch to nightly for my rocket project by running rustup override set nightly inside the app folder.
Remove all target folders in my project. (I also had one in root)
Manually remove the faulty cached packages from cargo cache. cd ~/.cargo/registry/cache/github.com-xxxxxxxxxxxx && rm -r pear_codegen-0.1.5/

Unable to build bevy on windows rust

I am trying to use bevy game engine with rust on windows. I have x86_64-mingw installed on my machine.
I have setup the rust tool chain default to x86_64-pc-windows-gnu. I put bevy = "0.4.0" under my dependencies in the Cargo.toml.
I tried cargo build and I get the following error
error: failed to run custom build command for `syn v1.0.63`
Caused by:
could not execute process `C:\Users\USERNAME\Projects\rust-game\target\debug\build\syn-a158346a8e8b6be7\build-script-build` (never executed)
Caused by:
Access is denied. (os error 5)
warning: build failed, waiting for other jobs to finish...
error: build failed
When I tried to compile in administrator mode syn compiled but another lib was giving error
Compiling proc-macro2 v1.0.24
Compiling syn v1.0.63
Compiling serde_derive v1.0.124
Compiling serde v1.0.124
error: failed to run custom build command for `proc-macro2 v1.0.24`
Caused by:
could not execute process `C:\Users\USERNAME\Projects\rust-game\target\debug\build\proc-macro2-a1d2a8cf734884f9\build-script-build` (never exe
cuted)
Caused by:
Access is denied. (os error 5)
warning: build failed, waiting for other jobs to finish...
error: build failed
Edit:
My Antivirus was preventing it, and denying it access, so just turning my AV for sometime worked!
I've tried compiling a project that uses bevy = "0.4.0" and was able to build with the stable-x86_64-pc-windows-msvc toolchain but not with stable-x86_64-pc-windows-gnu.
In my case, bevy-glsl-to-spirv is the crate that failed to build. On the bevy book is specified that you must have VS build tools 2019 installed. They do not explicitly say that you must use the msvc toolchain but as they require you to install VS build tools 2019 I guess you must compile the code using stable-x86_64-pc-windows-msvc.
You can download VS build tools 2019 here.
Also make sure that you install the stable-x86_64-pc-windows-msvc toolchain:
rustup toolchain install stable-x86_64-pc-windows-msvc
Set this toolchain as the default toolchain.
rustup default stable-x86_64-pc-windows-msvc
Finally, make sure the toolchain has been installed and set as the default toolchain:
rustup toolchain list
You should see:
stable-x86_64-pc-windows-gnu
stable-x86_64-pc-windows-msvc (default)
Try to cargo build and it should work like a charm.

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