|
| 1 | +# Developer's guide |
| 2 | + |
| 3 | +## Targeted rust version |
| 4 | + |
| 5 | +All development targets `stable`. |
| 6 | + |
| 7 | +## rust tool chain |
| 8 | + |
| 9 | +Install `rust` as described [here](https://www.rust-lang.org/tools/install). |
| 10 | + |
| 11 | +Then, install [rustfmt](https://github.com/rust-lang/rustfmt) and [clippy](https://github.com/rust-lang/rust-clippy), which are required to make sure that changes can pass CI tests (see below): |
| 12 | + |
| 13 | +```sh |
| 14 | +rustup component add rustfmt clippy |
| 15 | +``` |
| 16 | + |
| 17 | +### Other useful tools |
| 18 | + |
| 19 | +[tarpaulin](https://docs.rs/crate/cargo-tarpaulin/) for calculating test coverage: |
| 20 | + |
| 21 | +```sh |
| 22 | +cargo install cargo-tarpaulin |
| 23 | +``` |
| 24 | + |
| 25 | + |
| 26 | +## Continuous integration (CI) |
| 27 | + |
| 28 | +GitHub actions/work flows handle all CI: |
| 29 | + |
| 30 | +* `rustfmt` checks code formatting |
| 31 | +* `clippy` checks for code "lint". |
| 32 | +* The library is built, and tests are run, against both rust `stable` and `beta`. |
| 33 | + |
| 34 | +### More about clippy |
| 35 | + |
| 36 | +`clippy` is a very opinionated code "linter". |
| 37 | +Any changes must pass all `clippy` checks. |
| 38 | +Some of these checks may seem stylistic, meaning that you are being asked to replace working code with a different implementation. |
| 39 | +In these cases `clippy` is suggesting a more idiomatic approach to do what you are asking. |
| 40 | +We accept `clippy`'s recommendations for two reasons. |
| 41 | +First, it is best to respect language idioms whenever possible ("don't force rust to act like C or C++"). |
| 42 | +Second, these recommendations have been useful in learning more about rust. |
| 43 | + |
| 44 | +## Building the library |
| 45 | + |
| 46 | +```sh |
| 47 | +cargo build |
| 48 | +``` |
| 49 | + |
| 50 | +### Building examples |
| 51 | + |
| 52 | +```sh |
| 53 | +cargo build --examples |
| 54 | +``` |
| 55 | + |
| 56 | +### Release mode builds |
| 57 | + |
| 58 | +Add `--release` to any of the above. |
| 59 | +This flags adds optimizations and removes debugging symbols. |
| 60 | + |
| 61 | +## Building the documentation |
| 62 | + |
| 63 | +```sh |
| 64 | +cargo doc |
| 65 | +``` |
| 66 | + |
| 67 | +Then, point your browser at `target/doc/tskit/index.html`. |
| 68 | + |
| 69 | +## Running tests |
| 70 | + |
| 71 | +To run tests and doc tests: |
| 72 | + |
| 73 | +```sh |
| 74 | +cargo test |
| 75 | +``` |
| 76 | + |
| 77 | +To test examples: |
| 78 | + |
| 79 | +```sh |
| 80 | +cargo test --examples |
| 81 | +``` |
| 82 | + |
| 83 | +### Test coverage |
| 84 | + |
| 85 | +Using `tarpaulin`: |
| 86 | + |
| 87 | +```sh |
| 88 | +cargo tarpaulin --exclude-files '*.c' --exclude-files '*.h' -o html |
| 89 | +``` |
| 90 | + |
| 91 | +We exclude `*.c` and `*.h` because it is `tskit`'s job to manage the coverage of those files. |
| 92 | + |
| 93 | +Some notes on what `tarpaulin` does: |
| 94 | + |
| 95 | +* The coverage includes the test code itself, which is a bit annoying. |
| 96 | + In the future, we may move all tests to a separate directory and exclude them from the calculation. |
| 97 | + |
| 98 | +## Running optimized examples |
| 99 | + |
| 100 | +The default build is `debug`, which makes the examples slow. |
| 101 | +To run `release` builds of examples: |
| 102 | + |
| 103 | +```sh |
| 104 | +cargo build --release --examples |
| 105 | +``` |
| 106 | + |
| 107 | +The binaries will be in `target/release/examples/`. |
| 108 | + |
| 109 | +## Tips and tricks |
| 110 | + |
| 111 | +### Cleaning up the various builds |
| 112 | + |
| 113 | +```sh |
| 114 | +cargo clean |
| 115 | +``` |
| 116 | + |
| 117 | +### Cleaning out the dependency database |
| 118 | + |
| 119 | +```sh |
| 120 | +rm -f Cargo.lock |
| 121 | +``` |
0 commit comments