rust-lang / rust-lang/rust-bindgen

Problems binding to Resonance Audio - failing cargo layout tests, methods generated as free functions, probable struct return problem

Open
#1,392 30 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Hi,

I'm attempting to create bindings for Resonance audio. Here are some things I've noticed, which I'm not sure might be part of the cause:

  1. When running cargo test, there are numerous failures, and I noticed the failing test cases are either:
  • instantiations of template functions
  • Classes inheriting from parents that in turn, inherit from someone else. The parent class has implementation of some of the grandparent's methods, with some virtual.
  1. Most methods in c++ are generated as free-standing functions that take a this pointer in Rust. For example,
int vraudio::ResonanceAudioApiImpl::CreateStereoSource(size_t num_channels)

comes out as

pub unsafe extern "C" fn ResonanceAudioApiImpl_CreateStereoSource(
    this: *mut c_void, 
    num_channels: usize
) -> ResonanceAudioApi_SourceId

type ResonanceAudioApi_SourceId = c_int;
  1. It crashes when after I create a class, I attempt to call a method on it (src/main.rs). As discussed in the previous issue, the most likely cause is https://github.com/rust-lang/rust/issues/38258

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported failures with cargo test in the Resonance Audio bindings project, then inspect src/main.rs for the crash when calling a method on a created class. Compare the generated free-function signatures and struct-return behavior with the failing tests; done means the relevant layout tests pass and the method call no longer crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.