1cbd624adSopenharmony_ci# Getting Started 2cbd624adSopenharmony_ci 3cbd624adSopenharmony_ciIn order to build and test lexical, only a Rust toolchain (1.31+) is required. However, for reasons described below, we highly recommend you install a recent (1.55+) nightly toolchain. 4cbd624adSopenharmony_ci 5cbd624adSopenharmony_ci 6cbd624adSopenharmony_ci```bash 7cbd624adSopenharmony_cicargo +nightly build 8cbd624adSopenharmony_cicargo +nightly test 9cbd624adSopenharmony_ci``` 10cbd624adSopenharmony_ci 11cbd624adSopenharmony_ci# Code Structure 12cbd624adSopenharmony_ci 13cbd624adSopenharmony_ciFunctionality is generally made **public** to separate the tests from the implementation, although non-documented members is not stable, and any changes to this code is not considered a breaking change. Tests are separated from the actual implementation, and comprehensively test each individual component. 14cbd624adSopenharmony_ci 15cbd624adSopenharmony_ciFurthermore, any unsafe code uses the following conventions: 16cbd624adSopenharmony_ci 17cbd624adSopenharmony_ci1. Each unsafe function must contain a `# Safety` section. 18cbd624adSopenharmony_ci2. Unsafe operations/calls in unsafe functions must be marked as unsafe, with their safety guarantees clearly documented via a `// SAFETY:` section. 19cbd624adSopenharmony_ci 20cbd624adSopenharmony_ci# Dependencies 21cbd624adSopenharmony_ci 22cbd624adSopenharmony_ciIn order to fully test and develop lexical, a recent, nightly compiler along with following Rust dependencies is required: 23cbd624adSopenharmony_ci 24cbd624adSopenharmony_ci- Clippy 25cbd624adSopenharmony_ci- Rustfmt 26cbd624adSopenharmony_ci- Miri 27cbd624adSopenharmony_ci- Valgrind 28cbd624adSopenharmony_ci- Tarpaulin 29cbd624adSopenharmony_ci- Fuzz 30cbd624adSopenharmony_ci- Count 31cbd624adSopenharmony_ci 32cbd624adSopenharmony_ciThese dependencies may be installed via: 33cbd624adSopenharmony_ci 34cbd624adSopenharmony_ci```bash 35cbd624adSopenharmony_cirustup toolchain install nightly 36cbd624adSopenharmony_cirustup +nightly component add clippy 37cbd624adSopenharmony_cirustup +nightly component add rustfmt 38cbd624adSopenharmony_cirustup +nightly component add miri 39cbd624adSopenharmony_cicargo +nightly install cargo-valgrind 40cbd624adSopenharmony_cicargo +nightly install cargo-tarpaulin 41cbd624adSopenharmony_cicargo +nightly install cargo-fuzz 42cbd624adSopenharmony_cicargo +nightly install cargo-count 43cbd624adSopenharmony_ci``` 44cbd624adSopenharmony_ci 45cbd624adSopenharmony_ciIn addition, the following non-Rust dependencies must be installed: 46cbd624adSopenharmony_ci 47cbd624adSopenharmony_ci- Python3.6+ 48cbd624adSopenharmony_ci- python-magic (python-magic-win64 on Windows) 49cbd624adSopenharmony_ci- Valgrind 50cbd624adSopenharmony_ci 51cbd624adSopenharmony_ci# Development Process 52cbd624adSopenharmony_ci 53cbd624adSopenharmony_ciThe [scripts](https://github.com/Alexhuszagh/minimal_lexical/tree/main/scripts) directory contains numerous scripts for testing, fuzzing, analyzing, and formatting code. Since many development features are nightly-only, this ensures the proper compiler features are used. This requires a nightly compiler installed via Rustup, which can be invoked as `cargo +nightly`. 54cbd624adSopenharmony_ci 55cbd624adSopenharmony_ci- [check.sh](https://github.com/Alexhuszagh/minimal_lexical/blob/main/scripts/check.sh): Check rustfmt and clippy without formatting any code. 56cbd624adSopenharmony_ci- [fmt.sh](https://github.com/Alexhuszagh/minimal_lexical/blob/main/scripts/fmt.sh): Run `cargo fmt` and `cargo clippy` in all projects and workspaces, on nightly. 57cbd624adSopenharmony_ci- [hooks.sh](https://github.com/Alexhuszagh/minimal_lexical/blob/main/scripts/hooks.sh): Install formatting and lint hooks on commits. 58cbd624adSopenharmony_ci 59cbd624adSopenharmony_ciAll PRs must pass the following checks: 60cbd624adSopenharmony_ci 61cbd624adSopenharmony_ci```bash 62cbd624adSopenharmony_ci# Check all safety sections and other features are properly documented. 63cbd624adSopenharmony_ciRUSTFLAGS="--deny warnings" cargo +nightly build --features=lint 64cbd624adSopenharmony_ci# Ensure all rustfmt and clippy checks pass. 65cbd624adSopenharmony_ciscripts/check.sh 66cbd624adSopenharmony_ci``` 67cbd624adSopenharmony_ci 68cbd624adSopenharmony_ci# Safety 69cbd624adSopenharmony_ci 70cbd624adSopenharmony_ciIn order to ensure memory safety even when using unsafe features, we have the following requirements. 71cbd624adSopenharmony_ci 72cbd624adSopenharmony_ci- All code with local unsafety must be marked as an `unsafe` function. 73cbd624adSopenharmony_ci- All unsafe macros must have a `# Safety` section in the documentation. 74cbd624adSopenharmony_ci- All unsafe functions must have a `# Safety` section in the documentation. 75cbd624adSopenharmony_ci- All code using `unsafe` functionality must have a `// SAFETY:` section on the previous line, and must contain an `unsafe` block, even in `unsafe` functions. 76cbd624adSopenharmony_ci- If multiple lines have similar safety guarantees, a `// SAFETY:` section can be used for a block or small segment of code. 77cbd624adSopenharmony_ci 78cbd624adSopenharmony_ciIn order to very that the safety guarantees are met, any changes to `unsafe` code must be fuzzed, the test suite must be run with Valgrind, and must pass the following commands: 79cbd624adSopenharmony_ci 80cbd624adSopenharmony_ci```bash 81cbd624adSopenharmony_ci# Ensure `unsafe` blocks are used within `unsafe` functions. 82cbd624adSopenharmony_ciRUSTFLAGS="--deny warnings" cargo +nightly build --features=lint 83cbd624adSopenharmony_ci# Ensure clippy checks pass for `# Safety` sections. 84cbd624adSopenharmony_cicargo +nightly clippy --all-features -- --deny warnings 85cbd624adSopenharmony_ci``` 86cbd624adSopenharmony_ci 87cbd624adSopenharmony_ci# Algorithm Changes 88cbd624adSopenharmony_ci 89cbd624adSopenharmony_ciThe "docs" directory containing detailed descriptions of algorithms and benchmarks. If you make any substantial changes to an algorithm, you should both update the algorithm description and the provided benchmarks. 90