[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANiq72m20pom+B9EmWO+91E8fjbMEob3JmvHRQ6UaXe_JmatfA@mail.gmail.com>
Date: Wed, 8 Jan 2025 15:47:20 +0100
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Viresh Kumar <viresh.kumar@...aro.org>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>, Danilo Krummrich <dakr@...hat.com>, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>, linux-pm@...r.kernel.org,
Vincent Guittot <vincent.guittot@...aro.org>, Stephen Boyd <sboyd@...nel.org>,
Nishanth Menon <nm@...com>, rust-for-linux@...r.kernel.org,
Manos Pitsidianakis <manos.pitsidianakis@...aro.org>, Erik Schilling <erik.schilling@...aro.org>,
Alex Bennée <alex.bennee@...aro.org>,
Joakim Bech <joakim.bech@...aro.org>, Rob Herring <robh@...nel.org>, linux-kernel@...r.kernel.org,
John Baublitz <john.m.baublitz@...il.com>,
Christian Poveda <christian.poveda@...rous-systems.com>,
Emilio Cobos Álvarez <emilio@...sal.io>
Subject: Re: [PATCH V6 03/15] cpufreq: Rust implementation doesn't parse BIT() macro
On Tue, Jan 7, 2025 at 12:22 PM Viresh Kumar <viresh.kumar@...aro.org> wrote:
>
> Rust isn't able to parse the macro for now, avoid using it.
To clarify, the thing that struggles with `BIT` is `bindgen`, rather than Rust.
The reason is that `bindgen` does not handle non-trivial `#define`s.
The good news is that recently work got merged to make `bindgen`
understand those that resolve to a constant by (essentially) asking
the C compiler to do so. It is the `--clang-macro-fallback` flag.
Since I wanted to try it within the kernel for a while, I just did so
for `BIT` here, and it works in an standalone header, e.g.
#include <vdso/bits.h>
#define CPUFREQ_HAVE_GOVERNOR_PER_POLICY BIT(3)
gives me:
pub const CPUFREQ_HAVE_GOVERNOR_PER_POLICY: u32 = 8;
with `bindgen` 0.71.1.
However, when I tried to make it work within the full kernel build, it
did not work. I reduced it to using `-include` flags for the C
compiler (which we pass a few in the kernel build). I created an issue
at:
https://github.com/rust-lang/rust-bindgen/issues/3069
I confirmed this by including them manually at the top of the
`bindings_helper.h` file, and it worked (I get about ~1500 extra
constants). It requires something like:
#ifdef __BINDGEN__
#include <linux/compiler-version.h>
#include <linux/kconfig.h>
#include <linux/compiler_types.h>
#endif
Plus filtering out the flags.
See the attached patch in case someone wants to play with the feature
and/or improve `bindgen`. Note: it is not a finalized patch at all,
and not intended to be applied, but it gets you a build with the
`CPUFREQ` constant available.
So we could, in principle, use it that way as a workaround. Having
said that, we still need to upgrade the `bindgen` minimum supported
version. So it may be best to simply fix the issue upstream and then
make the upgrade eventually -- `--clang-macro-fallback` is a new
feature anyway.
I also noticed a couple other issues, which strengths that suggestion,
i.e. to try to fix the sharp edges or at least get an agreed
workaround before start using the feature:
- The dependencies file (`-Wp,-MMD,file.d`) changing behavior: I
filed https://github.com/rust-lang/rust-bindgen/issues/3070.
- Duplicate definitions created (`pub const`s), e.g. for
https://elixir.bootlin.com/linux/v6.12.6/source/include/uapi/linux/pkt_sched.h#L598-L604.
I filed https://github.com/rust-lang/rust-bindgen/issues/3071 (it
may be related to
https://github.com/rust-lang/rust-bindgen/issues/3066 too).
I hope that helps!
(Cc'ing John, Christian and Emilio)
Cheers,
Miguel
View attachment "0001-TEST-rust-try-clang-macro-feedback.patch" of type "text/x-patch" (5763 bytes)
Powered by blists - more mailing lists