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

Can't tell autocxx that the replaced type is POD and safe to use in other PODs #1192

Open
RReverser opened this issue Nov 27, 2022 · 4 comments

Comments

@RReverser
Copy link

RReverser commented Nov 27, 2022

Expected Behavior

I should be able to replace a C++ type autocxx doesn't understand with my custom Rust type, and tell autocxx that it's a POD so it can be used in generate_pod! for other types like this:

#include <Eigen/Dense>

struct MyStruct {
	Eigen::Vector2d vec;
};

(Eigen is a header-only library, so should be relatively easy to add for a repro, but I suppose this can be reproduced with simpler custom types too)

#[repr(transparent)]
pub struct Vector2d(pub nalgebra::Vector2<f64>);

impl cxx::ExternType for Vector2d {
    type Id = cxx::type_id!("Eigen::Vector2d");
    type Kind = cxx::kind::Trivial;
}

include_cpp! {
    #include "test.h"

    safety!(unsafe)

    extern_cpp_type!("Eigen::Vector2d", crate::Vector2d)
    pod!("Eigen::Vector2d")

    generate_pod!("MyStruct")
}

Actual Behavior

autocxx complains that MyStruct can't be generated as a POD because the dependency type "isn't known":

  --- stderr
  Error:
    × the include_cpp! macro couldn't be expanded into Rust bindings to C++:
    │ An item was requested using 'generate_pod' which was not safe to hold by
    │ value in Rust. Type MyStruct could not be POD because its dependent type
    │ Eigen::Vector2d isn't known

Specifications

  • Version: 0.23.1
@adetaylor
Copy link
Collaborator

Thanks. I agree this is seems like a valid bug. It would be even better if you could raise a PR with a failing test case in integration-tests/src/integration_tests.rs (or at least it means I'm likely to look at fixing it quicker).

@RReverser
Copy link
Author

I'll try to get to it, but have a bit much to unwrap locally at the moment.

@adetaylor
Copy link
Collaborator

Landed a fix in a branch, but it's made me realize this bit of the autocxx codebase is a bit... legacy. I might do some more thinking about it over the next week or so in case I think it merits a more substantial rewrite.

adetaylor added a commit that referenced this issue Nov 27, 2022
This shrinks us down to enumerating the fields in a struct in one place instead of two.

However, it adds a lot of code, so possibly not worth it.

Relates to #1192.
adetaylor added a commit that referenced this issue Jan 30, 2023
adetaylor added a commit that referenced this issue Jan 30, 2023
@ntorresalberto
Copy link

Hi, just commenting to say I'm interested in this use case, coming from the linear algebra and c++ world.

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