Dushistov / flapigen-rs

Tool for connecting programs or libraries written in Rust with other languages
BSD 3-Clause "New" or "Revised" License
775 stars 59 forks source link

CPP namespace enhancement proposal #423

Closed stephan57160 closed 2 years ago

stephan57160 commented 2 years ago

Scenario:

Use flapigen to generate JAVA & C++ bindings and library, as usual.

Observation:

Examples below are taken from android-example and cpp-example.

Java bingings are generated with a package name set to the application or library name (aka myapplication):

  prompt> cd android-example
  prompt> cargo build
  prompt> grep '^package' app/src/main/java/net/akaame/myapplication/*.java
  app/src/main/java/net/akaame/myapplication/InternalPointerMarker.java:package net.akaame.myapplication;
  app/src/main/java/net/akaame/myapplication/JNIReachabilityFence.java:package net.akaame.myapplication;
  app/src/main/java/net/akaame/myapplication/Session.java:package net.akaame.myapplication;
  prompt> 

C++ bindings are generated with a namespace always set to rust (or internal):

  prompt> grep '^namespace' cpp-part/rust-api/*.hpp
  cpp-part/rust-api/Foo_fwd.hpp:namespace rust {
  cpp-part/rust-api/Foo.hpp:namespace rust {
  cpp-part/rust-api/rust_foreign_slice_impl.hpp:namespace rust {
  cpp-part/rust-api/rust_foreign_vec_impl.hpp:namespace rust {
  cpp-part/rust-api/rust_slice_access.hpp:namespace rust {
  cpp-part/rust-api/rust_slice_tmpl.hpp:namespace rust {
  cpp-part/rust-api/rust_vec_access.hpp:namespace rust {
  cpp-part/rust-api/rust_vec_impl.hpp:namespace rust {
  cpp-part/rust-api/rust_vec_impl.hpp:namespace internal {
  prompt> 

Proposal:

From any RUST library, the namespace could have the name of the library, similarly to what is done in JAVA (forget the net.akaaname).

This would help to have 2 or more RUST libraries in the same C++ application (aka myapplication).

Dushistov commented 2 years ago

flapigen is just crate, it obviously have no idea about what is the crate name that you use. You can specify name of package with rust method, the same for c++.

stephan57160 commented 2 years ago

Oh OK. The package name is given by build.rs in both examples.

Maybe, the C++ example could use MyLibrary or anything else than just rust, then ...