-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bindgen
wanted features & bugfixes
#353
Comments
Hi everyone! I have opened some PRs on bindgen adding some features you needed:
I'd be happy to hear if the PRs here actually provide what you need. |
These look spot on to me. Thanks for your efforts! |
Added links above, thanks a lot @pvdrz! :) |
@ojeda Hey Miguel, is there a workaround in place for this?
I am trying to write a v4l2 driver and one of the issues I found was that the pixel formats bindings are not generated by bindgen because the V4L2_PIX_FMT_* stuff is defined using the v4l2_fourcc macro |
For something like pixel formats that are stable (given they are in Otherwise, if performance is not too much of a concern (even if cross-language LTO could reduce the cost at some point), one alternative is "executing" the macro at runtime by providing a C function that does it for the Rust side. In your case this one is likely not interesting because the important bits are the parameters to the macro, rather than the macro itself. |
For the drm fourcc pixel format codes, the drm-fourcc crate has some code which fetches all |
One question though, suppose I use the approach suggested by @bjorn3 Do I commit the bindings I generate? Asking because apparently bindings_generated.rs is not part of the kernel per-se and is only generated during build time. |
I think the bindings should be generated on the fly to ensure they stay up to date, just like bindings_generated.rs. |
well, in which case I suppose that the code to generate them (i.e. something similar to the code in the drm-fourcc crate) would have to be integrated into the kernel build system somehow? |
Indeed. There is already infrastructure to run code written in rust. See for example scripts/generate_rust_target.rs. |
Makes sense, thanks for the pointers! |
It depends. If these constants are strictly stable (unlike many kernel APIs that you may see in If you go the generated route (which many times is the only way), then indeed, you could use a host program (it does not necessarily need to be written in Rust, but as @bjorn3 mentions, the support is there, so I would recommend it -- though currently you will only have the Rust standard library available, e.g. no Another angle to think about is whether new constants will appear frequently or not. |
Note: see as well the "rust-for-linux" label in
bindgen
: https://github.com/rust-lang/rust-bindgen/labels/rust-for-linux.Features that we would like to see
Required (we almost certainly want them)
Support for a GCC-based backend.
Support non-trivial object-like macros that evaluate to a numeric value when fully expanded.
#define A ((int)1)
.#define
s using_IO*
.Support aligned members (including structs with bitfields) inside packed structs.
#[repr(C, align(...)]
inside an#[repr(C, packed)]
.struct alt_instr
: https://lore.kernel.org/all/[email protected]/#[repr(align)]
type rust-lang/rust-bindgen#2179.#[repr(packed)]
whenalign
is needed rust-lang/rust-bindgen#2734.Support a new "enum variant" kind, similar to
rustified_enum
, that provides a safe method to transform a C enum to Rust.constified_enum + rustified_enum
with conversions rust-lang/rust-bindgen#2646.Nice to have (not critical, we could workaround if needed, etc.)
Support for Edition 2024.
process_comments
via CLI.Low priority (we will likely not use them in the end)
Done (stabilized, fixed, not needed anymore, etc.)
Support
unsafe_op_in_unsafe_fn
.unsafe_op_in_unsafe_fn
rust-lang/rust-bindgen#2063.Support
_Noreturn
,[[noreturn]]
,__attribute__((noreturn))
_Noreturn
,[[noreturn]]
,__attribute__((noreturn))
rust-lang/rust-bindgen#2094.Support
typedef
s shadowing types e.g.typedef struct T *T;
.maple_*node
s (Build fail on linux-next (next-20220629 tag): the namemaple_enode
is defined multiple times #795).const struct *
andstruct *
patterns rust-lang/rust-bindgen#2304.Take advantage of
feature(core_ffi_c)
andfeature(c_size_t)
.--ctypes-prefix core::ffi
.feature(core_ffi_c)
(and possiblyfeature(c_size_t)
) rust-lang/rust-bindgen#2231.#[feature(core_ffi_c)]
when available rust-lang/rust-bindgen#2267.A way to query the Clang version being used.
bindgen
for LLVM version being used rust-lang/rust-bindgen#2138.Compile-time layout tests.
Support
static inline
functions in headers (by generating a wrapper).bindgen
currently (0.64.0) has experimental support via--wrap-static-fns --experimental
.skbuff.h
has 300+static inline
s: https://lore.kernel.org/rust-for-linux/[email protected]/--wrap-static-fns
rust-lang/rust-bindgen#2928.Raw pointer bitfield accessors.
Rust for Linux in the
bindgen
CI.CI: update to v6.12-rc5.
Bugs that we would like to see fixed
Required (we almost certainly want them)
Nice to have (probably not critical, we could workaround if needed, etc.)
Low priority (we will likely not use them in the end)
Done (stabilized, fixed, or not needed anymore, etc.)
C javadoc comments are not Markdown-escaped, triggering
rustdoc
warnings.rustdoc
warnings rust-lang/rust-bindgen#2057.Attribute
btf_type_tag
makesconst
ness of pointers disappear.btf_type_tag
makesconst
ness of pointers disappear rust-lang/rust-bindgen#2244."Unable to find libclang" problems (rust compiler not found #934), possibly related to Clang 15.
clang-sys
version rust-lang/rust-bindgen#2368.--wrap-static-fns
generates code thatreturn
s a call to avoid
function.--wrap-static-fns
generates code thatreturn
s a call to avoid
function rust-lang/rust-bindgen#2485.--wrap-static-fns
generates()
for empty parameter lists.--wrap-static-fns
generates()
for empty parameter lists rust-lang/rust-bindgen#2484.Fix the support for linking
libclang
statically.The text was updated successfully, but these errors were encountered: