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

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

Closed
SteveCookTU opened this issue Nov 22, 2023 · 1 comment
Closed

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

SteveCookTU opened this issue Nov 22, 2023 · 1 comment

Comments

@SteveCookTU
Copy link

SteveCookTU commented Nov 22, 2023

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.

@adetaylor
Copy link
Collaborator

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

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

No branches or pull requests

2 participants