Skip to content

Commit 0ca3d5d

Browse files
authored
Merge pull request #963 from IntersectMBO/mgalazyn/fix/restore-cardano-rpc
cardano-rpc | Use buf for code generation instead of cabal/protoc integration
2 parents ff61025 + 3b339df commit 0ca3d5d

File tree

18 files changed

+9493
-57
lines changed

18 files changed

+9493
-57
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cardano-rpc/gen/** linguist-generated=true
2+
cardano-rpc/gen/** no-prettify
3+

.github/workflows/haskell.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ jobs:
8686

8787
- name: "[Windows] Install grpc dependencies"
8888
if: runner.os == 'Windows'
89-
run: /usr/bin/pacman --noconfirm -S mingw-w64-x86_64-snappy mingw-w64-x86_64-protobuf
89+
run: |
90+
/usr/bin/pacman --noconfirm -S mingw-w64-x86_64-snappy mingw-w64-x86_64-protobuf
91+
cat <<EOF >> $GITHUB_ENV
92+
LIBRARY_PATH=/mingw64/lib
93+
CPATH=/mingw64/include
94+
EOF
9095
9196
- name: "[macOS] Install grpc dependencies"
9297
if: runner.os == 'macOS'
@@ -107,6 +112,34 @@ jobs:
107112
cabal-store: ${{ steps.setup-haskell.outputs.cabal-store }}
108113
cache-version: ${{ env.CABAL_CACHE_VERSION }}
109114

115+
116+
- name: '[Linux] [cardano-rpc] Install buf'
117+
if: runner.os == 'Linux'
118+
run: |
119+
curl -sSL "https://github.com/bufbuild/buf/releases/latest/download/buf-Linux-x86_64" -o "/usr/local/bin/buf"
120+
chmod +x /usr/local/bin/buf
121+
122+
- name: '[Linux] [cardano-rpc] Install proto-lens-protoc'
123+
if: runner.os == 'Linux'
124+
run: |
125+
cabal install proto-lens-protoc --installdir=$HOME/.local/bin
126+
127+
- name: '[Linux] [cardano-rpc] Generate protobuf code'
128+
if: runner.os == 'Linux'
129+
working-directory: cardano-rpc
130+
run: buf generate proto
131+
132+
- name: '[Linux] [cardano-rpc] Check that generated files from proto definitions are up to date'
133+
if: runner.os == 'Linux'
134+
run: |
135+
git add cardano-rpc/gen
136+
if ! git diff --staged --quiet -- cardano-rpc/gen; then
137+
echo "Generated files differ from repository files:"
138+
git diff --staged --name-status -- cardano-rpc/gen
139+
exit 1
140+
fi
141+
echo "All generated files match repository files"
142+
110143
# Now we build.
111144
- name: Build all
112145
run: cabal build all --enable-tests

.github/workflows/hls.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,4 @@ jobs:
119119
cradle:
120120
cabal:
121121
EOF
122-
# Remove the following line after `cardano-rpc` project is enabled in `cabal.project`
123-
mv cardano-rpc ../
124122
haskell-language-server

.hlint.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
# Allow snake_case naming in test modules (following Haskell test property convention)
6161
- ignore: {name: Use camelCase, within: [Test.Cardano.Api.**, Test.Golden.Cardano.Api.**]}
6262

63+
# Ignore all files in cardano-rpc/gen (generated code)
64+
- ignore: {within: [Proto.Cardano, Proto.Utxorpc]}
65+
6366
- ignore: {name: Eta reduce}
6467
- ignore: {name: Use + directly}
6568
- ignore: {name: Use fmap}

cabal.project

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,9 @@ packages:
2020
cardano-api
2121
cardano-api-gen
2222
cardano-wasm
23-
-- TODO fix potential issues with build-type: Custom and protoc and reenable
24-
-- When uncommenting this line, remember to reenable in .github/workflows/hls.yml
25-
-- by removing the line that moves it away before calling `haskell-language-server`.
26-
-- cardano-rpc
23+
cardano-rpc
2724

28-
extra-packages: Cabal, process
29-
30-
if impl(ghc < 9.8)
31-
constraints: interpolatedstring-perl6:setup.time source
25+
extra-packages: Cabal
3226

3327
-- It may slow down build plan preparation, but without it cabal has problems
3428
-- with solving constraints. Remove this when not needed anymore.

cardano-rpc/README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## What's this
44

5-
The `cardano-rpc` package provides client and server haskell modules for gRPC interface of `cardano-node`.
5+
The `cardano-rpc` package provides client and server haskell modules for gRPC interface of `cardano-node`.
66
It implements [UTxO RPC](https://utxorpc.org/introduction) protobuf communication protocol specification.
77

88
## Building
@@ -14,7 +14,24 @@ You need the following dependencies installed on your system:
1414
- [`snappy`](https://github.com/google/snappy) development files (`libsnappy-dev` in Ubuntu)
1515
- [`protobuf`](https://developers.google.com/protocol-buffers/) compiler (`protobuf-compiler` in Ubuntu)
1616

17-
Then do:
17+
### Generating the Haskell code from proto definitions
18+
19+
You need to install `buf` and `proto-lens-protoc`.
20+
1. Follow the `buf` installation guide at: https://buf.build/docs/cli/installation/
21+
1. To install Haskell protobuf code compiler:
22+
```bash
23+
cabal install proto-lens-protoc
24+
```
25+
26+
1. Generate Haskell code using:
27+
```bash
28+
( cd cardano-rpc/ ; buf generate proto )
29+
```
30+
This will output the generated Haskell code into `cardano-rpc/gen` directory.
31+
32+
### Building the haskell code
33+
34+
To build the package use the following command:
1835
```bash
1936
cabal build cardano-rpc
2037
```

cardano-rpc/Setup.hs

Lines changed: 0 additions & 10 deletions
This file was deleted.

cardano-rpc/buf.gen.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: v1
2+
3+
managed:
4+
enabled: true
5+
6+
plugins:
7+
# node
8+
# - plugin: es
9+
# out: gen/node/src
10+
# opt:
11+
# - target=ts
12+
#
13+
# - plugin: connect-es
14+
# out: gen/node/src
15+
# opt:
16+
# - target=ts
17+
#
18+
# - plugin: buf.build/bufbuild/protoschema-jsonschema
19+
# out: gen/jsonschema/schema
20+
21+
# haskell
22+
23+
- plugin: haskell-protolens
24+
path: proto-lens-protoc
25+
out: gen
26+

cardano-rpc/cardano-rpc.cabal

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,17 @@ license-files:
1717
LICENSE
1818
NOTICE
1919

20-
build-type: Custom
20+
build-type: Simple
2121
extra-doc-files:
2222
CHANGELOG.md
2323
README.md
2424

25-
extra-source-files: proto/**/*.proto
26-
27-
custom-setup
28-
setup-depends:
29-
Cabal >=3.0 && <3.13,
30-
base >=4.14 && <5,
31-
proto-lens-setup >=0.4 && <0.5,
32-
3325
common project-config
3426
default-language: Haskell2010
3527
default-extensions:
3628
ImportQualifiedPost
3729
OverloadedStrings
3830

