summaryrefslogtreecommitdiff
path: root/rust/Makefile
diff options
context:
space:
mode:
authorGary Guo <gary@garyguo.net>2023-11-04 17:56:56 +0300
committerMiguel Ojeda <ojeda@kernel.org>2023-12-14 22:14:01 +0300
commit743766565dc0bdeedf7db419500031c7bdc84033 (patch)
treebcc357f4dfab31ed67c4c53d62f4dd87d4180737 /rust/Makefile
parentbad098d76835c1379e1cf6afc935f8a7e050f83c (diff)
downloadlinux-743766565dc0bdeedf7db419500031c7bdc84033.tar.xz
rust: bindings: rename const binding using sed
Currently, for `const`s that bindgen doesn't recognise, we define a helper constant with const <TYPE> BINDINGS_<NAME> = <NAME>; in `bindings_helper.h` and then we put pub const <NAME>: <TYPE> = BINDINGS_<NAME>; in `bindings/lib.rs`. This is fine since we currently only have 3 constants that are defined this way, but is going to be more annoying when more constants are added since every new constant needs to be defined in two places. This patch changes the way we define constant helpers to const <TYPE> RUST_CONST_HELPER_<NAME> = <NAME>; and then use `sed` to postprocess Rust code generated by bindgen to remove the distinct prefix, so users of the `bindings` crate can refer to the name directly. Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Signed-off-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20231104145700.2495176-1-gary@garyguo.net [ Reworded for typos. ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/Makefile')
-rw-r--r--rust/Makefile2
1 files changed, 2 insertions, 0 deletions
diff --git a/rust/Makefile b/rust/Makefile
index 543b37f6c77f..2912c5e075cb 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -337,6 +337,8 @@ quiet_cmd_bindgen = BINDGEN $@
$(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
$(shell grep -Ev '^#|^$$' $(srctree)/$(src)/bindgen_parameters)
+$(obj)/bindings/bindings_generated.rs: private bindgen_target_extra = ; \
+ sed -Ei 's/pub const RUST_CONST_HELPER_([a-zA-Z0-9_]*)/pub const \1/g' $@
$(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
$(src)/bindgen_parameters FORCE
$(call if_changed_dep,bindgen)