google/autocxx

Unable to generate bindings for std::array<unsigned char, 6>

SteveCookTU opened this issue · 1 comments

Describe the bug
Attempting to generate bindings to a class in which a method returns std::array<unsigned char, 6>. Running cargo-expand shows the warning: autocxx bindings couldn't be generated: This function or method uses a type where one of the template parameters was incomprehensible to bindgen/autocxx - probably because it uses template specialization.

Preface
The following library typedefs C primitives to other values. Since they match the names of Rust primitives, I have renamed them. u8 to us8, etc.

Specific to this example, us8 is a typedef for unsigned char.

To Reproduce
In a new crate, I created a binding to the file found here. For coverage, I added the include to the PIDToIVState.hpp header as it is a forward declaration along with Method.hpp.

Everything generates correctly except this function:

    std::array<us8, 6> getIVs() const
    {
        return ivs;
    }

build.rs

fn main() -> miette::Result<()> {
    let dst = cmake::build("PokeFinder/Source/Core");

    println!("cargo:rustc-link-search=native={}", dst.display());
    println!("cargo:rustc-link-lib=static=PokeFinderCore");

    let path = std::path::PathBuf::from("PokeFinder/Source");
    let mut b = autocxx_build::Builder::new("src/lib.rs", &[&path]).build()?;
    b.flag_if_supported("-std=c++17").compile("pokefinder");

    println!("cargo:rerun-if-changed=src/lib.rs");

    Ok(())
}

lib.rs

use autocxx::prelude::*;

include_cpp! {
    #include "Core/Enum/Method.hpp"
    #include "Core/Gen3/States/PIDToIVState.hpp"
    #include "Core/Gen3/Tools/PIDToIVCalculator.hpp"
    safety!(unsafe)
    generate!("Method")
    generate!("PIDToIVState")
    generate!("PIDToIVCalculator::calculateIVs")
}

Expected behavior
The function would generate bindings with the returned value of [u8; 6] as shown on this page of cxx. Correct me if I am wrong but unsigned char seems to have no wrapper type and directly converts to u8 (It does this for the getIV function).

Additional context
Changing the return type to unsigned char and uint8_t produces the same result.

The C++ library is built with CMake.
OS: Windows 11
rustc: rustc 1.76.0-nightly (3a85a5cfe 2023-11-20)

Because of the holidays, I have run out of time to make a proper test for this. I will do so as soon as possible. If it could be looked into beforehand, it would be greatly appreciated.

Please advise if any other information is necessary.

Thanks for the thorough report. Arrays are not yet supported in autocxx - #266. Pull requests to add this support are very welcome.