-
Notifications
You must be signed in to change notification settings - Fork 0
Using Cargo
Cargo is the Rust package manager. Cargo downloads your Rust project’s dependencies, compiles your project, makes packages, and upload them to crates.io, the Rust community’s package registry.
Cargo comes bundled with rust on some platforms, and not on others. As always, it is recommended to install rust and cargo with your package manager:
Ubuntu/Debian:
[sudo] apt install cargo
Debian does not have cargo packaged in its stable
or older repositories. However, it is available in testing
/buster
and unstable
/sid
. Add one of these repositories to /etc/apt/sources.list.d/
and setup your pins appropriately. (Do read the warnings on this page, but unless you have other packages in stable
using llvm
, you shouldn't break any of your other packages.)
Fedora:
[sudo] dnf install cargo
Arch/Manjaro:
[sudo] pacman -S rustc
If rustc
/cargo
is not available for your distro, you can install it separately:
curl -sSf https://static.rust-lang.org/rustup.sh | sh
Know the dangers of curl $* | sh
! You may prefer inspecting the script before running it:
curl -sSf https://static.rust-lang.org/rustup.sh > rustup.sh
$PAGER rustup.sh # inspect the install script
sh rustup.sh # run it
cargo new your-project-name --bin
You should now have a directory containing these files:
your-project-name
├─ Cargo.toml
└─ src
└─ main.rs
You may also have a .git
directory and a .gitignore
file.
Currently, domain-coloring
is not on crates.io, but you can still add it as a dependency.
Edit Cargo.toml
and add/edit the [dependencies]
section:
[dependencies]
domain-coloring = { git = "https://github.com/pmodl/rust-domain-coloring", branch = "master" }
Finally, in src/main.rs
, add the following:
extern crate domain-coloring;
Cargo will automatically include the necessary dependencies when building your project. Here are some commands to get you started:
cargo update # install missing dependencies and update version information
cargo build # creates an unoptimized build at target/debug/your-project-name
cargo run # creates an unoptimized build at target/debug/your-project-name and runs it
cargo build --release # creates an optimized build at target/release/your-project-name
cargo run --release # creates an optimized build at target/release/your-project-name and runs it