Skip to content
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

rust: Proper support for cbindgen #13092

Open
gfxstrand opened this issue Apr 15, 2024 · 3 comments · May be fixed by #13093
Open

rust: Proper support for cbindgen #13092

gfxstrand opened this issue Apr 15, 2024 · 3 comments · May be fixed by #13093
Labels

Comments

@gfxstrand
Copy link
Contributor

We currently have a very handy built-in wrapper for bindgen:

_nil_bindings_rs = rust.bindgen(
  input: ['nil_bindings.h', _nil_format_table],
  output: 'nil_bindings.rs',
  c_args: [
    pre_args,
  ],
  include_directories : [inc_include, inc_src, include_directories('.')],
  args: [
    '--raw-line', '#![allow(non_camel_case_types)]',
    '--raw-line', '#![allow(non_snake_case)]',
    '--raw-line', '#![allow(non_upper_case_globals)]',
    '--allowlist-function', 'util_format_description',
    '--allowlist-type', 'nv_device_info',
    '--allowlist-type', 'nv_device_type',
    '--no-prepend-enum-name',
  ],
  dependencies: _libnil_deps,
)

We don't have anything similar for cbindgen. Currently in Mesa, we're invoking it directly via custom_target() and that works okay but it's a bit clunky:

prog_cbindgen = find_program('cbindgen', required : false, native : true)

# Thanks to cbindgen, this does need to include everything
_libnil_files = files(
  'lib.rs', # lib.rs has to come first
  'extent.rs',
  'format.rs',
  'image.rs',
  'tic.rs',
  'tiling.rs',
)

_nil_h = custom_target(
  'nil_h',
  input : [files('cbindgen.toml'), _libnil_files],
  output : ['nil.h'],
  command : [
    prog_cbindgen, '-q', '--config', '@INPUT0@', '--lang', 'c',
    '--output', '@OUTPUT0@', '--', '@INPUT1@'
  ],
)

It seems to be very much designed to be run from cargo but it is possible to invoke from Meson with some work. Probably the biggiest annoyance is that we have to list every Rust file in the meson instead of just invoking it on lib.rs and letting it go. That could probably be wrapped by Meson for us.

I don't have a particular proposal for what I want rust.cbindgen() to look like but I think we can do better than us having to list a bunch of rust files.

@dcbaker dcbaker added enhancement language:rust module:rust Specific to the Rust module labels Apr 15, 2024
dcbaker added a commit to dcbaker/meson that referenced this issue Apr 15, 2024
@dcbaker
Copy link
Member

dcbaker commented Apr 15, 2024

@dwlsalmeida and I had been talking about this a while back, and I have some work on this. I pushed the work I have, which is not completed. Let me have a look at what's in Mesa and we'll go from there

@dcbaker
Copy link
Member

dcbaker commented Apr 15, 2024

Probably the biggiest annoyance is that we have to list every Rust file in the meson instead of just invoking it on lib.rs and letting it go. That could probably be wrapped by Meson for us.

I asked them to add support for Make compatible depfiles, and it was added, so with more recent versions of cbindgen this isn't a problem, cbindgen will tell Ninja about any files it consumes, and Ninja will do the right thing.

dcbaker added a commit to dcbaker/meson that referenced this issue Apr 15, 2024
dcbaker added a commit to dcbaker/meson that referenced this issue Apr 15, 2024
dcbaker added a commit to dcbaker/meson that referenced this issue Apr 15, 2024
This is pretty minimal, but does work at least for basic tests.

TODO:
  - needs docs
  - needs release snippet
  - more?

Fixes: mesonbuild#13092
@dcbaker dcbaker linked a pull request Apr 15, 2024 that will close this issue
@dcbaker
Copy link
Member

dcbaker commented Apr 15, 2024

Okay, I opened a Draft PR with what I have cleaned up a little bit. I've also checked this with Mesa, and it seems to work for the one case there so far.

dcbaker added a commit to dcbaker/meson that referenced this issue Apr 15, 2024
This is pretty minimal, but does work at least for basic tests.

TODO:
  - needs docs
  - needs release snippet
  - more?

Fixes: mesonbuild#13092
dcbaker added a commit to dcbaker/meson that referenced this issue Apr 15, 2024
This is pretty minimal, but does work at least for basic tests.

TODO:
  - needs docs
  - needs release snippet
  - more?

Fixes: mesonbuild#13092
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants