Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[new release] ocaml-protoc (4 packages) (3.0.0) #24863

Merged
merged 5 commits into from
Dec 11, 2023

Conversation

c-cube
Copy link
Contributor

@c-cube c-cube commented Nov 29, 2023

Pure OCaml compiler for .proto files

CHANGES:

Major version that breaks code for every user. Sorry!

Breaking

  • Generated code now always fits into 2 files: code
    for foo.proto is produced in foo.ml and foo.mli.
    This follows a fairly large internal refactor that enables
    a plugin architecture internally (which facilitated codegen for
    services).
    All encoder/decoder functions also have a new name now,
    so that they don't collide inside the same file.
  • CLI flags now use --this-style rather than -this-style
  • Bump minimal OCaml version to 4.08

Performance

  • encode probotufs backward, which means we can write directly
    into a single buffer (which is not possible in a forward mode
    because sub-messages require an unknown amount of prefix space
    to write their size as a varint)
  • add C stubs for pbrt
  • use Bytes functions to read/write fixed size integers
  • inlining annotations
  • more benchmarks, helping optimization overall
  • reduce allocations drastically, by having the generated code
    create fewer closures

Services

  • add pbrt_services runtime library
  • generate code for service statements. This is a big feature
    for users who want to implement RPC systems using protobuf.
    The generated code is agnostic to whatever RPC implementation
    will use it, it only packs together RPC method names and path
    with the relevant encoders/decoders. Services require
    both JSON and binary encoders/decoders to be present.

JSON

  • migrate pbrt_yojson into the main ocaml-protoc repo
  • JSON runtime support for empty messages
  • Add support for bytes in JSON encoding
  • Add support for encoding and decoding maps in JSON

Other features and fixes

  • add --make flag to generate make functions that take fewer
    optional arguments. This helps preventing the user from
    forgetting important arguments when they're encoding to protobuf.
    Arguments actually marked as optional in the .proto file
    are still optional.
  • Support maps/lists in options
  • add Pbrt.Decoder.of_substring
  • Allow options to be named like (validate.rules).message.required
  • support code generation for empty messages
  • Empty proto file is a valid proto as well

Testing

  • expect-style tests for parser
  • Tests for option parsing
  • Test demonstrating parse error printing

@c-cube
Copy link
Contributor Author

c-cube commented Nov 29, 2023

This is going to require a lot of new upper bounds on other packages (pbrt < 3.0, ocaml-protoc < 3.0, etc.).

@c-cube c-cube force-pushed the release-ocaml-protoc-v3.0.0 branch 4 times, most recently from 9715af9 to 70bda27 Compare November 30, 2023 02:03
CHANGES:

Major version that breaks code for every user. Sorry!

### Breaking

- Generated code now always fits into 2 files: code
    for `foo.proto` is produced in `foo.ml` and `foo.mli`.
    This follows a fairly large internal refactor that enables
    a plugin architecture internally (which facilitated codegen for
    services).
    All encoder/decoder functions also have a new name now,
    so that they don't collide inside the same file.
- CLI flags now use `--this-style` rather than `-this-style`
- Bump minimal OCaml version to 4.08

### Performance

- encode probotufs backward, which means we can write directly
    into a single buffer (which is not possible in a forward mode
    because sub-messages require an unknown amount of prefix space
    to write their size as a varint)
- add C stubs for pbrt
- use Bytes functions to read/write fixed size integers
- inlining annotations
- more benchmarks, helping optimization overall
- reduce allocations drastically, by having the generated code
    create fewer closures

### Services

- add `pbrt_services` runtime library
- generate code for `service` statements. This is a big feature
    for users who want to implement RPC systems using protobuf.
    The generated code is agnostic to whatever RPC implementation
    will use it, it only packs together RPC method names and path
    with the relevant encoders/decoders. Services require
    both JSON and binary encoders/decoders to be present.

### JSON

- migrate `pbrt_yojson` into the main ocaml-protoc repo
- JSON runtime support for empty messages
- Add support for bytes in JSON encoding
- Add support for encoding and decoding maps in JSON

### Other features and fixes

