@@ -10,11 +10,13 @@ Formatting
1010
1111clang-format
1212============
13+
1314``clang-format `` is configured to help you with formatting C code.
1415
1516.. note ::
1617
17- The ``.clang-format `` script requires clang 9 or newer.
18+ The ``.clang-format `` script requires clang 9 or newer. At this
19+ time ``clang-format-14 `` is used to validate formatting in CI.
1820
1921Format your Changes
2022-------------------
@@ -32,9 +34,9 @@ reformat your whole branch after the fact.
3234.. note ::
3335
3436 Depending on your installation, you might have to use the version-specific
35- ``git clang-format `` in the commands below, e.g. ``git clang-format-9 ``,
37+ ``git clang-format `` in the commands below, e.g. ``git clang-format-14 ``,
3638 and possibly even provide the ``clang-format `` binary with
37- ``--binary clang-format-9 ``.
39+ ``--binary clang-format-14 ``.
3840
3941 As an alternative, you can use the provided ``scripts/clang-format.sh ``
4042 that isolates you from the different versions.
@@ -155,20 +157,21 @@ You can always disable clang-format.
155157
156158 Installing clang-format and git-clang-format
157159--------------------------------------------
160+
158161clang-format 9 or newer is required.
159162
160- On ubuntu 18 .04:
163+ On Ubuntu 24 .04:
161164
162165- It is sufficient to only install clang-format, e.g.
163166
164167 .. code-block :: bash
165168
166- $ sudo apt-get install clang-format-9
169+ $ sudo apt-get install clang-format-14
167170
168171 - See http://apt.llvm.org for other releases in case the clang-format version
169172 is not found in the default repos.
170173
171- On fedora :
174+ On Fedora :
172175
173176- Install the ``clang `` and ``git-clang-format `` packages with
174177
432435Function names
433436==============
434437
435- Function names are NamedLikeThis().
438+ Function names are SCNamedLikeThis(). All non-static functions should
439+ be prefixed with `SC `.
436440
437441.. code-block :: c
438442
@@ -504,8 +508,6 @@ clang-format:
504508Comments
505509********
506510
507- TODO
508-
509511Function comments
510512=================
511513
@@ -551,6 +553,8 @@ Put each enum values on a separate line.
551553Tip: Add a trailing comma to the last element to force "one-value-per-line"
552554formatting in clang-format.
553555
556+ Enums exposed in a header file should be prefixed with ``SC_ ``.
557+
554558.. code-block :: c
555559
556560 enum { VALUE_ONE, VALUE_TWO }; // <- wrong
@@ -567,7 +571,15 @@ clang-format:
567571Structures and typedefs
568572***********************
569573
570- TODO
574+ Structures and typedefs use ``TitleCase `` naming. When exposed in a
575+ header file they must be prefixed with ``SC ``.
576+
577+ For example:
578+
579+ .. code-block :: rust
580+
581+ typedef struct SCPlugin_ {
582+ } SCPlugin;
571583
572584 switch statements
573585*****************
@@ -681,9 +693,8 @@ clang-format:
681693Includes
682694********
683695
684- TODO
685-
686- A .c file shall include it's own header first.
696+ A .c file shall include it's own header first, or immediately after
697+ ``suricata-common.h ``.
687698
688699clang-format:
689700 - SortIncludes: false
@@ -746,6 +757,39 @@ Banned functions
746757Also, check the existing code. If yours is wildly different, it's wrong.
747758Example: https://github.com/oisf/suricata/blob/master/src/decode-ethernet.c
748759
760+ Rust
761+ ****
762+
763+ Pure Rust Code
764+ ==============
765+
766+ Rust functions should follow normal Rust style where appropriate, for
767+ example:
768+
769+ .. code-block :: rust
770+
771+ pub fn try_new_array() -> Result<()> {
772+ Ok(())
773+ }
774+
775+ New Rust code should be formatted with ``rustfmt `` or ``cargo
776+ fmt ``. If reformatting an existing file, format and commit before
777+ making any changes. Such reformatting may be rejected in a PR based on
778+ a variety of factors.
779+
780+ FFI
781+ ===
782+
783+ Rust code that is exposed to C should follow our C code style with
784+ respect to naming. This applies to all functions marked as
785+ ``#[no_mangle] ``. For example:
786+
787+ .. code-block :: rust
788+
789+ #[no_mangle]
790+ pub extern "C" SCJbNewArray() -> *mut JsonBuilder {
791+ }
792+
749793 .. rubric :: Footnotes
750794
751795.. [llvm ] Default LLVM clang-format Style
0 commit comments