llvm-sys - Didn't find usable system-wide LLVM - rust

I'm trying to learn LLVM to make a programming language using Rust. I am using the llvm-sys crate that wraps around the LLVM API.
I have installed LLVM : LLVM-8.0.0-win64
My dependencies in cargo.toml
[dependencies]
llvm-sys = "80.1.1"
When I run cargo run I get the following error,
Updating crates.io index
Compiling memchr v2.2.1
Compiling lazy_static v1.4.0
Compiling regex-syntax v0.6.12
Compiling semver-parser v0.7.0
Compiling libc v0.2.65
Compiling cc v1.0.47
Compiling thread_local v0.3.6
Compiling semver v0.9.0
Compiling aho-corasick v0.7.6
Compiling regex v1.3.1
Compiling llvm-sys v80.1.1
error: failed to run custom build command for `llvm-sys v80.1.1`
Caused by:
process didn't exit successfully: `C:\Users\Name\Desktop\Carbon\carbon-lang\target\debug\build\llvm-sys-ed5d351b1ae6a41b\build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=LLVM_SYS_80_PREFIX
cargo:rerun-if-env-changed=LLVM_SYS_80_IGNORE_BLACKLIST
cargo:rerun-if-env-changed=LLVM_SYS_80_STRICT_VERSIONING
cargo:rerun-if-env-changed=LLVM_SYS_80_NO_CLEAN_CFLAGS
cargo:rerun-if-env-changed=LLVM_SYS_80_USE_DEBUG_MSVCRT
cargo:rerun-if-env-changed=LLVM_SYS_80_FFI_WORKAROUND
Didn't find usable system-wide LLVM.
--- stderr
thread 'main' panicked at 'Failed to execute "C:\\Program Files\\LLVM\\bin\\llvm-config": Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }', src\libcore\result.rs:1165:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
But I have set the LLVM_SYS_80_PREFIX as C:\Program Files\LLVM which is where the bin folder is.
Should the llvm-config file be separately installed? I could not find it anywhere.
FYI: I'm on Windows 10
Thanks for the help!

llvm-config is a developer-side tool, it is not shipped with binaries. You need to build LLVM from sources.

LLVM is not shipped with a component called llvm-config.exe, I am not sure how to bypass though.

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 build error: unknown `--json` option `future-incompat`

