Unable to build with rust clap with yaml feature - rust

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).

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?

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

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.

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.

How can I specify linker flags/arguments in a build script?

I'm using Rust, bindgen, and a build script to work on some FFI bindings to a library.
This library is built using OpenMP, so when linking against it, I'd normally pass the -fopenmp flag to the compiler.
How can I get this flag to be set by build.rs when the library is built by Cargo?
Currently, building using Cargo fails, with the failing command being something like:
cc -Wl,--as-needed -Wl,-z,noexecstack -m64 -l gomp -l stdc++
...skipping dozens of paths/files...
-Wl,-Bdynamic -l dl -l rt -l pthread -l gcc_s -l c -l m -l rt -l pthread -l util
which fails with hundreds of undefined reference to 'GOMP_parallel_end' errors.
Rerunning the generated command above with the -fopenmp flag manually added succeeds.
I can specify the flag using RUSTFLAGS='-C link-args=-fopenmp' before compiling, but is there a way of specifying it from within build.rs?
This feature has been added to Cargo and was stabilized in Cargo 1.56. The accepted answer is now out-of-date.
Linker arguments can be specified in build.rs like so:
// Pass `-fopenmp` to the linker.
println!("cargo:rustc-link-arg=-fopenmp");
You cannot could not. See the sibling answer from ecstaticm0rse for an updated answer.
Before then, you can use a Cargo configuration file.
.cargo/config
[build]
rustflags = ["-C", "link-args=-fsome-artisanal-option"]
Execution
$ cargo build --verbose
Compiling example v0.1.0 (file:///private/tmp/example)
Running `rustc ...blah blah blah... -C link-args=-fsome-artisanal-option`
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-m64" ...blah blah blah... "-fsome-artisanal-option"
= note: clang: error: unknown argument: '-fsome-artisanal-option'
See also:
How to get the linker to produce a map file using Cargo
How can I globally configure a Cargo profile option?
Is it possible to specify `panic = "abort"` for a specific target?

"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).

Resources