rust-cargo

Can I install a library using Cargo without a Cargo.toml?

感情迁移 提交于 2019-11-29 17:15:39
问题 I am going through Rust's getting started and I need to get the rand crate on my system. I'm not doing the Cargo packaging stuff (e.g. creating Cargo.toml ) because I was interested in the language, not packaging. Can I install the rand library on my system without creating a Cargo.toml using the cargo command? $ cargo install rand Updating registry `https://github.com/rust-lang/crates.io-index` specified package has no binaries 回答1: Practical answer No. Use Cargo. It's extremely easy to use

How to pass rustc flags to cargo?

情到浓时终转凉″ 提交于 2019-11-29 13:43:32
问题 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? 回答1: 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

What exactly is considered a breaking change to a library crate?

半腔热情 提交于 2019-11-29 13:08:09
问题 Rust crates use Semantic Versioning. As a consequence, each release with a breaking change should result in a major version bump. A breaking change is commonly considered something that may break downstream crates (code the depends on the library in question). However, in Rust a whole lot has the potential of breaking downstream crates. For example, changing (including merely adding to ) the set of public symbols is possibly a breaking change, because downstream crates can use glob-imports (

How to define test-only dependencies?

牧云@^-^@ 提交于 2019-11-29 10:32:06
问题 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? 回答1: 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

How can I set default build target for Cargo?

孤街醉人 提交于 2019-11-29 10:28:39
I tried to make 'Hello World' in Rust using this tutorial , but the build command is a bit verbose: cargo +nightly build --target wasm32-unknown-unknown --release Is it possible to set the default target for cargo build ? I guess you could use a cargo configuration file to specify a default target-tripple for you project: https://doc.rust-lang.org/cargo/reference/config.html In you project's root create a .cargo directory and a config file in it with the following contents: [build] target = "wasm32-unknown-unknown" As listed in the Cargo documentation , you can create a .cargo/config and

Can tests be built in release mode using Cargo?

谁都会走 提交于 2019-11-29 09:30:22
I'm using cargo build --release to build my project in release configuration and cargo test to build and run my tests. However, I'd like to also build my tests in release mode; can this be done using cargo? huon cargo test --release exists, but it is slightly different than just enabling optimizations. For example, debug assertions become disabled. You can also set opt-level in the [profile.test] section of your Cargo.toml, as Viktor Dahl suggests . 来源: https://stackoverflow.com/questions/29818084/can-tests-be-built-in-release-mode-using-cargo

Can Cargo download and build dependencies without also building the application?

≯℡__Kan透↙ 提交于 2019-11-29 09:13:43
Is there a way to tell Cargo to install and build all my dependencies, but not attempt to build my application? I thought cargo install would do that, but it actually goes all the way to building my app too. I want to get to a state where cargo build would find all dependencies ready to use, but without touching the /src directory. What I'm really trying to accomplish: I'm trying to build a Docker image for a Rust application, where I'd like to do the following steps: Build time ( docker build . ): import a docker image with rust tooling installed add my Cargo.toml and Cargo.lock files

Does cargo install have an equivalent update command?

半城伤御伤魂 提交于 2019-11-28 21:00:56
I'd like to update a package that I used cargo install to globally install packages, such as rustfmt or racer. I can't find a way to update an installed package without first deleting it (via cargo uninstall ) and then running the install command again. Is there an update command? Nicolai Fröhlich As of Cargo 1.36.0, you can now use the following command(s) on a nightly toolchain instead of using the cargo-update crate to update crates to their latest version: rustup install nightly cargo +nightly install -Z install-upgrade <crate> This came from pull request #6798 (Add install-upgrade) . How

How can the location of Cargo's configuration directory be overridden?

那年仲夏 提交于 2019-11-28 10:22:34
It seems that the default behavior of Cargo when searching for its configuration directory is to look in the current user's home directory ( ~/.cargo on my system). How can this behavior be modified to make Cargo look in a user-supplied directory instead? aSpex Environment variables Cargo reads You can override these environment variables to change Cargo's behavior on your system: CARGO_HOME — Cargo maintains a local cache of the registry index and of git checkouts of crates. By default these are stored under $HOME/.cargo , but this variable overrides the location of this directory. Once a

Is it possible to have Cargo always show warnings?

筅森魡賤 提交于 2019-11-28 09:10:58
I'm using watch with cargo , in order to quickly see compile time errors. However, cargo build will only show errors when building the first time. $ cargo build Compiling clayman v0.0.1 src/core_math/vector.rs:8:5: 13:6 warning: method is never used: `New`, #[warn(dead_code)] on by default src/core_math/vector.rs:8 pub fn New(x: i32, y: i32) -> Vector { src/core_math/vector.rs:9 Vector { src/core_math/vector.rs:10 x: x, src/core_math/vector.rs:11 y: y src/core_math/vector.rs:12 } src/core_math/vector.rs:13 } src/core_math/vector.rs:8:5: 13:6 warning: method `New` should have a snake case name