rust-lang / rust-lang/rust-bindgen

Possibly failing to detect template parameter T

Open
#1,496 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug I-needs-reduced-test-case
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header

Header file itself can be found here. It's C++ 17 and uses templating.

namespace seal
{
    template<typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
    class IntArray
    {
    public:
        using size_type = std::size_t;

The definition seems pretty exotic so I suppose that something in it is unsupported.

Bindgen Invocation
 // Generate the bindings
    let bindings = bindgen::Builder::default()
        .generate_inline_functions(true)
        .derive_default(true)
        .header("./seal/src/seal/seal.h")
        .clang_arg("-I./seal/src/")
        .clang_arg("-std=c++17")
        .clang_arg("-x")
        .clang_arg("c++")
        .opaque_type("std::.*")
        .whitelist_type("seal::.*")
        .whitelist_function("seal::.*")
        .generate()
        .expect("Unable to generate bindings");
Actual Results

The bindings.rs file has an undefined T value in IntArray:

#[repr(C)]
#[derive(Debug)]
pub struct seal_IntArray {
    pub pool_: seal_MemoryPoolHandle,
    pub capacity_: seal_IntArray_size_type,
    pub size_: seal_IntArray_size_type,
    pub data_: seal_util_Pointer<T>,
}

Which causes the expected compilation error:

error[E0412]: cannot find type `T` in this scope
    --> src/./bindings.rs:6218:34
     |
6218 |     pub data_: seal_util_Pointer<T>,
     |                                  ^ not found in this scope

For reference, here is the relevant header file.

Expected Results

I would expect the generated code to compile.

For now, I have found that simply replacing T by u64 (since it's the only type they used as T in their code) works, but ideally I wouldn't have to edit the bindings by hand.

Possibly related: #1464
Also see issue: #1490

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 bindgen invocation against the linked seal/intarray.h header and inspecting the generated bindings.rs around seal_IntArray. Compare the C++ template declaration with the emitted Rust field using T; done means the generated bindings compile without manually replacing T, with coverage for this template case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.