-
Notifications
You must be signed in to change notification settings - Fork 435
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/202212272003.rgQDX8DQ-lkp@intel.com/#[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.enum
s, from Add option to generate safe and unsafe conversions for rustified enums rust-lang/rust-bindgen#2908 (comment)): [RFC] Revamp interface for enum representations rust-lang/rust-bindgen#3050.Nice to have (not critical, we could workaround if needed, etc.)
Support for Edition 2024.
unsafe extern
issue: Generateunsafe extern
blocks (Edition 2024) rust-lang/rust-bindgen#2901.unsafe extern
PR: Add support for unsafe extern blocks rust-lang/rust-bindgen#3015.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/f28d6403-d042-4ffb-9872-044388d0f9d9@lunn.ch/--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.
A way to specify a MSRV, instead of
--rust-target
(which only supports a subset of versions).--rust-target
, the kernel supported Rust 1.78.0+ andbindgen
0.65.1+, thus we picked--rust-target 1.68
, since it is the maximum stable version supported by the--rust-target
flag inbindgen
0.65.1 (and it is lower than our MSRV).RustTarget
rust-lang/rust-bindgen#2993.A way to specify an output Edition, e.g.
--rust-edition
.--rust-edition
rust-lang/rust-bindgen#3002.CI: update to v6.13-rc1.
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.)
Support
--version
without header (affects 0.69.0, fixed in 0.69.1, regressed in 0.71.0, fixed again in 0.71.1).bindgen
0.69.0 issue").bindgen --version
does not work (0.71.0 regression) rust-lang/rust-bindgen#3039.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: