Building with Nix is simple, but not incremental. From the root of this
repository, run:
$ nix-build --attr proto3-suite
The build products will be available via the ./result symlink.
Stack
We use Nix and Cabal at Awake Security, so those are the most exercised paths.
Stack support is provided on a best effort basis.
Building the library and executable components is straightforward. From the root
of this repository, run:
$ stack build
Building and running tests is more complicated when using Stack. You'll need to
use the compile-proto-file executable you just compiled to convert
test_*.proto files to Haskell modules, by running the following from the root
of this repository:
$ mkdir gen
$ forprotoin$(find test-files -name 'test_*.proto');do
stack run compile-proto-file -- --out gen --includeDir test-files --proto "${proto#test-files/}"done
$ stack test
Running the language interop tests
We test inter-language interop using protoc's built-in Python code generation.
In order to successfully run these tests, you'll need to install the Google
protobuf Python library. It's best to create a virtualenv and then use pip
to install the right version (virtualenv is a Python utility which can be
installed with pip).
$ virtualenv pyenv
$ source pyenv/bin/activate
$ pip install protobuf==3.0.0b3 # Need the latest version for the newest protoc
brew install python may also work.
Installing compile-proto-file and canonicalize-proto-file
To install the compile-proto-file and canonicalize-proto-file executables,
run the following commmand from the root of this repository:
To uninstall, removing the executables from your Nix user profile PATH, run:
$ nix-env --uninstall proto3-suite
Using compile-proto-file
$ compile-proto-file --help
Usage: compile-proto-file [--includeDir DIR] [--extraInstanceFile FILE]
--proto FILE --out DIR
Compiles a .proto file to a Haskell module
Available options:
-h,--help Show this help text
--includeDir DIR Path to search for included .proto files (can be
repeated, and paths will be searched in order; the
current directory is used if this option is not
provided)
--extraInstanceFile FILE Additional file to provide instances that would
otherwise be generated. Can be used multiple times.
Types for which instance overrides are given must be
fully qualified.
--proto FILE Path to input .proto file
--out DIR Output directory path where generated Haskell modules
will be written (directory is created if it does not
exist; note that files in the output directory may be
overwritten!)
compile-proto-file bases the name (and hence, path) of the generated Haskell
module on the filename of the input .proto file, relative to the include
path where it was found, converting snake case to camel case as needed.
As an example, let's assume this is our current directory structure before
performing any code generation:
Note that delimiting . characters in the input .proto basename are treated
as / characters, so the input filenames google.protobuf.timestamp.proto and
google/protobuf/timestamp.proto would produce the same generated Haskell
module name and path.
This is essentially the same module naming scheme as the protoc Python plugin
uses when compiling .proto files.
Docker
For those unable to run Nix locally, a Dockerfile is provided:
请发表评论