Skip to content

Commit a1a033f

Browse files
authored
Add development documentation. (#91)
1 parent ce3d8f4 commit a1a033f

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed

CONTRIBUTING.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Contributing
2+
3+
`tskit_rust` is a free and open-source project that welcomes contributions from everyone.
4+
The [developer](https://github.com/molpopgen/tskit_rust/blob/main/DEVELOPMENT.md)] and [design](https://github.com/molpopgen/tskit_rust/blob/main/DESIGN.md) guides will help you get started.
5+
6+
We have an active slack group where tskit and associated projects are discussed.
7+
If you wish to join email [[email protected]](mailto:[email protected]).
8+
9+
We ask all users to follow our [code of conduct](https://github.com/tskit-dev/.github/blob/main/CODE_OF_CONDUCT.md)
10+
when interacting with the project.

DESIGN.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Design
2+
3+
## Including the `tskit` `C` code.
4+
5+
We manually copy the source files from the current stable release.
6+
We cannot use submodules because the `tskit` repository contains symbolic links, which causes problems with `bindgen`.
7+
8+
## Key principles
9+
10+
* Don't reinvent the wheel.
11+
If there is a `C` function in place, call it.
12+
Calling existing functions takes advantage of the high test coverage of `tskit`.
13+
* Prefer rust idioms where possible.
14+
For example, provide iterator types instead of manual `next/advance` functions.
15+
See how `NodeIterator` works by looking in `src/traits.rs` and `src/trees.ts` for an example of a reusable iterator pattern.

DEVELOPMENT.md

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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

Comments
 (0)