Re: [PATCH v2] rust: bindings: rename const binding using sed

From: Alice Ryhl
Date: Sun Nov 05 2023 - 06:21:16 EST


On 11/4/23 15:56, Gary Guo wrote:
Current for consts that bindgen don'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 that 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 by generated by bindgen to
remove the distinct prefix, so user of the binding crate can refer to
the name directly.

Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx>
Reviewed-by: Andreas Hindborg <a.hindborg@xxxxxxxxxxx>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@xxxxxxxxx>
Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>