[PATCH 16/16] rust: allow older version of bindgen

Paolo Bonzini posted 16 patches 1 week ago
There is a newer version of this series
[PATCH 16/16] rust: allow older version of bindgen
Posted by Paolo Bonzini 1 week ago
Cope with the old version that is provided in Debian 12 and Ubuntu 22.04.
--size_t-is-usize is needed on bindgen <0.61.0 (Debian 12, Ubuntu 22.04),
and it was removed in bindgen 0.65.0, so check for it in meson.build.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 meson.build | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index e08f226ee8a..2a292935a94 100644
--- a/meson.build
+++ b/meson.build
@@ -74,6 +74,7 @@ endif
 have_rust = false
 if not get_option('rust').disabled() and add_languages('rust', required: get_option('rust'), native: false) \
     and add_languages('rust', required: get_option('rust'), native: true)
+  bindgen = find_program('bindgen')
   rustc = meson.get_compiler('rust')
   have_rust = true
   if rustc.version().version_compare('<1.63.0')
@@ -3939,6 +3940,9 @@ if have_rust and have_system
     '--allowlist-file', meson.project_source_root() + '/.*',
     '--allowlist-file', meson.project_build_root() + '/.*'
     ]
+  if bindgen.version().version_compare('<0.65.0')
+    bindgen_args += ['--size_t-is-usize']
+  endif
   c_enums = [
     'DeviceCategory',
     'GpioPolarity',
@@ -3974,7 +3978,7 @@ if have_rust and have_system
     dependencies: common_ss.all_dependencies(),
     output: 'bindings.rs',
     include_directories: include_directories('.', 'include'),
-    bindgen_version: ['>=0.69.4'],
+    bindgen_version: ['>=0.59.1'],
     args: bindgen_args,
     )
   subdir('rust')
-- 
2.46.2
Re: [PATCH 16/16] rust: allow older version of bindgen
Posted by Junjie Mao 6 days, 16 hours ago
Paolo Bonzini <pbonzini@redhat.com> writes:

> Cope with the old version that is provided in Debian 12 and Ubuntu 22.04.
> --size_t-is-usize is needed on bindgen <0.61.0 (Debian 12, Ubuntu 22.04),
> and it was removed in bindgen 0.65.0, so check for it in meson.build.

The bindgen 0.59.1 installed from Ubuntu 22.04 apt source does not
support the following args:

    '--formatter', 'rustfmt',
    '--merge-extern-blocks',
    '--allowlist-file', meson.project_source_root() + '/include/.*',
    '--allowlist-file', meson.project_source_root() + '/.*',
    '--allowlist-file', meson.project_build_root() + '/.*'

The first two args are cosmetic and should not hurt if removed (but I
need to double check).

Removing the allowlist-file, however, causes IPPORT_RESERVED to be
generated twice using different types and thus break the
build. Allowlists for bindgen 0.59.1 can only be specified as regex on
function, type or var. I don't find (yet) an equivalent way of
--allowlist-file. A dirty trick is `--blocklist-item IPPORT_RESERVED`,
which works but is so ad-hoc.

--
Best Regards
Junjie Mao
Re: [PATCH 16/16] rust: allow older version of bindgen
Posted by Paolo Bonzini 6 days, 14 hours ago
Il mer 16 ott 2024, 08:29 Junjie Mao <junjie.mao@hotmail.com> ha scritto:

>
> The bindgen 0.59.1 installed from Ubuntu 22.04 apt source does not
> support the following args:
>
>     '--formatter', 'rustfmt',
>     '--merge-extern-blocks',
>     '--allowlist-file', meson.project_source_root() + '/include/.*',
>     '--allowlist-file', meson.project_source_root() + '/.*',
>     '--allowlist-file', meson.project_build_root() + '/.*'
>
>
Ouch. --allowlist-file was added in 0.60, so Debian has it. I think we
should ask Canonical if they can update bindgen in addition to rustc.

Paolo

The first two args are cosmetic and should not hurt if removed (but I
> need to double check).
>
> Removing the allowlist-file, however, causes IPPORT_RESERVED to be
> generated twice using different types and thus break the
> build. Allowlists for bindgen 0.59.1 can only be specified as regex on
> function, type or var. I don't find (yet) an equivalent way of
> --allowlist-file. A dirty trick is `--blocklist-item IPPORT_RESERVED`,
> which works but is so ad-hoc.
>
> --
> Best Regards
> Junjie Mao
>
>