CONTRIBUTING.md 4,9 КБ
Newer Older
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
1
2
# Libcanard contribution guide

Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
3
4
5
6
7
## Design principles

The library is intended for use in real-time high-integrity applications.
It is paramount that its temporal properties and resource utilization are plain to model and predict statically.
The code shall follow applicable high-reliability coding guidelines as explained later in this document.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
8
The implementation shall be fully compliant with the Cyphal/CAN specification.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
9
10

The implementation and the API should be kept simple.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
11
There will be no high-level abstractions -- if that is desired, other implementations of Cyphal should be used.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

The library is intended for deeply embedded systems where the resources may be scarce.
The ROM footprint is of a particular concern because the library should be usable with embedded bootloaders.

## Directory layout

The production sources and some minimal configuration files (such as `.clang-tidy`) are located under `/libcanard/`.
Do not put anything else in there.

The tests are located under `/tests/`.
This directory also contains the top `CMakeLists.txt` needed to build and run the tests on the local machine.

There is no separate storage for the documentation because it is written directly in the header files.
This works for Libcanard because it is sufficiently compact and simple.

Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
27
28
## Standards

Niel Cansino's avatar
Niel Cansino включено в состав коммита
29
The library shall be implemented in ISO C99/C11 following MISRA C:2012.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
30
31
32
33
34
35
36
37
38
39
40
41
42
The MISRA compliance is enforced by Clang-Tidy and SonarQube.
Deviations are documented directly in the source code as follows:

```c
// Intentional violation of MISRA: <some valid reason>
<... deviant construct ...>
```

The full list of deviations with the accompanying explanation can be found by grepping the sources.

Do not suppress compliance warnings using the means provided by static analysis tools because such deviations
are impossible to track at the source code level.
An exception applies for the case of false-positive (invalid) warnings -- those should not be mentioned in the codebase.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
43
44

[Zubax C++ Coding Conventions](https://kb.zubax.com/x/84Ah) shall be followed.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
45
46
47
48
49
50
51
Formatting is enforced by Clang-Format; it is used also to fail the CI/CD build if violations are detected.

Unfortunately, some rules are hard or impractical to enforce automatically,
so code reviewers shall be aware of MISRA and general high-reliability coding practices
to prevent non-compliant code from being accepted into upstream.

## Tools
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
52

Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
53
54
The following tools are required to conduct library development locally
(check the CI workflow files for the required versions):
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
55

Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
56
57
58
59
- GCC
- Clang and Clang-Tools
- CMake
- An AMD64 machine
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
60

Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
61
62
63
You may want to use the [toolshed](https://github.com/OpenCyphal/docker_toolchains/pkgs/container/toolshed)
container for this.

Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
### Clang-Tidy

Clang-Tidy is used to enforce compliance with MISRA and Zubax Coding Conventions.
There are separate configuration files per directory:

- `/libcanard/` (the production code) is equipped with the most stringent configuration.

- `/tests/` is equipped with a separate configuration which omits certain rules that are considered
  expensive to maintain.
  This is because the test suite is intentionally kept to a somewhat lower quality bar to reduce development costs.

Clang-Tidy is invoked automatically on each translation unit before it is compiled;
the build will fail if the tool is not available locally.
To disable this behavior, pass `NO_STATIC_ANALYSIS=1` to CMake at the generation time.

### Clang-Format

Clang-Format is used to enforce compliance with MISRA and Zubax Coding Conventions.
There is a single configuration file at the root of the repository.

To reformat the sources, generate the project and build the target `format`; e.g., for Make: `make format`.

### SonarQube

SonarQube is a cloud solution so its use is delegated to the CI/CD pipeline.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
89
If you need access, please get in touch with the OpenCyphal Development Team members.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
90
91

### IDE
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
92
93

The recommended development environment is JetBrains CLion. The root project file is `tests/CMakeLists.txt`.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
94
The repository contains the spelling dictionaries for CLion located under `.idea/`, make sure to use them.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
95
96
97

## Testing

Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
98
99
100
101
102
103
104
Generate the CMake project, build all, and then build the target `test` (e.g., `make test`).
The tests are built for x86 and x86_64; the latter is why an AMD64 machine is required for local development.

At the moment, the library is not being tested against other platforms.
We would welcome contributions implementing CI/CD testing against popular embedded architectures, particularly
the ARM Cortex M series and AVR in an emulator.
As a high-integrity library, the Libcanard test suite should provide full test coverage for all commonly used platforms.
Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
105

Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
106
107
108
109
**WARNING:**
[Catch2 is NOT thread-safe!](https://github.com/catchorg/Catch2/blob/1e379de9d7522b294e201700dcbb36d4f8037301/docs/limitations.md#thread-safe-assertions)
Never use `REQUIRE` etc. anywhere but the main thread.

Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
110
111
## Releasing

Pavel Kirienko's avatar
Pavel Kirienko включено в состав коммита
112
Simply create a new release on GitHub: <https://github.com/OpenCyphal/libcanard/releases/new>