xref: /aosp_15_r20/external/lz4/CODING_STYLE (revision 27162e4e17433d5aa7cb38e7b6a433a09405fc7f)
1*27162e4eSAndroid Build Coastguard WorkerLZ4 CODING STYLE
2*27162e4eSAndroid Build Coastguard Worker================
3*27162e4eSAndroid Build Coastguard Worker
4*27162e4eSAndroid Build Coastguard WorkerWhen contributing code and patches to the `LZ4` project, the following rules are expected to be followed for a successful merge.
5*27162e4eSAndroid Build Coastguard Worker
6*27162e4eSAndroid Build Coastguard Worker
7*27162e4eSAndroid Build Coastguard WorkerLibrary
8*27162e4eSAndroid Build Coastguard Worker-------
9*27162e4eSAndroid Build Coastguard Worker
10*27162e4eSAndroid Build Coastguard WorkerThe library's source code in `lib/` directory has a BSD 2-clause license.
11*27162e4eSAndroid Build Coastguard WorkerIt's designed to be integrated into 3rd party applications.
12*27162e4eSAndroid Build Coastguard Worker
13*27162e4eSAndroid Build Coastguard WorkerIt adheres relatively strictly to vanilla `C90`, with the following exceptions:
14*27162e4eSAndroid Build Coastguard Worker- `long long` type is required, in order to support 64-bit values
15*27162e4eSAndroid Build Coastguard Worker- Variadic Macros are used for debug mode (but not required in release mode)
16*27162e4eSAndroid Build Coastguard Worker
17*27162e4eSAndroid Build Coastguard WorkerBeyond that, all other rules and limitations of C90 must be respected, including `/* ... */` comment style only, and variable declaration at top of block only. The automated CI test suite will check for these rules.
18*27162e4eSAndroid Build Coastguard Worker
19*27162e4eSAndroid Build Coastguard WorkerThe code is allowed to use more modern variants (C99 / C11 / C23) when useful
20*27162e4eSAndroid Build Coastguard Workeras long as it provides a clean C90 backup for older compilers.
21*27162e4eSAndroid Build Coastguard WorkerFor example, C99+ compilers will employ the `restrict` keyword, while `C90` ones will ignore it, thanks to conditional macros.
22*27162e4eSAndroid Build Coastguard WorkerThis ensures maximum portability across a wide range of systems.
23*27162e4eSAndroid Build Coastguard Worker
24*27162e4eSAndroid Build Coastguard WorkerMoreover, in the interest of safety, the code has to respect a fairly strigent list of additional restrictions, provided through warning flags, the list of which is maintained within `Makefile`.
25*27162e4eSAndroid Build Coastguard WorkerAmong the less common ones, we want the source to be compatible with `-Wc++-compat`, which ensures that the code can be compiled "as is", with no modification, as C++ code. It makes it possible to copy-paste the code into other C++ source files, or the source files are just dropped into a C++ environment which then compiles them as C++ source files.
26*27162e4eSAndroid Build Coastguard Worker
27*27162e4eSAndroid Build Coastguard Worker
28*27162e4eSAndroid Build Coastguard WorkerCommand Line Interface
29*27162e4eSAndroid Build Coastguard Worker----------------------
30*27162e4eSAndroid Build Coastguard Worker
31*27162e4eSAndroid Build Coastguard WorkerThe CLI executable's source code in `programs/` directory has a GPLv2+ license.
32*27162e4eSAndroid Build Coastguard WorkerWhile it's designed to be portable and freely distributable, it's not meant to be integrated into 3rd party applications.
33*27162e4eSAndroid Build Coastguard WorkerThe license difference is meant to reflect that choice.
34*27162e4eSAndroid Build Coastguard Worker
35*27162e4eSAndroid Build Coastguard WorkerSimilar to the library, the CLI adheres relatively strictly to vanilla `C90`, and features the same exceptions:
36*27162e4eSAndroid Build Coastguard Worker- `long long` requirement for 64-bit values
37*27162e4eSAndroid Build Coastguard Worker- Variadic Macros for console messages (now used all the time, not just debug mode)
38*27162e4eSAndroid Build Coastguard Worker
39*27162e4eSAndroid Build Coastguard WorkerThe code can also use system-specific libraries and symbols (such as `posix` ones)
40*27162e4eSAndroid Build Coastguard Workeras long as it provides a backup for plain `C90` platforms.
41*27162e4eSAndroid Build Coastguard WorkerIt's even allowed to lose capabilities, as long as the CLI can be cleanly compiled on `C90`.
42*27162e4eSAndroid Build Coastguard WorkerFor example, systems without `<pthread>` support nor Completion Ports will just not feature multi-threading support, and run single threaded.
43*27162e4eSAndroid Build Coastguard Worker
44*27162e4eSAndroid Build Coastguard WorkerIn the interest of build familiarity, the CLI source code also respects the same set of advanced warning flags as the library.
45*27162e4eSAndroid Build Coastguard WorkerThat being said, this last part is debatable and could deviate in the future.
46*27162e4eSAndroid Build Coastguard WorkerFor example, there are less reasons to support `-Wc++-compat` on the CLI side, since it's not meant to be integrated into 3rd party applications.
47*27162e4eSAndroid Build Coastguard Worker
48*27162e4eSAndroid Build Coastguard Worker
49*27162e4eSAndroid Build Coastguard WorkerOthers
50*27162e4eSAndroid Build Coastguard Worker------
51*27162e4eSAndroid Build Coastguard Worker
52*27162e4eSAndroid Build Coastguard WorkerThe repository includes other directories with their own set of compilable projects, such as `tests/`, `examples/` and `contrib/`.
53*27162e4eSAndroid Build Coastguard Worker
54*27162e4eSAndroid Build Coastguard WorkerThese repositories do not have to respect the same set of restrictions, and can employ a larger array of different languages.
55*27162e4eSAndroid Build Coastguard WorkerFor example, some tests employ `sh`, and others employ `python`.
56*27162e4eSAndroid Build Coastguard Worker
57*27162e4eSAndroid Build Coastguard WorkerThese directories may nonetheless include several targets employing the same coding convention as the `lz4` library. This is in a no way a rule, more like a side effect of build familiarity.
58