Repository: mransan/ocaml-protoc (ocaml)

Issue:
Expose compilerlib library publicly?
I am working on some proprietary code generator for [Twirp](https://twitchtv.github.io/twirp/docs/intro.html) and was able to implement it successfully using this protobuf implementation for OCaml, but I had to vendor the library and mark `compilerlib` as a public library to be able to do so. Would be nice if compiler library was public, it's quite useful for developing protobuf related tooling.

Pull request description:
expose compiler library as `ocaml-protoc.compiler-lib`
close #187


Patch:
diff --git a/src/compilerlib/dune b/src/compilerlib/dune
index 4e7ecd1..5a78667 100644
--- a/src/compilerlib/dune
+++ b/src/compilerlib/dune
@@ -2,8 +2,9 @@
 (ocamlyacc pb_parsing_parser)
 
 (library
- (name compiler_lib)
- (wrapped false)
+ (name ocaml_protoc_compiler_lib)
+ (public_name ocaml-protoc.compiler-lib)
+ (wrapped true)
  (modules 
   pb_codegen_backend
   pb_codegen_decode_binary
diff --git a/src/compilerlib/pb_codegen_backend.ml b/src/compilerlib/pb_codegen_backend.ml
index 603762f..28db1c1 100644
--- a/src/compilerlib/pb_codegen_backend.ml
+++ b/src/compilerlib/pb_codegen_backend.ml
@@ -638,3 +638,13 @@ let compile all_types = function
   | {Tt.spec = Tt.Enum e ; file_name; scope; file_options; _ } ->
     [compile_enum file_options file_name scope e]
 
+
+module Internal = struct
+  let is_mutable = is_mutable
+  let constructor_name = constructor_name
+  let module_name = module_name
+  let label_name_of_field_name = label_name_of_field_name
+  let type_name = type_name
+  let variant_of_oneof = variant_of_oneof
+
+end
diff --git a/src/compilerlib/pb_codegen_backend.mli b/src/compilerlib/pb_codegen_backend.mli
index 2e5cfef..1c4070e 100644
--- a/src/compilerlib/pb_codegen_backend.mli
+++ b/src/compilerlib/pb_codegen_backend.mli
@@ -40,3 +40,24 @@ val compile :
   Pb_field_type.resolved Tt.proto ->
   Pb_field_type.resolved Tt.proto_type -> 
   Ot.type_ list 
+
+(** Internal helpers.
+
+    For now there are no guarantees of stability within this module.
+    It's unlikely that the signatures will change, but the possibility
+    is still there.
+
+    @since 2.4 *)
+module Internal : sig
+  val is_mutable : ?field_name:string -> Pb_option.set -> bool
+
+  val constructor_name : string -> string
+  val module_name : string -> string
+  val label_name_of_field_name : string -> string
+  val type_name : string list -> string -> string
+
+  val variant_of_oneof :
+    ?include_oneof_name:unit ->
+    outer_message_names:string list ->
+    'a Tt.proto -> Pb_option.set -> string -> int Tt.oneof -> Ot.variant
+end
diff --git a/src/ocaml-protoc/dune b/src/ocaml-protoc/dune
index ac14d63..a8c7b11 100644
--- a/src/ocaml-protoc/dune
+++ b/src/ocaml-protoc/dune
@@ -7,7 +7,8 @@
     ocaml_protoc_cmdline
     ocaml_protoc_compilation
     ocaml_protoc_generation)
-  (libraries compiler_lib)
+  (libraries ocaml-protoc.compiler-lib)
+  (flags :standard -open Ocaml_protoc_compiler_lib)
 )
 
 (library


Test patch:
diff --git a/src/tests/unit-tests/dune b/src/tests/unit-tests/dune
index d168ffe..eee9847 100644
--- a/src/tests/unit-tests/dune
+++ b/src/tests/unit-tests/dune
@@ -21,5 +21,6 @@
     wrapper_encoding
     varint
   )
-  (libraries pbrt compiler_lib)
+  (libraries pbrt ocaml-protoc.compiler-lib)
+  (flags :standard -open Ocaml_protoc_compiler_lib)
 )