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?
Related
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.
I am trying to build with the Clap Yaml feature, but it errors out here.
Compiling clap v3.1.12
Building [========================> ] 44/47: clap, yaml-rust
error: could not compile `clap`
Caused by:
process didn't exit successfully: `rustc --crate-name clap --edition=2018 /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-3.1.12/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="atty"' --cfg 'feature="color"' --cfg 'feature="default"' --cfg 'feature="std"' --cfg 'feature="strsim"' --cfg 'feature="suggestions"' --cfg 'feature="termcolor"' --cfg 'feature="yaml"' --cfg 'feature="yaml-rust"' -C metadata=c304c427904608a0 -C extra-filename=-c304c427904608a0 --out-dir /home/ubuntu/Fuzzer/fuzzer/target/release/deps -L dependency=/home/ubuntu/Fuzzer/fuzzer/target/release/deps --extern atty=/home/ubuntu/Fuzzer/fuzzer/target/release/deps/libatty-a738dbd9b3c63306.rmeta --extern bitflags=/home/ubuntu/Fuzzer/fuzzer/target/release/deps/libbitflags-32a2c4a16da85e35.rmeta --extern clap_lex=/home/ubuntu/Fuzzer/fuzzer/target/release/deps/libclap_lex-9fd816bdd1aa0a27.rmeta --extern indexmap=/home/ubuntu/Fuzzer/fuzzer/target/release/deps/libindexmap-2a2b92386f84cd5f.rmeta --extern strsim=/home/ubuntu/Fuzzer/fuzzer/target/release/deps/libstrsim-aa9e0b1c28b1955e.rmeta --extern termcolor=/home/ubuntu/Fuzzer/fuzzer/target/release/deps/libtermcolor-d93b521b81ab3f3d.rmeta --extern textwrap=/home/ubuntu/Fuzzer/fuzzer/target/release/deps/libtextwrap-455b4f0f719538f2.rmeta --extern yaml_rust=/home/ubuntu/Fuzzer/fuzzer/target/release/deps/libyaml_rust-176b9c782134aa71.rmeta --cap-lints allow` (signal: 9, SIGKILL: kill)
Please advise
Here is what my dependencies in the Cargo.toml file look like:
[dependencies]
rand = "0.8.4"
libc = "0.2.122"
rand_chacha = "0.3.1"
rand_pcg = "0.3.1"
rayon = "1.5.2"
clap = { version = "3.1.12", features = ["yaml"] }
There is nothing wrong with what you've shown, but something is killing the Rust compiler.
Are you running on a Raspberry Pi or similar computer with very limited memory? If so, likely you are running out of memory during the compilation, and the Linux “OOM killer” is deciding that the compiler is a runaway process to be stopped.
You can reduce the maximum memory required by creating a Cargo configuration file (this is not Cargo.toml) and setting
[build]
jobs = 1
to avoid trying to compile multiple crates at once. Setting up a swap partition, if you do not already have one, may also be necessary (warning: this can wear out SD cards quickly; plug in a SSD or hard drive if possible).
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.
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).
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