Failed to run `rustc`: unknown codegen option: `-Zshare-generics` - rust

So I am trying to build a rust project using cargo build and receive:
error: failed to run `rustc` to learn about target-specific information
Caused by:
process didn't exit successfully: `rustc - --crate-name ___ --print=file-names -C -Zshare-generics=y -Csplit-debuginfo=unpacked --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit status: 1)
--- stderr
error: unknown codegen option: `-Zshare-generics`
I tried multiple projects, non of them worked. So tried creating a new one. Still didn't work. Removed the config file and still nothing.
My cargo version is cargo 1.66.1 (ad779e08b 2023-01-10) and rustc rustc 1.66.1 (90743e729 2023-01-10). Tried uninstalling rust (rustup self uninstall and rm -rf $HOME/.cargo) and reinstalling but still get the error.
$ rustup show
Default host: x86_64-apple-darwin
rustup home: /Users/USER/.rustup
stable-x86_64-apple-darwin (default)
rustc 1.66.1 (90743e729 2023-01-10)
I tried creating a new project after the reinstall. Still nothing so any help is appreciated.

Related

How to pass llc arguments through Rust Cargo?

I am compiling code through Rust cargo. I need to enable the llc option --nozero-initialized-in-bss to work around a bug in lld.
I tried to pass the argument through
RUSTFLAGS="-C llvm-args=--nozero-initialized-in-bss" cargo build
but it did not work, generating the following error
error: failed to run `rustc` to learn about target-specific information
Caused by:
process didn't exit successfully: `rustc - --crate-name ___ --print=file-names -C llvm-args=--nozero-initialized-in-bss --target thumbv7em-none-eabi --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit status: 1)
--- stderr
rustc -Cllvm-args="..." with: Unknown command line argument '--nozero-initialized-in-bss'. Try: 'rustc -Cllvm-args="..." with --help'
rustc -Cllvm-args="..." with: Did you mean '--lower-interleaved-accesses'?
Is it because rustc only recognizes a subset of all llc options? Or my way of passing llc options is incorrect?

pip install fastapi[all] is failing due to a rust component?

Hi I'm trying to install fastapi, but it seems to be failing when im installing orjson
Here is the full error code:
Building wheel for orjson (PEP 517) ... error
ERROR: Command errored out with exit status 1:
command: 'd:\pythonapps\fastapi_tutorial\env\scripts\python.exe' 'd:\pythonapps\fastapi_tutorial\env\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\User\AppData\Local\Temp\tmp4yope0de'
cwd: C:\Users\User\AppData\Local\Temp\pip-install-35a1h4do\orjson
Complete output (50 lines):
Compiling cfg-if v0.1.10
Compiling winapi v0.3.8
Compiling bitflags v1.2.1
Compiling ryu v1.0.5
Compiling scopeguard v1.1.0
Compiling packed_simd v0.3.3
Compiling serde v1.0.111
Compiling lexical-core v0.7.4
Compiling libc v0.2.71
Compiling version_check v0.9.2
Compiling smallvec v1.4.0
Compiling arrayvec v0.5.1
Compiling encoding_rs v0.8.23
Compiling static_assertions v1.1.0
Compiling itoa v0.4.5
Compiling orjson v3.1.0 (C:\Users\User\AppData\Local\Temp\pip-install-35a1h4do\orjson)
Compiling rand_core v0.4.2
Compiling inlinable_string v0.1.11
Compiling associative-cache v1.0.1
Compiling once_cell v1.4.0
Compiling lock_api v0.3.4
Compiling wyhash v0.3.0
Compiling pyo3 v0.10.1
error: failed to run custom build command for `pyo3 v0.10.1`
Caused by:
process didn't exit successfully: `C:\Users\User\AppData\Local\Temp\pip-install-35a1h4do\orjson\target\release\build\pyo3-dde0edb355843ae5\build-script-build` (exit code: 1)
--- stderr
Error: "Your Rust target architecture (64-bit) does not match your python interpreter (32-bit)"
warning: build failed, waiting for other jobs to finish...
thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:912:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.46.0-nightly (4fb54ed48 2020-06-14) running on x86_64-pc-windows-msvc
note: compiler flags: -Z mutable-noalias -C opt-level=3 -C panic=abort -C linker-plugin-lto -C codegen-units=1 --crate-type lib
note: some of the compiler flags provided by cargo are hidden
error: build failed
💥 maturin failed
Caused by: Failed to build a native library through cargo
Caused by: Cargo build finished with "exit code: 101": `cargo rustc --message-format json --manifest-path Cargo.toml --lib --release -- -C link-arg=-s`
Running `maturin pep517 build-wheel -i python --manylinux=off --strip=on`
Error: Command '['maturin', 'pep517', 'build-wheel', '-i', 'python', '--manylinux=off', '--strip=on']' returned non-zero exit status 1.
----------------------------------------
ERROR: Failed building wheel for orjson
Failed to build orjson
ERROR: Could not build wheels for orjson which use PEP 517 and cannot be installed directly
Please let me know what could I do? I have installed rustup and set it to nightly. Any help is greatly appreciated Thank you!
The problem is quite clear:
Your Rust target architecture (64-bit) does not match your python interpreter (32-bit)
Either upgrade your Python interpreter to 64 bit, or use rustup to install a 32 bit Rust target
Edit: Here is how you could manually target 32 bit on a x86_64 machine

