protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Lightweight / pure Ada run-time implementation (without Matreshka)

Open zertovitch opened this issue 6 months ago • 6 comments

A worry with the current implementation is the dependency of some parts of the run-time on Matreshka.

That library is impressive but a clear antipattern. Like, you need a pipe and you drag a whole chemical plant into your project...

When I build an example generated from a tiny .proto, GNAT compiles 15 of the 18 pb_support* files it needs, two google*, the generated stuff, plus... 360 (!) files from Matreshka, including what looks like a XML parser (!!), regexp things, JSON stuff (at different places), .ini files support, things that are heavily CPU and OS dependent, global strings for an application, etc.

If it is possible to add switches to protoc, an idea would be to have a "pure Ada" mode using only Ada.* packages.

The type generated for strings would be Unbounded_String (some people are happy with UTF-8) instead of Universal_String. It would require a bit of remodeling of the run-time, with a protobuf/source/runtime/using_matreshka subdirectory and a protobuf/source/runtime/light for the other variant.

zertovitch avatar Jun 24 '25 14:06 zertovitch

A related issue is #23.

mgrojo avatar Jun 25 '25 21:06 mgrojo

Here, informally, a modif providing a choice between "Plain Ada" and "League/Matreshka": pb_plain.zip

The choice is done via:

   type Runtime_Dep_Type is
      (Runtime_League,      --  Use League library (and Matreshka).
       Runtime_Plain_Ada);  --  Use only Ada.* or own resources;
                            --  strings are assumed being UTF-8-encoded.

   Runtime_Dep : constant Runtime_Dep_Type := Runtime_Plain_Ada;

This is added to: compiler.ads ...and used for code generation in: compiler-field_descriptors.adb

The following are in sources/runtime/using_plain_ada : pb_support-basics.ads pb_support-internal.adb pb_support-internal.ads pb_support-io.adb pb_support-io.ads

The original files with same names (less pb_support-basics.ads) are moved to sources/runtime/using_matreshka

The demo files in both "flavours": demo_league.adb demo_plain.adb

zertovitch avatar Jul 20 '25 21:07 zertovitch

This would be a nice addition to the project. It should be selectable using a crate configuration variable, or, even better, a runtime option. I saw an official option optimize_for, that can be set to SPEED, CODE_SIZE, or LITE_RUNTIME. But each value has a specific official meaning, being LITE_RUNTIME the value used for generating code "that depends only on the “lite” runtime library (libprotobuf-lite instead of libprotobuf)." How to pass other options to the language generator is a bit obscure in the documentation.

mgrojo avatar Jul 21 '25 19:07 mgrojo

We could try to do it on alire layer by writing several runtime crates with common interface and let the user install any of them.

пн, 21 лип. 2025 р., 22:40 користувач Manuel @.***> пише:

mgrojo left a comment (reznikmm/protobuf#35) https://github.com/reznikmm/protobuf/issues/35#issuecomment-3098216877

This would be a nice addition to the project. It should be selectable using a crate configuration variable https://alire.ada.dev/docs/#using-crate-configuration, or, even better, a runtime option. I saw an official option https://protobuf.dev/programming-guides/proto3/#options optimize_for, that can be set to SPEED, CODE_SIZE, or LITE_RUNTIME. But each value has a specific official meaning, being LITE_RUNTIME the value used for generating code "that depends only on the “lite” runtime library (libprotobuf-lite instead of libprotobuf)." How to pass other options to the language generator is a bit obscure in the documentation.

— Reply to this email directly, view it on GitHub https://github.com/reznikmm/protobuf/issues/35#issuecomment-3098216877, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRB77ZT4PRO4OYVAYKHPSD3JU64XAVCNFSM6AAAAACAAPL3GCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAOJYGIYTMOBXG4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

reznikmm avatar Jul 22 '25 05:07 reznikmm

There is a fix around vectors of strings. I have realized that I have to respect the convention: Result.Package_Name := "PB_Support." & Result.Type_Name & "_Vectors";

Here an update of the informal source set as described above.

pb_plain_v2.zip

zertovitch avatar Jul 22 '25 20:07 zertovitch

Again a fix (range check error).

pb_plain_v3.zip

zertovitch avatar Jul 27 '25 08:07 zertovitch