rust-cargo

How to cross compile from Mac to Linux?

二次信任 提交于 2019-12-01 02:13:37
问题 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? 回答1: Rust not having a runtime means that it doesn't have a lot of code running as part

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

感情迁移 提交于 2019-12-01 00:21:16
问题 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

error: native library `openssl` is being linked to by more than one version of the same package

送分小仙女□ 提交于 2019-11-30 18:10:18
I'm facing this problem when I try to cargo build: 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.6.7 openssl-sys v0.7.13 Cargo and Rust versions: $ cargo --version cargo 0.11.0-nightly (3ff108a 2016-05-24) $ rustc --version rustc 1.11.0-nightly (7746a334d 2016-05-28) Files: Cargo.toml Cargo.lock can't get why this doesn't compile and how to solve this problem. Thank you! The way that linking works, you can only

Disable registry update in Cargo

假装没事ソ 提交于 2019-11-30 17:50:49
How do I disable cargo update or cargo build from attempting to access github.com; but still download the appropriate package from crates.io I have a single dependency in my cargo.toml [dependencies] chrono = "0.2.14" Running cargo build E:\>cargo build Updating registry `https://github.com/rust-lang/crates.io-index` Unable to update registry https://github.com/rust-lang/crates.io-index We are blocked from github.com at work but not crates.io. Is there an option where cargo can still download the packages it needs without needing to update it's registry? If you look at the documentation for

How to include files from same directory in a module using Cargo/Rust?

扶醉桌前 提交于 2019-11-30 16:59:07
问题 I have a Cargo project consisting of three files in the same directory: main.rs , mod1.rs and mod2.rs . I want to import functions from mod2.rs to mod1.rs the same way I would import functions from mod1.rs to main.rs . I've read about the file structure required but I don't get it - naming all the imported files mod will lead to minor confusion in the editor and also this just complicates the project hierarchy. Is there a way to import/include files independently of directory structure as I

error: native library `openssl` is being linked to by more than one version of the same package

戏子无情 提交于 2019-11-30 16:54:11
问题 I'm facing this problem when I try to cargo build: 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.6.7 openssl-sys v0.7.13 Cargo and Rust versions: $ cargo --version cargo 0.11.0-nightly (3ff108a 2016-05-24) $ rustc --version rustc 1.11.0-nightly (7746a334d 2016-05-28) Files: Cargo.toml Cargo.lock can't get why

How to pass rustc flags to cargo?

六月ゝ 毕业季﹏ 提交于 2019-11-30 08:55:31
I am trying to disable dead code warnings. I tried the following cargo build -- -A dead_code ➜ rla git:(master) ✗ cargo build -- -A dead_code error: Invalid arguments. So I am wondering how would I pass rustc arguments to cargo? You can pass flags through Cargo by several different means: cargo rustc , which only affects your crate and not its dependencies. The RUSTFLAGS environment variable, which affects dependencies as well. Some flags have a proper Cargo option, e.g., -C lto and -C panic=abort can be specified in the Cargo.toml file. Add flags in .cargo/config using one of the rustflags=

How to define test-only dependencies?

最后都变了- 提交于 2019-11-30 07:49:12
I have a Rust library that implements a lint plugin. I want to include compiletest , but not require it outside of testing. What is the correct way to specify that the dependency is for testing only? Yes. Use dev-dependencies . From the Cargo docs : You can add a [dev-dependencies] section to your Cargo.toml whose format is equivalent to [dependencies] : [dev-dependencies] tempdir = "0.3" Dev-dependencies are not used when compiling a package for building, but are used for compiling tests, examples, and benchmarks. 来源: https://stackoverflow.com/questions/29857002/how-to-define-test-only

Can I make an object public for integration tests and/or benchmarks only?

白昼怎懂夜的黑 提交于 2019-11-30 06:05:11
问题 As suggested by The Book, I have moved the integration tests in my crate to a tests directory. Some of those tests use functions that I don't want to export outside of the crate, though, and I am no longer able to use them in the integration test folder. I use them for non-test purposes too, so they need to compile outside of tests too . I tried using variants of pub(restricted), but I wasn't able to make it work. Ideally I'd like to have something like pub(tests) . directory tree (the

Disable registry update in Cargo

会有一股神秘感。 提交于 2019-11-30 01:55:26
问题 How do I disable cargo update or cargo build from attempting to access github.com; but still download the appropriate package from crates.io I have a single dependency in my cargo.toml [dependencies] chrono = "0.2.14" Running cargo build E:\>cargo build Updating registry `https://github.com/rust-lang/crates.io-index` Unable to update registry https://github.com/rust-lang/crates.io-index We are blocked from github.com at work but not crates.io. Is there an option where cargo can still download