Support gRPC 1.46.3 (also fix builds on Darwin)
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:
- Updated
nixpkgspin to use therelease-22.05branch - Added
shellattribute todefault.nixthat I used to make this change, originalshell.nixwas 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 onhaskellPackages.shellForcan be useful comparing toshell.nixwhich is justgrpc-haskell.env. - Added
stack-envattribute todefault.nixthat makes Stack project buildable on NixOS (gmpandzlibare required). I used this command to build the projectstack build --nix --system-ghc --no-test - Created new pins for gRPC and its Python dependencies to match the same version as recommended in the comments of gRPC derivation
- Also created pins for the overridden Haskell dependencies so that the used patches are always applicable against other
nixpkgspins where the versions of those dependencies may change - Updated
proto3-wireandproto3-suiteto match the versions fromrelease-22.05branch ofnixpkgs - Exposed in the attributes of
default.nixoverridden Haskell dependencies - Used
nixpkgs.python3instead ofnixpkgs.pythonwhich 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 - 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
- [ ] Just one test of
grpc-haskell-coreabout graceful shutdowns (seeLowLevelTests.testGoaway/core/tests/LowLevelTests.hs). But what’s weird that it’s not always failing. I managed to build it on one of my machines when it was successful. Do you have any ideas how to fix it or what could be the problem? It doesn’t seem like it’s related to my changes but rather to the newer version of gRPC for instance. - [ ] Attempt to build
nix-build -A grpc-haskellwithoutno-testsfails with:Builder called die: Cannot wrap 'tests/protoc.sh' because it is not an executable file. Is that a known issue? - [ ] What is the right way to run this example
cabal configure --enable-tests && cabal testin a Nix Shell using new Cabal 3.x for instance? This command doesn’t work.
UPD: Just added missing$ cabal --version cabal-install version 3.6.2.0 compiled using version 3.6.3.0 of the Cabal library $ cabal configure --enable-tests && cabal build && cabal test 'cabal.project.local' already exists, backing it up to 'cabal.project.local~0'. Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal update' to download it. Resolving dependencies... cabal: Could not resolve dependencies: [__0] trying: grpc-haskell-0.3.0 (user goal) [__1] rejecting: grpc-haskell:!test (constraint from config file, command line flag, or user target requires opposite flag selection) [__1] trying: grpc-haskell:*test [__2] unknown package: tasty-hunit (dependency of grpc-haskell *test) [__2] fail (backjumping, conflict set: grpc-haskell, tasty-hunit, grpc-haskell:test) After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: grpc-haskell, grpc-haskell:test, tasty-hunitpipesandtasty-hunitpackages to theghcWithPackagesofgrpc-haskelland it worked. Kind of. It runs the tests infinitely (never finishes):In order, the following will be built (use -v for more details): - grpc-haskell-0.3.0 (test:tests) (ephemeral targets) Preprocessing test suite 'tests' for grpc-haskell-0.3.0.. Building test suite 'tests' for grpc-haskell-0.3.0.. Running 1 test suites... Test suite tests: RUNNING...
Support of different gRPC versions
- [ ] I think it would be better to support the old gRPC version as well, right? So maybe use
CPPextension and add some conditions for the code. But the problem is that gRPC is not a Haskell package, there is no way to easily check the version of that C-library dependency version right? Maybe some Template Haskell magic can do that? Or maybe let’s provide gRPC version as Cabal flag? And default it to the supported1.46.3and in Nix there can be automatic set of this flag to thenixpkgs.grpc.version. What do you think about this?
Is there anything I can help to move this forward? @Gabriella439 @unclechu
@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...