Could not compile `http`: process didn't exit successfully with signal: 9, SIGKILL: kill

When running my projects which has a dependency that requires http 0.1.13, cargo stops when trying to compile it.
It was compiling just fine on my one computer, but when I went to run my project on another machine cargo exits with "Could not compile `http`":
process didn't exit successfully: rustc --crate-name http /root/.cargo/registry/src/github.com-1ecc6299db9ec823/http-0.1.13/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=60ef54382f532dbf -C extra-filename=-60ef54382f532dbf --out-dir /root/server-coordinator/target/debug/deps -L dependency=/root/server-coordinator/target/debug/deps --extern bytes=/root/server-coordinator/target/debug/deps/libbytes-951afda431db1a1b.rlib --extern fnv=/root/server-coordinator/target/debug/deps/libfnv-140d1d3e6e17478d.rlib --extern itoa=/root/server-coordinator/target/debug/deps/libitoa-3473eacee051d37a.rlib --cap-lints allow (signal: 9, SIGKILL: kill)
How can I figure out what the problem is? I'm running it on a VPS and the Linux kernel is 2.6 so I'm thinking it might have something to do with outdated compiler software.
I was getting a similar error. Reinstalling (uninstall & fresh install) the rust compiler solved the issue for me, you can also give it a try.

"Error loading target specification" when building a WebAssembly module with Cargo

I've constructed a simple Rust app as follows:
cargo new hello_world --bin
I can compile to WebAssembly using the Rust compiler as follows:
rustc +nightly --target wasm32-unknown-unknown -O src/main.rs
I'd like to use Cargo to manage external dependencies, but when I build for the same target using cargo:
cargo build --release --target wasm32-unknown-unknown
It fails as follows:
$ cargo build --release --target wasm32-unknown-unknown
error: failed to run `rustc` to learn about target-specific information
Caused by:
process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --target wasm32-unknown-unknown --crate-type bin --crate-type rlib` (exit code: 101)
--- stderr
error: Error loading target specification: Could not find specification for target "wasm32-unknown-unknown"
|
= help: Use `--print target-list` for a list of built-in targets
As the wasm32-unknown-unknown target has only recently been added to Rust, it's only available in the nightly toolchain. You have to specify that you wish to use the nightly toolchain:
cargo +nightly build --release --target wasm32-unknown-unknown
# ^^^^^^^^
You were already doing this when calling rustc directly:
rustc +nightly --target wasm32-unknown-unknown -O src/main.rs
# ^^^^^^^^
It's probably easier if you:
Use a toolchain override in your project directory:
$ rustup override set nightly
Set a default target in your project's .cargo/config:
[build]
target = "wasm32-unknown-unknown"
Then you can just cargo build --release. (It's recommended to avoid debug mode for now).

Cross-compilation to x86_64-unknown-linux-gnu fails on Mac OSX

I tried to compile one of my Rust projects to the x86_64-unknown-linux-gnu target:
$ cargo build --target=x86_64-unknown-linux-gnu
Compiling deployer v0.1.0 (file:///Users/raphael/web/deployer)
error: linking with `cc` failed: exit code: 1
|
= note: "cc"
= note: clang: warning: argument unused during compilation: '-pie'
ld: unknown option: --as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I don't know what to do with such a message. What should I do to make it work?
Here is my Cargo.toml file:
[package]
name = "deployer"
version = "0.1.0"
authors = ["..."]
[dependencies]
clap = "2.14.0"
time = "0.1.35"
slack-hook = "0.2"
Cargo version:
cargo 0.13.0-nightly (109cb7c 2016-08-19)
Rust version:
rustc 1.12.0 (3191fbae9 2016-09-23)
I tried to update everything with rustup, but I still get the same problem.
Inspired from cross-compile-rust-from-mac-to-linux, I typically install these dependencies to cross compile rust from Mac OS to Linux (e.g. for Docker containers):
rustup target add x86_64-unknown-linux-gnu
# Install a pre-built cross compiler
brew tap SergioBenitez/osxct
brew install x86_64-unknown-linux-gnu
And finally I can cross compile to Linux on Mac OS with:
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc \
cargo build --target=x86_64-unknown-linux-gnu

Resources