- add `--make` flag to generate `make` functions that take fewer
    optional arguments. This helps preventing the user from
    forgetting important arguments when they're encoding to protobuf.
    Arguments actually marked as `optional` in the .proto file
    are still optional.
- Support maps/lists in options
- add Pbrt.Decoder.of_substring
- Allow options to be named like `(validate.rules).message.required`
- support code generation for empty messages
- Empty proto file is a valid proto as well

### Testing

- expect-style tests for parser
- Tests for option parsing
- Test demonstrating parse error printing
@c-cube c-cube force-pushed the release-ocaml-protoc-v3.0.0 branch from 70bda27 to 9c18c1a Compare November 30, 2023 02:37
@haochenx
Copy link
Member

haochenx commented Dec 3, 2023

This is going to require a lot of new upper bounds on other packages (pbrt < 3.0, ocaml-protoc < 3.0, etc.).

maybe this will do it: c-cube#1

@c-cube
Copy link
Contributor Author

c-cube commented Dec 4, 2023

Ah, this looks a lot better!

@c-cube
Copy link
Contributor Author

c-cube commented Dec 4, 2023

Is there a way to mark this as incompatible with 32 bit archs?

@haochenx
Copy link
Member

haochenx commented Dec 5, 2023

you probably also need a lower bound for ppx_deriving on the kinetic-client package.

Co-authored-by: Haochen M. Kotoi-Xie <hx@kxc.inc>
@c-cube
Copy link
Contributor Author

c-cube commented Dec 5, 2023

I don't know what the kinetic client is, truthfully. Could it instead be a dependency on a recent dune?

@haochenx
Copy link
Member

haochenx commented Dec 5, 2023

Is there a way to mark this as incompatible with 32 bit archs?

Related: ocaml/opam#4633

@haochenx
Copy link
Member

haochenx commented Dec 5, 2023

I don't know what the kinetic client is, truthfully. Could it instead be a dependency on a recent dune?

Ah, I see now that it's just a revdep of your packages. Since it's not directly related to this PR, I don't think you need to bother about it. I can update them later.

Once the CI for the other packages comes green, I think this PR is good to be merged.

@haochenx
Copy link
Member

haochenx commented Dec 5, 2023

Now the only relevant failure is with ppc64. You are free to investigate or simply mark it as unavailable on ppc

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Processing  2/3: [ocaml-protoc: dune subst]
+ /home/opam/.opam/opam-init/hooks/sandbox.sh "build" "dune" "subst" (CWD=/home/opam/.opam/5.1/.opam-switch/build/ocaml-protoc.3.0.0)
Processing  2/3: [ocaml-protoc: dune build]
+ /home/opam/.opam/opam-init/hooks/sandbox.sh "build" "dune" "build" "-p" "ocaml-protoc" "-j" "175" "@install" "@runtest" (CWD=/home/opam/.opam/5.1/.opam-switch/build/ocaml-protoc.3.0.0)
- (cd _build/default/src/tests/unit-tests && ./graph_test.exe)
- Graph Test ... Ok
- (cd _build/default/src/tests/unit-tests && ./verify_syntax_invariants.exe)
- Verify syntax invariants ... Ok
- (cd _build/default/src/tests/unit-tests && ./parse_enum.exe)
- Parse Enum ... Ok
- File "src/tests/unit-tests/dune", line 7, characters 14-30:
- 7 |    pbrt_array wrapper_encoding varint)
-                   ^^^^^^^^^^^^^^^^
- (cd _build/default/src/tests/unit-tests && ./wrapper_encoding.exe)
- Command got signal SEGV.
- (cd _build/default/src/tests/unit-tests && ./parse_message.exe)
- Parse Message ... Ok
- Parse Message ... Ok
- (cd _build/default/src/tests/unit-tests && ./parse_field_options.exe)
- Parse Field Options ... Ok
- (cd _build/default/src/tests/unit-tests && ./pbtt_compile_p1.exe)
- Pbtt Compile P1 ... Ok
- File "src/tests/unit-tests/dune", line 7, characters 31-37:
- 7 |    pbrt_array wrapper_encoding varint)
-                                    ^^^^^^
- (cd _build/default/src/tests/unit-tests && ./varint.exe)
- Command got signal SEGV.
- (cd _build/default/src/tests/unit-tests && ./parse_import.exe)
- Parse Import ... Ok
- (cd _build/default/src/tests/unit-tests && ./pbtt_compile_p2.exe)
- Pbtt Compile P2 ... Ok
- (cd _build/default/src/tests/unit-tests && ./parse_file_options.exe)
- Parse File Options ... Ok
- File "src/examples/dune", line 80, characters 7-18:
- 80 |  (name orgchart_ml)
-             ^^^^^^^^^^^
- (cd _build/default/src/examples && ./orgchart_ml.exe)
- Command got signal SEGV.
- (cd _build/default/src/tests/google_unittest && ./google_unittest.exe)
- Google unittest .... OK
[ERROR] The compilation of ocaml-protoc.3.0.0 failed at "dune build -p ocaml-protoc -j 175 @install @runtest".