39-
build-depends: base >=4.14 && <5
4031
ghc-options:
4132
-Wall
4233
-Wcompat
@@ -50,7 +41,6 @@ common project-config
5041
library
5142
import: project-config
5243
hs-source-dirs: src
53-
build-tool-depends: proto-lens-protoc:proto-lens-protoc
5444
exposed-modules:
5545
Cardano.Rpc.Client
5646
Cardano.Rpc.Proto.Api.Node
@@ -65,29 +55,13 @@ library
6555
Cardano.Rpc.Server.Internal.UtxoRpc.Query
6656
Cardano.Rpc.Server.Internal.UtxoRpc.Submit
6757
Cardano.Rpc.Server.Internal.UtxoRpc.Type
68-
Proto.Cardano.Rpc.Node
69-
Proto.Cardano.Rpc.Node_Fields
70-
Proto.Utxorpc.V1alpha.Cardano.Cardano
71-
Proto.Utxorpc.V1alpha.Cardano.Cardano_Fields
72-
Proto.Utxorpc.V1alpha.Query.Query
73-
Proto.Utxorpc.V1alpha.Query.Query_Fields
74-
Proto.Utxorpc.V1alpha.Submit.Submit
75-
Proto.Utxorpc.V1alpha.Submit.Submit_Fields
7658

7759
other-modules:
7860
Cardano.Rpc.Server.Internal.Orphans
7961
Paths_cardano_rpc
8062

8163
autogen-modules:
8264
Paths_cardano_rpc
83-
Proto.Cardano.Rpc.Node
84-
Proto.Cardano.Rpc.Node_Fields
85-
Proto.Utxorpc.V1alpha.Cardano.Cardano
86-
Proto.Utxorpc.V1alpha.Cardano.Cardano_Fields
87-
Proto.Utxorpc.V1alpha.Query.Query
88-
Proto.Utxorpc.V1alpha.Query.Query_Fields
89-
Proto.Utxorpc.V1alpha.Submit.Submit
90-
Proto.Utxorpc.V1alpha.Submit.Submit_Fields
9165

9266
build-depends:
9367
aeson,
@@ -98,6 +72,7 @@ library
9872
cardano-ledger-binary,
9973
cardano-ledger-conway,
10074
cardano-ledger-core,
75+
cardano-rpc:gen,
10176
containers,
10277
contra-tracer,
10378
data-default,
@@ -107,24 +82,44 @@ library
10782
grpc-spec,
10883
proto-lens,
10984
proto-lens-protobuf-types,
110-
proto-lens-runtime,
11185
rio,
11286
text,
11387

88+
-- this should be replaced by utxorpc package from hackage
89+
-- ideally we should upstream whatever is implemented in Proto.Cardano.Rpc.Node
90+
-- into utxorpc
91+
library gen
92+
import: project-config
93+
hs-source-dirs: gen
94+
exposed-modules:
95+
Proto.Cardano.Rpc.Node
96+
Proto.Cardano.Rpc.Node_Fields
97+
Proto.Utxorpc.V1alpha.Cardano.Cardano
98+
Proto.Utxorpc.V1alpha.Cardano.Cardano_Fields
99+
Proto.Utxorpc.V1alpha.Query.Query
100+
Proto.Utxorpc.V1alpha.Query.Query_Fields
101+
Proto.Utxorpc.V1alpha.Submit.Submit
102+
Proto.Utxorpc.V1alpha.Submit.Submit_Fields
103+
104+
build-depends:
105+
proto-lens-protobuf-types,
106+
proto-lens-runtime,
107+
114108
test-suite cardano-rpc-test
115109
import: project-config
116110
hs-source-dirs: test/cardano-rpc-test
117111
main-is: cardano-rpc-test.hs
118112
type: exitcode-stdio-1.0
119113
build-depends:
114+
base,
120115
cardano-api,
121116
cardano-api:gen,
122117
cardano-ledger-api,
123118
cardano-ledger-conway,
124119
cardano-ledger-core,
125120
cardano-rpc,
126121
containers,
127-
hedgehog >=1.1,
122+
hedgehog,
128123
rio,
129124
tasty,
130125
tasty-hedgehog,

0 commit comments

Comments
 (0)