# Cargo Workspaces Projets get big, having them in a single folder file per file is an abomination ## Creating a Workspace - Create the folder - Add the directory in `Cargo.toml` ```rust [workspace] members = [ "binary_project_name", ] ``` - `cargo new ` - `cargo init` if the folder is already created That's it, now you can continue on with the development, is similar to nesting crates. A "base workspace" `cargo.toml` will only hold workspaces and maybe some other information. For now know that the base can't hold dependencies or package name. A `Workspace` Crate is only that, a crate to organize other packages. ## Creating a Second Package ```rust [workspace] members = [ "binary_project_name", "library_project_name", ... ] ``` - Repeat If we want to make a project depend on another ```rust // Cargo.toml of a project x [dependencies] project_y = {"../project_y_fodler"} ``` Interdependencies must be explicit. `cargo build` -> Will build all packages `cargo run` -> will run all packages? `cargo run -p ` -> will run the specified packages ## Depending on External Packages - add `crate_name = "Semantic.Version.Number"` to cargo.toml under [dependencies] This dependency will be local to the package, not to every one. We should specify to each `cargo.toml` that does depend on a crate, it will not duplicate the download or anything strange, it is to declare its usage. ## Adding Tests to a Workspace `cargo test` will run ALL the test in all the crates by default, do the same as with `cargo run` ## Publishing a Workspace You can't, publish for each crate. === # Installing Binaries from `Crates.io` with `cargo install` `cargo install ` They are installed at `$HOME/.cargo/bin` # Extending with custom commands Basically, anything in `$PATH` that has a name `cargo-somethign` can be run as `cargo something` and will be listen when doing `cargo --list`. There are crates that are actual extensions to `cargo` and then amplify the experience.