autocxx icon indicating copy to clipboard operation
autocxx copied to clipboard

Remove need for generated code to require cxx as well as autocxx

Open adetaylor opened this issue 5 years ago • 7 comments

Or at least, add an error message to make it clear. See comments in #33.

adetaylor avatar Oct 15 '20 15:10 adetaylor

Here's the plan here.

  • autocxx_engine depends on cxx in its dependencies not just dev-dependencies. It has a pub use cxx.
  • src/lib.rs in the root (containing the macro) moves into a new autocxx_macro sub-project.
  • The root project has a pub use for the macro, and a pub use for cxx.
  • The generated code gets a pub use autocxx::cxx.

adetaylor avatar Nov 07 '20 01:11 adetaylor

I think I have concluded this is (nearly) impossible.

The code generated by the #[cxx::bridge] macro is full of references to types qualified as ::cxx::..., for instance ::cxx::UniquePtr.

As far as I know, there is no way to populate the root namespace short of actually having a crate called cxx.

Any solution here would require significant changes to cxx. Either:

  • In gen/lib provide an API to qualify the path to cxx every time it's mentioned. Or,
  • Expose an API from gen/lib to expand the macro token stream, then we could post-process it. Even more disruptive.

I'll keep this issue open, because I do regard it as an actual bug, but it won't be a quick fix.

adetaylor avatar Nov 07 '20 02:11 adetaylor

Abandoned work: https://github.com/google/autocxx/compare/re-export-cxx

adetaylor avatar Nov 07 '20 02:11 adetaylor

https://github.com/dtolnay/cxx/issues/697 is a good step forward here.

adetaylor avatar Feb 12 '21 17:02 adetaylor

Even with the above change, we're not particularly close to solving this. The expanded cxx::bridge mod still contains references to ::cxx::UniquePtr and ::cxx::private::Opaque, etc.

adetaylor avatar Feb 19 '21 18:02 adetaylor

Next steps here: raise a pull request against cxx which adds the ability to override the prefix for cxx in its generated code.

adetaylor avatar Feb 04 '22 15:02 adetaylor

Very early work towards cxx change (about 10% finished) https://github.com/adetaylor/cxx/pull/new/cxx-path-prefix

adetaylor avatar Mar 16 '22 00:03 adetaylor