autocxx icon indicating copy to clipboard operation
autocxx copied to clipboard

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

Open RReverser opened this issue 2 years ago • 4 comments

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

RReverser avatar Nov 27 '22 17:11 RReverser

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).

adetaylor avatar Nov 27 '22 17:11 adetaylor

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

RReverser avatar Nov 27 '22 17:11 RReverser

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 avatar Nov 27 '22 20:11 adetaylor

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

ntorresalberto avatar Feb 29 '24 21:02 ntorresalberto