unclechu's fork of gRPC-haskell
Find a file
przemyslaw wierzbicki 68ce43f183 nixpkgs upgrade
2019-05-23 21:43:05 -04:00
bench Client helpers, re-exports, and fixups (#70) 2018-10-14 17:52:59 -05:00
bin Upgrade nix grpc version to 1.0.1 + fix tests (#86) 2016-12-20 15:57:38 -06:00
core Port grpc-haskell[-core] to ghc-8.6 and modern tasty. (#77) 2019-03-25 16:52:04 -07:00
examples Client helpers, re-exports, and fixups (#70) 2018-10-14 17:52:59 -05:00
nix nixpkgs upgrade 2019-05-23 21:43:05 -04:00
src/Network/GRPC Shut down server when serverLoop thread is killed. (#71) 2019-01-07 15:53:10 -08:00
tests fix tests broken by previous commit (#69) 2018-10-09 19:29:29 -05:00
.gitignore Update echo client/server to use CG and high-level interfaces (#88) 2016-12-22 14:33:44 -06:00
default.nix Extract lowlevel bits into a core package (#42) 2018-01-29 08:59:34 -08:00
fetch-nixpkgs.nix Fix the output of the nixpkgs derivation and make the pin forwards compatible with Nix 2.0 (#52) 2018-03-12 11:06:21 -05:00
grpc-haskell.cabal Port grpc-haskell[-core] to ghc-8.6 and modern tasty. (#77) 2019-03-25 16:52:04 -07:00
LICENSE Fix author/maintainer/copyright in grpc-haskell.cabal (#82) 2016-12-14 12:55:56 -06:00
nixpkgs.nix nixpkgs upgrade 2019-05-23 21:43:05 -04:00
README.md Remove proto3-wire dependency from core package. (#47) 2018-01-30 09:20:05 -08:00
release.nix nixpkgs upgrade 2019-05-23 21:43:05 -04:00
Setup.hs Initial commit. 2015-02-27 18:14:32 +01:00
shell.nix Port grpc-haskell[-core] to ghc-8.6 and modern tasty. (#77) 2019-03-25 16:52:04 -07:00
stack.yaml Fix broken links to proto3-wire and proto3-suite (#72) 2019-01-22 08:40:55 -06:00

Attribution

This library is a fork of https://github.com/aloiscochard/grpc-haskell that we have extended and released under the same LICENSE

Installation

The current version of this library requires gRPC version 1.2.0. Newer versions may work but have not been tested.

Usage

There is a tutorial here

Building and testing

If you want to use stack on MacOS, you will need to have GRPC installed already -- see the Installing GRPC for stack section below. Any example build and test recipes below which use stack assume you have already performed the steps described in that section.

Without stack, nix-build release.nix -A grpc-haskell will build and test the whole thing and put the completed package into the nix store. nix-shell can be used to give you a development environment where you can use the cabal and stack toolchains for development and testing:

$ nix-shell release.nix -A grpc-haskell.env
[nix-shell]$ cabal configure --enable-tests && cabal build && cabal test
$ nix-shell release.nix -A grpc-haskell.env
[nix-shell]$ stack build --fast && stack test --fast

Note that, for stack, the nix-shell environment is only needed to run the tests, because it uses some custom python tooling (for grpc interop testing). You should still be able to stack build without using the nix-shell environment at all.

NB: You can also instruct stack to run the tests inside the nix-shell environment directly, via stack --nix test --fast. However, this will frequently rebuild the custom ghc that is used in release.nix, so is not recommended during develop-debug cycles (use the cabal path for that, or iterate within a nix-shell).

Finally, since stack does not use nix for any Haskell package dependencies, be sure to update repository references for dependent packages such as protobuf-wire in both nix/<pkg>.nix AND in stack.yaml.

Installing GRPC for stack (MacOS)

If you want to use stack in a relatively natural and painless manner, you will need a working installation of the GRPC C core libraries.

On MacOS, because of issues related to System Integrity Protection, dependencies on the nix-built grpc don't seem to work properly in the stack toolflow when DYLD_LIBRARY_PATH refers to the nix-built grpc library in the nix store, so the library needs to be installed somewhere that the loader can pick it up without DYLD_LIBRARY_PATH set (e.g., in /usr/local/lib).

There are basically two methods to accomplish this:

  1. Run bin/install-macos-nix-grpc.sh.

This script will build the same version of grpc used in release.nix, which is what is used in the end-to-end system and in our CI testing flows. It then pretends to be an impoverished version of brew and installs symlinks from the nix store into /usr/local/include/grpc and /usr/local/lib/libgrpc.dylib. It should be run manually whenever the grpc dependency is updated. Note that it is intentionally destructive to any existing brew installs of grpc.

Is it an ugly hack? Yes, but it's better than having either a rootless system to circumvent SIP or building atop a version of grpc which may differ from CI and production environments (which may be the case with brew-installed grpc).

After running this script, you should be able to use stack normally, in combination with a nix-shell environment for running the tests:

$ bin/install-macos-nix-grpc.sh
$ stack build --fast
$ stack --nix test --fast
  1. Use brew

If you don't want to hack the global pathing yourself using the above script, you can rely on homebrew to do this for you instead. However, you will need to specify the version of the grpc release that you want to use.

$ brew tap grpc/grpc
$ brew edit grpc
$ brew install grpc

Make sure you select a release version that is reasonably close to our grpc dependency, e.g.:

url "https://github.com/grpc/grpc/archive/release-0_15_0.tar.gz"
sha256 "d02235dff278869e94cb0dcb31cfea935693c6f87bd73f43d44147185e6becdd"

or

url "https://github.com/grpc/grpc/archive/v1.0.1.tar.gz"
sha256 "efad782944da13d362aab9b81f001b7b8b1458794751de818e9848c47acd4b32"

Using the Library

You must compile with -threaded, because we rely on being able to execute Haskell while blocking on foreign calls to the gRPC library. If not using code generation, the recommended place to start is in the Network.GRPC.HighLevel.Server.Unregistered module, where serverLoop provides a handler loop.