Skip to content

Migration Guide

Judah Jacobson edited this page Sep 9, 2018 · 4 revisions

This page provides a guide for the changes necessary to switch between major versions of proto-lens.

0.4

Cabal configuration

In version 0.4, we have split proto-lens-protoc into several packages:

  • proto-lens-protoc just contains the binary
  • proto-lens-runtime contains the runtime libraries needed by generated code
  • proto-lens-setup enables building custom Setup scripts. It depends on proto-lens-protoc.

To upgrade from v0.3 to v0.4:

  • In the setup-depends field of the custom-setup clause, change proto-lens-protoc to proto-lens-setup.
  • In the build-depends fields of libraries, tests and executables, change proto-lens-protoc to proto-lens-runtime.

See the README for more detailed instructions.

Proto construction

In proto-lens v0.3 and earlier, we used the def message from Data.Default.Class (from the data-default-class package) to construct default protobuf messages:

class Data.Default.Class.Default a => Message a where
    ...

In version 0.4, we have changed that to a custom method. (See #194 for the motivation). The new API is:

class Message a where
    defMessage :: a

Any previous code that tries to build a protobuf message with Data.Default.Class.def will break. There are two ways to fix this:

  1. Replace all uses of def with defMessage. That method is exported from both Data.ProtoLens and Data.ProtoLens.Message.

  2. (Simpler, legacy option): use Data.ProtoLens.Default.def, which is defined as

    def :: Message a => a
    def = defMessage
    

    That is, change any module imports from

    import Data.ProtoLens (def, encodeMessage, ...)
    

    to

    import Data.ProtoLens (encodeMessage, ...)
    import Data.ProtoLens.Default (def)
    

Data Constructors

Starting in v0.4, record constructors and raw record fields are no longer exported from generated modules.

For example, previously it was possible to construct a message with something like:

Foo { _Foo'bar = ..., _Foo'baz=...}

In v0.4, you should use the generated lenses, for example, either

defMessage & bar .~ ... & .~ baz .~ ...

or, with the OverloadedLabels extension:

defMessage & #bar .~ ... & #baz .~ ...

Command line flags

Direct users of protoc-gen-haskell (such as Bazel build rules) should change --no-reexports flag to --no-runtime.

Generated Instances

proto-lens-protoc now generates an explicit NFData instance for each protocol buffer message type. Any previously-added (orphan) instances of NFData should be removed.

Additionally, the Show instance has been changed to use showMessageShort rather than displaying the raw constructors. Note that, like showMessageShort, it omits any fields which are set to the default values.

Clone this wiki locally