rust-cargo

How to compile a static musl binary of a Rust project with native dependencies?

我是研究僧i 提交于 2021-01-21 07:43:28
问题 I have a project with dependencies on Hyper and Diesel, and because of that, on native libraries OpenSSL and libpq. The project builds on nightly Rust because it uses compiler plugins. My current attempt is to build on a Docker container. I have the MUSL libc and the libraries make 'd and installed with prefix /usr/local/musl . I run cargo with the following command: (Not sure if some of the options are redundant, I'm not too well-versed with the compiler chain, and not even sure if they end

How can I specify which crate `cargo run` runs by default in the root of a Cargo workspace?

二次信任 提交于 2021-01-20 19:30:25
问题 Right now I have a Cargo workspace with three members. [workspace] members = [ "foo", "bar", "baz", ] If I run cargo run in the root directory, I get this error: error : manifest path /home/lukas/dev/mahboi/Cargo.toml is a virtual manifest, but this command requires running against an actual package in this workspace That makes sense. I can run cargo run -p foo and it works. But the thing is: foo is the only crate that is executable and I will execute it very often, so it would be nice if I

How can I specify which crate `cargo run` runs by default in the root of a Cargo workspace?

五迷三道 提交于 2021-01-20 19:29:19
问题 Right now I have a Cargo workspace with three members. [workspace] members = [ "foo", "bar", "baz", ] If I run cargo run in the root directory, I get this error: error : manifest path /home/lukas/dev/mahboi/Cargo.toml is a virtual manifest, but this command requires running against an actual package in this workspace That makes sense. I can run cargo run -p foo and it works. But the thing is: foo is the only crate that is executable and I will execute it very often, so it would be nice if I

How to check release / debug builds using cfg in Rust?

此生再无相见时 提交于 2021-01-20 17:00:08
问题 With the C pre-processor it's common to do, #if defined(NDEBUG) // release build #endif #if defined(DEBUG) // debug build #endif Cargo's rough equivalents are: cargo build --release for release. cargo build for debug. How would Rust's #[cfg(...)] attribute or cfg!(...) macro be used to do something similar? I understand that Rust's pre-processor doesn't work like C's. I checked the documentation and this page lists some attributes. (assuming this list is comprehensive) debug_assertions could

How do I change the default rustc / Cargo linker?

假如想象 提交于 2020-12-26 05:51:54
问题 I would like to make rustc use lld as a linker instead of ld in a particular crate. So I create .cargo/config in my project directory with the following: [target.x86_64-unknown-linux-gnu] linker = "ld.lld" Which leads to linker errors: $ cargo build ... = note: ld.lld: error: unable to find library -ldl ld.lld: error: unable to find library -lrt ld.lld: error: unable to find library -lpthread ld.lld: error: unable to find library -lgcc_s ld.lld: error: unable to find library -lc ld.lld: error

How do I change the default rustc / Cargo linker?

邮差的信 提交于 2020-12-26 05:51:05
问题 I would like to make rustc use lld as a linker instead of ld in a particular crate. So I create .cargo/config in my project directory with the following: [target.x86_64-unknown-linux-gnu] linker = "ld.lld" Which leads to linker errors: $ cargo build ... = note: ld.lld: error: unable to find library -ldl ld.lld: error: unable to find library -lrt ld.lld: error: unable to find library -lpthread ld.lld: error: unable to find library -lgcc_s ld.lld: error: unable to find library -lc ld.lld: error

Is it possible to apply a patch to external code in Cargo.toml?

只愿长相守 提交于 2020-12-13 03:01:10
问题 I read the Cargo manual about the patch option but it is still unclear to me. Is it possible to instruct Cargo: Get the code from this repository. Apply this patch file (my_cool_change.patch) to that code. Is making my own fork of the project the only way to do it? 回答1: It is not possible to instruct Cargo to do something like "take version 1.2.3 of crate foo-bar from crates.io and apply these arbitrary changes to the source code before compiling it". The Cargo documentation is not lying to

Is it possible to apply a patch to external code in Cargo.toml?

喜欢而已 提交于 2020-12-13 02:56:35
问题 I read the Cargo manual about the patch option but it is still unclear to me. Is it possible to instruct Cargo: Get the code from this repository. Apply this patch file (my_cool_change.patch) to that code. Is making my own fork of the project the only way to do it? 回答1: It is not possible to instruct Cargo to do something like "take version 1.2.3 of crate foo-bar from crates.io and apply these arbitrary changes to the source code before compiling it". The Cargo documentation is not lying to

How can I specify a custom Cargo output directory?

耗尽温柔 提交于 2020-11-29 05:31:38
问题 I put this in my Cargo.toml [build] target-dir = "../my-target" However, Cargo doesn't recognize this key. cargo run --release --bin my_project warning: unused manifest key: build error: failed to open: /.../project-root/target/releases/.cargo-lock Caused by: Permission denied (os error 13) The custom target dir with the environment variable works: CARGO_TARGET_DIR=../my-target cargo run --bin my_project but how can I specify '../my-target' in Cargo.toml? 回答1: [build] is a Cargo-level

How do I debug a failing cargo test in GDB?

余生颓废 提交于 2020-11-25 20:55:06
问题 I have a failing Cargo test: $ cargo test [snip] Running target/gunzip-c62d8688496249d8 running 2 tests test test_extract_failure ... FAILED test test_extract_success ... ok failures: ---- test_extract_failure stdout ---- task 'test_extract_failure' panicked at 'assertion failed: result.is_err()', /home/dhardy/other/flate2-rs/tests/gunzip.rs:19 failures: test_extract_failure test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured task '<main>' panicked at 'Some tests failed', /home