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

Generating Rust bindings which include a type named String doesn't compile #1371

Open
DRvader opened this issue Apr 27, 2024 · 2 comments
Open

Comments

@DRvader
Copy link

DRvader commented Apr 27, 2024

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.

@adetaylor
Copy link
Collaborator

Please file a test case PR following these instructions.

Unfortunately all the stuff around names in autocxx is very fragile so this might not be an easy fix.

nujhong added a commit to nujhong/autocxx that referenced this issue Oct 8, 2024
nujhong added a commit to nujhong/autocxx that referenced this issue Oct 8, 2024
@nujhong
Copy link

nujhong commented Oct 8, 2024

Added a test in #1402

I was able to create a simpler reproducible test case, I believe it's just name conflicts with the default prelude, using a different struct name other than String should generate bindings without problems

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

3 participants