вторник, 10 декабря 2019 г.

Cargo package manager

Cargo Book
The Rust build tool and package manager.

build your project with:
> cargo build
> cargo build --release
run your project with:
> cargo run
> cargo run --release
test your project with:
> cargo test
build documentation for your project with:
> cargo doc
> cargo doc --open
> cargo doc --open --no-deps
delete targets
> cargo clean

publish a library to crates.io with:
> cargo publish

Cargo also provides a command called cargo check. This command quickly checks your code to make sure it compiles but doesn’t produce an executable:
> cargo check
 
Cargo, please create a new project called hello I can run as a binary application:
> cargo new --bin hello
Cargo, please build and run it:
> cd hello
> cargo run
Output:
>> Hello, world!

 hello
  ├── Cargo.toml
  └── src
           └── main.rs

Filename: main.rs
fn main() {
    println!("Hello, world!");
}

Filename: Cargo.toml
[package]
name = "hello"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"

[dependencies]

  
When your project is finally ready for release, you can use cargo build --release to compile it with optimizations. This command will create an executable in target/release instead of target/debug
 
Cargo has two main profiles: the dev profile Cargo uses when you run cargo build and the release profile Cargo uses when you run cargo build --release. The dev profile is defined with good defaults for development, and the release profile has good defaults for release builds.

Cargo has default settings for each of the profiles that apply when there aren’t any [profile.*] sections in the project’s Cargo.toml file. By adding [profile.*] sections for any profile you want to customize, you can override any subset of the default settings. For example, here are the default values for the opt-level setting for the dev and release profiles:
 
Filename: Cargo.toml
[profile.dev]
opt-level = 0

[profile.release]
opt-level = 3
 
More info.

Комментариев нет:

Отправить комментарий