awakesecurity / gRPC-haskell

Haskell gRPC support
https://hackage.haskell.org/package/grpc-haskell
Apache License 2.0
238 stars 75 forks source link

Support gRPC 1.46.3 (also fix builds on Darwin) #138

Open unclechu opened 2 years ago

unclechu commented 2 years ago

Closes https://github.com/awakesecurity/gRPC-haskell/issues/136.

Some context

I had to fix issues with building nixpkgs.grpc on Darwin using release-22.05 nixpkgs branch. The pin from gRPC-haskell (1.34.1) was giving some “undefined reference” errors coming from nixpkgs.abseil-cpp library as it seems. It turned out that nixpkgs.grpc from release-22.05 branch (1.46.3) builds just fine on Darwin but it’s not compatible with gRPC-haskell, there are some breaking changes in gRPC API. I decided it would be easier to just implement support for gRPC-haskell for 1.46.3 gRPC version than debugging the old 1.34.1 against Darwin, especially taking into account that I don’t have any Apple hardware by hand.

What I changed

The change to the API that makes it work with gRPC 1.46.3 is relatively small. There are few differences in the newer version of gRPC how the insecure/unauthenticated server and channel are created. This are no *_insecure_* functions anymore. Instead there are functions that are creating insecure credentials object.

Though I significantly refactored Nix configuration for the project:

  1. Updated nixpkgs pin to use the release-22.05 branch
  2. Added shell attribute to default.nix that I used to make this change, original shell.nix was failing to build for me when I was making a fix. After the fix it started to build fine, but while API was broken is was impossible to enter a nix-shell. So this addition based on haskellPackages.shellFor can be useful comparing to shell.nix which is just grpc-haskell.env.
  3. Added stack-env attribute to default.nix that makes Stack project buildable on NixOS (gmp and zlib are required). I used this command to build the project stack build --nix --system-ghc --no-test
  4. Created new pins for gRPC and its Python dependencies to match the same version as recommended in the comments of gRPC derivation
  5. Also created pins for the overridden Haskell dependencies so that the used patches are always applicable against other nixpkgs pins where the versions of those dependencies may change
  6. Updated proto3-wire and proto3-suite to match the versions from release-22.05 branch of nixpkgs
  7. Exposed in the attributes of default.nix overridden Haskell dependencies
  8. Used nixpkgs.python3 instead of nixpkgs.python which is Python 2 by default because some of the Python dependencies of gRPC do not support Python 2 anymore and entering nix-shell fails due to this
  9. Other changes are minor, more like stylistic ones

Note that I also updated the Stack configuration to use the newer snapshot to match the GHC version from nixpkgs pin. I also added stack.yaml.lock file to the project.

Open questions for the maintainer(s)

About tests

Support of different gRPC versions

fumieval commented 1 year ago

Is there anything I can help to move this forward? @Gabriella439 @unclechu

ixmatus commented 1 year ago

@fumieval what would be helpful is if you could provide a review of this PR yourself, someone from our org will also have to (it will likely be me I think) but I'll have to swap in a lot so it would certainly help move things along if you provided a review...