| 1 |
Developing Rust Decimal |
| 2 |
======================= |
| 3 |
|
| 4 |
* [Setup](#setup) |
| 5 |
* [Building](#building) |
| 6 |
* [Library Versioning](#library-versioning) |
| 7 |
* [Formatting / Code Style](#formatting--code-style) |
| 8 |
* [Testing](#testing) |
| 9 |
* [Fuzzing](#fuzzing) |
| 10 |
* [Benchmarking](#benchmarking) |
| 11 |
* [Code Coverage](#code-coverage) |
| 12 |
|
| 13 |
## Setup |
| 14 |
|
| 15 |
Rust Decimal leverages [cargo make](https://github.com/sagiegurari/cargo-make) to ensure a consistent build/test/release |
| 16 |
approach. This also handles installing any additional dependencies in order to execute various commands, making getting set |
| 17 |
up and going relatively straight forward and easy. |
| 18 |
|
| 19 |
Installing this can be done using `cargo`: |
| 20 |
|
| 21 |
```shell |
| 22 |
cargo install --force cargo-make |
| 23 |
``` |
| 24 |
|
| 25 |
Once this has been installed, common tasks can be initiated with the `makers` command. |
| 26 |
|
| 27 |
## Building |
| 28 |
|
| 29 |
**Useful Make Commands:** `makers build` |
| 30 |
|
| 31 |
Building this library doesn't require any special commands and can be performed using a standard `cargo build`. |
| 32 |
|
| 33 |
### Building no-std |
| 34 |
|
| 35 |
Builds by default leverage `std`. To disable this functionality you can build Rust Decimal without any default features |
| 36 |
enabled: |
| 37 |
|
| 38 |
```shell |
| 39 |
cargo build --no-default-features |
| 40 |
``` |
| 41 |
|
| 42 |
## Library Versioning |
| 43 |
|
| 44 |
**Useful Make Commands:** `makers outdated` |
| 45 |
|
| 46 |
The general rule of thumb with Rust Decimal is to ensure that downstream dependencies are kept up to date, so long as they |
| 47 |
align with the minimum requirements of the Rust Decimal build system. As a helpful measure, a `makers` command has been created |
| 48 |
to identify any outdated dependencies within the project. On a regular basis this command is run and results evaluated for potential |
| 49 |
updates to be applied. |
| 50 |
|
| 51 |
Please note: because this is a library, the `Cargo.lock` file is not committed into the repository. This means that `cargo update` |
| 52 |
should be run before running `makers outdated`. |
| 53 |
|
| 54 |
## Formatting / Code Style |
| 55 |
|
| 56 |
**Useful Make Commands:** `makers format`, `makers clippy` |
| 57 |
|
| 58 |
To maintain consistent styling across the project, both `clippy` and `cargo fmt` are used. Github actions will |
| 59 |
check for consistent styling upon pull request however it is recommended that both of these commands are run before creating |
| 60 |
a PR. |
| 61 |
|
| 62 |
## Testing |
| 63 |
|
| 64 |
**Useful Make Commands:** `makers test-all`, `makers test-no-std`, `makers test-maths`, `makers test-serde`, `makers test-db` |
| 65 |
|
| 66 |
Testing is a critical part of the Rust Decimal development lifecycle. It helps ensure that the library is behaving correctly under |
| 67 |
a mixture of different inputs and feature configurations. |
| 68 |
|
| 69 |
There are many different test configurations defined in `Makefile.toml` to help ensure that common test cases are easy to execute locally. |
| 70 |
For the full complete list, please review `Makefile.toml` directly for all `test-*` tasks. Some useful test tasks are listed below: |
| 71 |
|
| 72 |
* `test-all`: Tests all test configurations against all features |
| 73 |
* `test-default`: Test the default configuration |
| 74 |
* `test-no-std`: Test the library against a `no-std` build |
| 75 |
* `test-maths`: Test the maths feature of the library using both legacy and default ops. |
| 76 |
* `test-serde`: Test serialization and deserialization using a mixture of serde features |
| 77 |
* `test-db`: Test a variety of database logic changes, including `diesel` and `postgres` configurations. |
| 78 |
|
| 79 |
When adding new features, please make sure to generate new tasks within the `Makefile.toml` to ensure continued |
| 80 |
coverage of your feature going forward. |
| 81 |
|
| 82 |
### Generated tests |
| 83 |
|
| 84 |
Rust Decimal includes a number of generated tests that have been generated outside the scope of this project. These are |
| 85 |
effectively CSV files that use randomized data for the `lo`, `mid` and `hi` portions of the Decimal number. |
| 86 |
|
| 87 |
Modification of these files is restricted and should not be committed. If you would like to add further generated tests then |
| 88 |
please create new files as you see fit. |
| 89 |
|
| 90 |
## Fuzzing |
| 91 |
|
| 92 |
**Useful Make Commands:** `makers fuzz` |
| 93 |
|
| 94 |
Rust Decimal includes some fuzz testing support also to help capture a wider range of testing scenarios. These can be |
| 95 |
run by using `makers fuzz`. |
| 96 |
|
| 97 |
## Benchmarking |
| 98 |
|
| 99 |
**Useful Make Commands:** `makers bench` |
| 100 |
|
| 101 |
In order to ensure that Rust Decimal runs quickly, a number of benchmarks have been created and can be executed using |
| 102 |
`makers bench`. |
| 103 |
|
| 104 |
When adding new benchmarking configurations, please ensure that you add a corresponding `Makefile.toml` task to capture the |
| 105 |
updated configuration. |
| 106 |
|
| 107 |
## Code Coverage |
| 108 |
|
| 109 |
**Useful Make Commands:** `makers coverage`, `makers codecov-open` |
| 110 |
|
| 111 |
Limited code coverage support has been added to Rust Decimal using `gcov`. A code coverage report |
| 112 |
can be generated by running `makers coverage`. Once generated, the report can be opened using `makers codecov-open`. |