#=== ERROR while compiling ocaml-protoc.3.0.0 =================================#
# context              2.2.0~alpha4~dev | linux/ppc64 | ocaml-base-compiler.5.1.0 | pinned(https://github.com/mransan/ocaml-protoc/releases/download/v3.0.0/ocaml-protoc-3.0.0.tbz)
# path                 ~/.opam/5.1/.opam-switch/build/ocaml-protoc.3.0.0
# command              ~/.opam/opam-init/hooks/sandbox.sh build dune build -p ocaml-protoc -j 175 @install @runtest
# exit-code            1
# env-file             ~/.opam/log/ocaml-protoc-7-53a35b.env
# output-file          ~/.opam/log/ocaml-protoc-7-53a35b.out
### output ###
# (cd _build/default/src/tests/unit-tests && ./graph_test.exe)
# Graph Test ... Ok
# (cd _build/default/src/tests/unit-tests && ./verify_syntax_invariants.exe)
# Verify syntax invariants ... Ok
# (cd _build/default/src/tests/unit-tests && ./parse_enum.exe)
# Parse Enum ... Ok
# File "src/tests/unit-tests/dune", line 7, characters 14-30:
# 7 |    pbrt_array wrapper_encoding varint)
#                   ^^^^^^^^^^^^^^^^
# (cd _build/default/src/tests/unit-tests && ./wrapper_encoding.exe)
# Command got signal SEGV.
# (cd _build/default/src/tests/unit-tests && ./parse_message.exe)
# Parse Message ... Ok
# Parse Message ... Ok
# (cd _build/default/src/tests/unit-tests && ./parse_field_options.exe)
# Parse Field Options ... Ok
# (cd _build/default/src/tests/unit-tests && ./pbtt_compile_p1.exe)
# Pbtt Compile P1 ... Ok
# File "src/tests/unit-tests/dune", line 7, characters 31-37:
# 7 |    pbrt_array wrapper_encoding varint)
#                                    ^^^^^^
# (cd _build/default/src/tests/unit-tests && ./varint.exe)
# Command got signal SEGV.
# (cd _build/default/src/tests/unit-tests && ./parse_import.exe)
# Parse Import ... Ok
# (cd _build/default/src/tests/unit-tests && ./pbtt_compile_p2.exe)
# Pbtt Compile P2 ... Ok
# (cd _build/default/src/tests/unit-tests && ./parse_file_options.exe)
# Parse File Options ... Ok
# File "src/examples/dune", line 80, characters 7-18:
# 80 |  (name orgchart_ml)
#             ^^^^^^^^^^^
# (cd _build/default/src/examples && ./orgchart_ml.exe)
# Command got signal SEGV.
# (cd _build/default/src/tests/google_unittest && ./google_unittest.exe)
# Google unittest .... OK

Co-authored-by: Haochen M. Kotoi-Xie <hx@kxc.inc>
@c-cube
Copy link
Contributor Author

c-cube commented Dec 11, 2023

Seems like all remaining failures are unrelated!

@mseri
Copy link
Member

mseri commented Dec 11, 2023

Thanks!

@mseri mseri merged commit 18a778e into ocaml:master Dec 11, 2023
@c-cube c-cube deleted the release-ocaml-protoc-v3.0.0 branch December 11, 2023 14:48
@c-cube
Copy link
Contributor Author

c-cube commented Dec 11, 2023

Thank you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants