rust-cargo

Why can a Cargo package only have one library target?

有些话、适合烂在心里 提交于 2019-12-01 15:07:58
问题 According to its manual, Cargo packages can have multiple executable targets, but only one library target is allowed. A package can contain zero or one library crates and as many binary crates as you’d like. There must be at least one crate (either a library or a binary) in a package. Why is it limited to one? What are the reasons and benefits? 回答1: Cargo is primarily a package manager. Thus, the primary role of a package is to define a library. When we use a crate as a dependency, we only

How can I avoid running some tests in parallel?

大城市里の小女人 提交于 2019-12-01 07:44:18
问题 I have a collection of tests. There are a few tests that need to access a shared resource (external library/API/hardware device). If any of these tests run in parallel, they fail. I know I could run everything using --test-threads=1 but I find that inconvenient just for a couple of special tests. Is there any way to keep running all tests in parallel and have an exception for a few? Ideally, I would like to say do not run X, Y, Z at the same time. 回答1: As mcarton mentions in the comments, you

Using both git2 and hyper: openssl linked more than once

孤街浪徒 提交于 2019-12-01 06:53:10
I'm trying to build something which is using both hyper and git2 at the same time. Now I've got a problem with openssl being linked twice. A tip by shepmaster lead me to Cargos features and I tried that but I'm still stuck. The precise error I'm getting upon cargo build is the following: error: native library `openssl` is being linked to by more than one version of the same package, but it can only be linked once; try updating or pinning your dependencies to ensure that this package only shows up once openssl-sys v0.7.17 openssl-sys v0.9.1 As far as I can tell openssl is required both by git2

How can I run cargo tests on another machine without the Rust compiler?

允我心安 提交于 2019-12-01 06:38:49
I know that the compiler can run directly on arm-linux-androideabi , but the Android emulator (I mean emulation of ARM on x86/amd64) is slow, so I don't want to use cargo and rustc on the emulator, I only want to run tests on it. I want to cross-compile tests on my PC ( cargo test --target=arm-linux-androideabi --no-run ?), and then upload and run them on emulator, hoping to catch bugs like this . How can I run cargo test without running cargo test ? Is it as simple as running all binaries that were built with cargo test --no-run ? kennytm There are two kinds of tests supported by cargo test ,

Using both git2 and hyper: openssl linked more than once

梦想的初衷 提交于 2019-12-01 05:26:17
问题 I'm trying to build something which is using both hyper and git2 at the same time. Now I've got a problem with openssl being linked twice. A tip by shepmaster lead me to Cargos features and I tried that but I'm still stuck. The precise error I'm getting upon cargo build is the following: error: native library `openssl` is being linked to by more than one version of the same package, but it can only be linked once; try updating or pinning your dependencies to ensure that this package only

How to cross compile from Mac to Linux?

我们两清 提交于 2019-12-01 04:42:03
I wrote a little game using Rust, and I used cargo build --release to compile a release version on Mac. I tried to share this with my friend who is using Ubuntu, but when he tried to run the binary, he got the following error: cannot execute binary file: Exec format error I searched for this but found no answers. Doesn't Rust claim to have "no runtime"? Shouldn't it be able to run anywhere in binary form? Chris Emerson Rust not having a runtime means that it doesn't have a lot of code running as part of the language (for example a garbage collector or bytecode interpreter). It does still need

Can I prevent cargo from rebuilding libraries with every new project?

自古美人都是妖i 提交于 2019-12-01 03:49:34
Suppose I execute cargo new one --bin and cargo new two --bin then add the same dependency to each project's Cargo.toml and build them. Now there are two absolutely identical sets of libraries: /one/target/debug/deps/ *.rlib /two/target/debug/deps/ *.rlib They are same files and waste storage space, but really the problem is that I have to compile these libraries again for every project. It takes a very much time. There is the same problem with cargo install . Can I specify a place to store compiled libraries to avoid recompilation? Several Cargo projects might share the libraries by using the

cargo test --release causes a stack overflow. Why doesn't cargo bench?

旧时模样 提交于 2019-12-01 03:35:12
In trying to write an optimized DSP algorithm, I was wondering about relative speed between stack allocation and heap allocation, and size limits of stack-allocated arrays. I realize there is a stack frame size limit, but I don't understand why the following runs, generating seemingly realistic benchmark results with cargo bench , but fails with a stack overflow when run with cargo test --release . #![feature(test)] extern crate test; #[cfg(test)] mod tests { use test::Bencher; #[bench] fn it_works(b: &mut Bencher) { b.iter(|| { let stack = [[[0.0; 2]; 512]; 512]; }); } } kennytm To get things

How can I run cargo tests on another machine without the Rust compiler?

梦想与她 提交于 2019-12-01 03:10:44
问题 I know that the compiler can run directly on arm-linux-androideabi , but the Android emulator (I mean emulation of ARM on x86/amd64) is slow, so I don't want to use cargo and rustc on the emulator, I only want to run tests on it. I want to cross-compile tests on my PC ( cargo test --target=arm-linux-androideabi --no-run ?), and then upload and run them on emulator, hoping to catch bugs like this. How can I run cargo test without running cargo test ? Is it as simple as running all binaries

“unresolved import — maybe a missing extern” When extern declaration exists

孤人 提交于 2019-12-01 02:47:24
I have a small project which built with no issues when it was all in one big .rs file. I wanted to make it easier to work with, so I broke it up into modules, and the project is now structured like this: ├── GameState │ ├── ballstate.rs │ ├── collidable.rs │ ├── gamestate.rs │ ├── mod.rs │ └── playerstate.rs ├── lib.rs └── main.rs In ballstate.rs , I need to use the rand crate. Here's an abbreviated version of the file: extern crate rand; pub struct BallState { dir: Point, frame: BoundingBox } impl BallState { fn update_dir(&mut self) { use rand::*; let mut rng = rand::thread_rng(); self.dir.x