1# Nearby Rust 2 3## Folder Structure 4 5Root repo of the nearby Rust components, folder structure: 6 7`/connections` nearby connections rust components 8 9`/crypto` shared crypto components 10 11`/presence` nearby presence rust components 12 13## Setup 14 15### Toolchain 16 17If you don't already have a Rust toolchain, see [rustup.rs](https://rustup.rs/). 18 19### Cargo 20 21Install [`cargo-deny`](https://github.com/EmbarkStudios/cargo-deny) 22and [`cargo-fuzz`](https://github.com/rust-fuzz/cargo-fuzz): 23 24``` 25cargo install --locked cargo-deny 26cargo install cargo-fuzz 27``` 28 29### Setting up a Docker dev environment 30 31Our project requires specific versions of system dependencies like OpenSSL and 32protobuf in order to build correctly. To make the setup of this easier you can 33use Docker to handle setting up the environment in a container. 34 35First install Docker then build and run the image from repo root: 36 37``` 38sudo docker build -t nearby_rust:v1.0 . 39sudo docker run --rm -it nearby_rust:v1.0 40``` 41 42Building the image creates a snapshot of the environment that has all of the 43system dependencies needed to start building and running all of the artifacts in 44the codebase. 45 46Running the image runs `cargo run -- check-everything` to verify all of the targets can 47successfully build and all of the tests pass in your new container environment. 48 49To open a bash shell from the container environment: 50 51``` 52sudo docker run -it nearby_rust:v1.0 bash 53``` 54 55You can also setup VSCode 56to [develop in a Docker container on a remote host](https://code.visualstudio.com/remote/advancedcontainers/develop-remote-host) 57that way you can make code changes and test them in the same environment without 58having to re-build the image. 59 60## Common tasks 61 62See `cargo run -- --help` for all the available subcommands. 63 64Check everything: 65 66``` 67cargo run -- check-everything 68``` 69 70Build everything: 71 72``` 73cargo build --workspace --all-targets 74``` 75 76Run tests: 77 78``` 79cargo test --workspace 80``` 81 82Generate Docs: 83 84``` 85cargo doc --no-deps --workspace --open 86``` 87 88Run linter on dependencies as configured in `deny.toml` <br> 89This will make sure all of our dependencies are using valid licenses and check 90for known existing security 91vulnerabilities, bugs and deprecated versions 92 93``` 94cargo deny --workspace check 95``` 96 97Update dependencies in `Cargo.lock` to their latest in the currently specified 98version ranges (i.e. transitive deps): 99 100``` 101cargo update 102``` 103 104Check for outdated dependencies 105with [cargo-outdated](https://github.com/kbknapp/cargo-outdated): 106 107``` 108cargo outdated 109``` 110 111## Benchmarks 112 113Benchmarks are in `benches`, and use 114[Criterion](https://bheisler.github.io/criterion.rs/book/getting_started.html) . 115 116``` 117cargo bench --workspace 118``` 119