Files
systemd/.editorconfig
Christian Brauner 770c05374e meson: add -Drust= for programs written in Rust
Add optional support for programs written in Rust. Nothing else
changes. libsystemd-shared, libsystemd and the NSS and PAM modules stay
C and a program written in Rust links libsystemd-shared dynamically
just like the C programs do. Rust code gets core. There's no std, the
alloc crate isn't used either and there are no external crates.

The option is a feature and defaults to auto. We need rustc >= 1.85 and
bindgen >= 0.71.1 which is exactly what Debian 13 ships. 1.85 is the
minimum supported Rust version and we hand it to bindgen as well so the
generated bindings never require a newer compiler than the hand-written
code. bindgen 0.72.0 is refused as it generates code that doesn't
compile. With auto the toolchain is used when it's found and
-Drust=enabled fails loudly when it isn't.

Rust support also needs meson 1.4.0 for the rust module's bindgen()
integration. The tree keeps its meson floor and -Drust=auto silently
turns itself off on older meson. Cross-compilation isn't supported yet
as bindgen would need to be told about the target. HAVE_RUST tells
units, man pages and tests whether Rust programs are built.

bindgen loads libclang at runtime so finding the binary proves nothing
about being able to generate bindings. So run it once at configure time
over tools/bindgen-probe.h. That reports the libclang version, which is
shown in the summary, and contains the construct bindgen < 0.72.1
mishandles with libclang >= 22. A broken combination is thus refused or
disables Rust support instead of failing the build later.

The lints and the codegen options are project-wide rustc arguments.
Warnings are only errors with --werror just like for C. The lint set is
the kernel's:

- unsafe operations need an unsafe block
- every unsafe block needs a SAFETY comment and every unsafe function a
  Safety section, enforced via clippy's undocumented_unsafe_blocks and
  friends
- public items need docs
- the pointer cast lints keep raw pointer handling explicit

Overflow checks are enabled in every build type. rustc's default
depends on the optimization level and meson always passes
overflow-checks=no but Rust code shouldn't get to wrap silently where C
code checks. Everything is built with panic=abort. Unwinding couldn't
cross the C frames of an event loop anyway and without std there's no
unwinder. meson passes source paths relative to the build directory and
that's what file!() and thus CODE_FILE= in the journal would show. So
remap the prefix away like PROJECT_FILE does for C.

rustfmt.toml and .clippy.toml carry the formatting and lint settings
for Rust code. rustfmt uses its defaults except for the line length the
tree already uses and clippy gets the MSRV. The edition is 2021 for the
whole project and .editorconfig learns about *.rs files.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-10-23 16:31:43 +02:00

52 lines
954 B
INI

# EditorConfig configuration for systemd
# http://EditorConfig.org
# NOTE: If you update this file make sure to update .dir-locals.el and .vimrc,
# too.
# Top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file, utf-8 charset
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
[NEWS]
indent_style = space
indent_size = 4
# Match config files, set indent to spaces with width of eight
[*.{c,h}]
indent_style = space
indent_size = 8
max_line_length = 109
[{*.sh,mkosi.build,mkosi.prepare,mkosi.postinst,shell-completion/zsh/_*}]
indent_style = space
indent_size = 4
[meson.build]
indent_style = space
indent_size = 8
[*.rs]
indent_style = space
indent_size = 4
max_line_length = 109
[man/*.xml]
indent_size = 2
indent_style = space
max_line_length = 109
[docs/**/*.css]
indent_style = space
indent_size = 2
[docs/**/*.html]
indent_style = space
indent_size = 2