Description
Describe the bug
When trying to generate bindings to a type with the name String I get the error
Error: × cxx couldn't handle our generated bindings - could be a bug in autocxx:
│ unsupported unique_ptr target type
In my particular case the String type is being incidentally generated because it is being returned from another function. But it will reproduce when directly generating the type named String as well.
To Reproduce
I created a minimized example which reproduces this behaviour with a header named test.h
#pragma once
#include <memory>
#include <stdint.h>
namespace tester {
struct String {
char *data;
uint32_t len;
};
}
class Indirect {
public:
tester::String data;
std::unique_ptr<tester::String> datum() {
return std::make_unique<tester::String>(data);
}
};
use autocxx::prelude::*;
include_cpp! {
#include "test.h"
safety!(unsafe)
generate!("Indirect")
}
fn main() {}
Additional notes
I did some initial digging and found that the cxxbridge
that autocxx is generating contains
impl UniquePtr<String> {}
impl SharedPtr<String> {}
impl WeakPtr<String> {}
impl CxxVector<String> {}
without the corresponding type String = super::bindgen::root::tester::String;
declaration (which appears later). If these lines are removed then compilation will fail with cxx0.h
containing a function conversion which attempts to return a rust::String
instead of tester::String
.
I am happy to continue to explore/fix this problem, but I would like some guidance on where I should look to find the String -> rust::String conversion machinery.