I am trying to build a basic application for the Adafruit CLUE using Rust.
When using the peripheral access crate (PAC) everything works fine, but I would like to use the HAL crate from Nordic Semiconductors.
I set up a very basic project which uses their nrf52840-hal crate. When running cargo build, I get the following error (full build log with --verbose):
Updating crates.io index
Compiling semver-parser v0.7.0
Compiling cortex-m v0.7.4
Compiling proc-macro2 v1.0.37
Compiling nb v1.0.0
Compiling unicode-xid v0.2.3
Compiling syn v1.0.92
Compiling vcell v0.1.3
Compiling void v1.0.2
Compiling bitfield v0.13.2
Compiling cortex-m-rt v0.7.1
Compiling critical-section v0.2.7
Compiling typenum v1.15.0
info: syncing channel updates for 'nightly-2021-08-18-x86_64-unknown-linux-gnu'
Compiling az v1.2.0
Compiling nrf52840-pac v0.11.0
info: latest update on 2021-08-18, rust version 1.56.0-nightly (30a0a9b69 2021-08-17)
Compiling fixed v1.15.0
Compiling cfg-if v1.0.0
info: component 'rust-src' is up to date
info: component 'rust-std' for target 'riscv32imac-unknown-none-elf' is up to date
info: component 'rust-std' for target 'riscv32imc-unknown-none-elf' is up to date
info: component 'rust-std' for target 'thumbv6m-none-eabi' is up to date
info: component 'rust-std' for target 'thumbv7em-none-eabi' is up to date
info: component 'rustfmt' for target 'x86_64-unknown-linux-gnu' is up to date
warning: Force-skipping unavailable component 'rust-std-avr-specs/avr-atmpeg328p.json'
Compiling bare-metal v1.0.0
error: unknown `--json` option `future-incompat`
Compiling half v1.8.2
error: could not compile `critical-section`
warning: build failed, waiting for other jobs to finish...
error: build failed
I am using rustup with the stable toolchain on Ubuntu 20.04 (using nighly 2022-05-03 does not change anything to the error message). Rustup version output is:
rustup 1.24.3 (ce5817a94 2021-05-31)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.60.0 (7737e0b5c 2022-04-04)`
The full project is available here.
My .cargo/config.toml file is:
[build]
target = "thumbv7em-none-eabihf"
rustflags = [
"-C", "link-arg=-Tlink.x",
]
The Cargo.toml is:
[package]
name = "hal-test"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cortex-m-rt = "0.7.1"
nrf52840-hal = "0.15.0"
panic-halt = "0.2.0"
and the src/main.rs file is:
#![no_std]
#![no_main]
use panic_halt as _;
#[cortex_m_rt::entry]
fn main() -> ! {
loop {}
}
I tried to go through the dependency tree but I failed to find where this future-incompat option is added, given that it is passed plenty of times to rustc and it succeeds.
I would appreciate any pointers as to where to look further.
Update 2022-05-06: building the project with the exact same toolchain version on Ubuntu 21.04 works, I'll have to investigate further.
The issue was fixed by switching away from the rustup snap and using the recommended installation method of running the shell script (https://www.rust-lang.org/tools/install).

Cargo: "No such file or directory" error when compiling a Rust project

I'm trying to build a Rust project with cargo (on Ubuntu 20.04), and it seems I'm running into an error when compiling some of the dependencies.
I run cargo build --release, all of the external crates are downloaded, then it begins compiling some of them, but eventually runs into the error below:
> cargo build --release
Updating crates.io index
Downloaded ansi_term v0.12.1
Downloaded phf_generator v0.7.24
Downloaded cmake v0.1.48
...
Downloaded 95 crates (6.9 MB) in 2.51s (largest was `wabt-sys` at 2.6 MB)
Compiling libc v0.2.112
...
Compiling unicode-width v0.1.9
error: couldn't create a temp dir: No such file or directory (os error 2) at path "/home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-1.0.0/home/user/rustcH0KskO"
...
And I get the exact same error for 15 other packages. It's obvious why the path wouldn't exist, but I'm not sure where to begin fixing this issue.
I've tried uninstalling and reinstalling Rust, but I'm new to the language and not sure what to do beyond that, so help is much appreciated. Thanks!
I linked it above, but the project in question is https://github.com/iden3/circom.

Rust compiler can't find crate for 'std'

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.

Cargo Build Error - File Missing

Trying to compile the example given at https://github.com/gifnksm/twitter-api-rs on a 32bit Windows 10 machine, I get the following error - any ideas as to what to do?
(I had a previous issue with the curl-sys compilation, which required the environment variable CFLAGS setting to '-mmmx -msse' )
D:\Proj\Rust\projects\twittest>cargo build --verbose
Fresh rustc-serialize v0.3.16
Fresh pkg-config v0.3.5
Fresh libc v0.1.10
Fresh winapi v0.2.2
Fresh winapi-build v0.1.1
Fresh matches v0.1.2
Fresh log v0.3.2
Fresh url v0.2.37
Fresh advapi32-sys v0.1.2
Fresh kernel32-sys v0.1.4
Fresh rand v0.3.11
Fresh gcc v0.3.13
Fresh time v0.1.32
Compiling curl-sys v0.1.25
Running `D:\Proj\Rust\projects\twittest\target\debug\build\curl-sys-865cd014190c57f1\build-script-build`
Fresh libz-sys v0.1.8
Fresh rust-crypto v0.2.31
failed to run custom build command for `curl-sys v0.1.25`
Process didn't exit successfully: `D:\Proj\Rust\projects\twittest\target\debug\build\curl-sys-865cd014190c57f1\build-script-build` (exit code: 101)
--- stdout
cargo:rustc-link-search=D:\Proj\Rust\projects\twittest\target\debug\build\curl-sys-865cd014190c57f1\out/lib
cargo:rustc-link-lib=static=curl
cargo:root=D:\Proj\Rust\projects\twittest\target\debug\build\curl-sys-865cd014190c57f1\out
cargo:include=D:\Proj\Rust\projects\twittest\target\debug\build\curl-sys-865cd014190c57f1\out/include
cargo:rustc-flags=-l ws2_32
curlsys running: "sh" "-c" "/c/Users/Me/.cargo/registry/src/github.com-121aea75f9ef2ce2/curl-sys-0.1.25/curl/configure --with-winssl --enable-static=yes --enable-shared=no --enable-optimize --prefix=D:/Proj/Rust/projects/twittest/target/debug/build/curl-sys-865cd014190c57f1/out --without-librtmp --without-libidn --without-libssh2 --without-nghttp2 --disable-ldap --disable-ldaps --disable-ftp --disable-rtsp --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smtp --disable-gopher --disable-manual"
--- stderr
thread '<main>' panicked at 'cmd.status() return the error The system cannot find the file specified.
(os error 2)', C:\Users\Me\.cargo\registry\src\github.com-121aea75f9ef2ce2\curl-sys-0.1.25\build.rs:134
I am using http://mingw-w64.org but I suspect the problem lies with the 32bit build parameters in the library configure sh files (possibly!)
My guess is that the --prefix=D:/Proj/... part is wrong, and should be --prefix=/d/Proj/....
In https://github.com/carllerche/curl-rust/blob/master/curl-sys/build.rs#L110 , there is a hardcoded replace("C:\\", "/c/") but no handling of other unit labels.
In other words, it seems curl-rust currently does not support building when your project root is not on C:. Would it be possible to move your projects directory, or at least the code for this project?

Resources