lean-grpc

License Lean Docs

General-purpose Lean 4 gRPC library: HPACK + HTTP/2 + gRPC framing on Std.Async.TCP.

Standalone Lake package (1.1.0). Consumers depend via git tag or, after indexing, Reservoir.

Docs: rileybetts.ai/oss/lean-grpc (curated) · docs/ (full in-repo index)

Public libraries: Bytes, Hpack, H2, Proto, Grpc (umbrella LeanGrpc). Tests, examples, and the compile-time Proofs library are not consumer API.

Install / depend

System deps: OpenSSL (libssl-dev / Homebrew openssl + pkg-config). If headers are missing: ./scripts/fetch-openssl-headers.sh. On macOS, set LIBRARY_PATH for Homebrew OpenSSL (see docs/packaging.md).

In your lakefile.lean:

require «lean-grpc» from git
  "https://github.com/RileyBetts/lean-grpc.git" @ "v1.1.0"

Then import Grpc. After Reservoir lists the package you can use require «lean-grpc» without a git URL. Packaging details and the maintainer release checklist: docs/packaging.md.

Documentation

DocDescription
Hosted docsCurated guides on rileybetts.ai
docs/README.mdFull documentation index (source of truth)
Getting startedTyped unary helloworld, TLS, Lake dependency
CookbooksUnary · streaming · interceptors / mTLS
PackagingLake/Reservoir layout, consumer contract, release checklist
ProvenanceIndependent protocol implementation; third-party interop protos
ArchitectureLayering and data flow
API referenceModule catalogue
Protocol mappinggRPC-over-HTTP/2 mapping for this stack
ConformanceScorecard, interop matrix, allowlists
Formal proofsCompile-time theorems for pure codecs
TLS / EnvoyIn-process OpenSSL and sidecars
CHANGELOGVersion history
ROADMAPWhat v1.1.0 shipped vs open proof/hardening follow-ups
CONTRIBUTINGDev setup and PR expectations
SECURITYVulnerability reporting (security@rileybetts.ai)
Code of ConductCommunity standards

Status

Near grpc-go / official interop parity for general-purpose use. Core wire + Go/Python/Rust interop and stress/framing gates are CI-gated. Cloud-edge items (live Google ADC, ALTS) remain mock/allowlisted.

Rough estimates (see conformance.md for detail):

AxisImplementedTested
Official gRPC standard~95%~90%
vs grpc-go surface~93%~88%
vs Python (grpcio) peer~92%~82%
vs Rust (tonic) peer~92%~82%
LayerPackageNotes
Bytes / slicesBytesHot-path slice views, BE helpers, buffer pool
HPACKHpackStatic + dynamic table, Huffman encode/decode
HTTP/2 h2cH2Full h2spec hard gate; flow control; CONTINUATION; §8.1
Protobuf (minimal)ProtoEnums, nested, repeated, Any/map/oneof helpers
gRPCGrpcDuplex streams, deadlines, compression, dial/LB/retry, health/reflection/channelz
TLSGrpc.Native.Tls + Grpc.TlsIn-process OpenSSL ALPN h2 (sidecar optional); mTLS
ADC / xDSGrpc.Adc, Grpc.XdsAdsSA/metadata Bearer; ADS LDS→EDS chain
Codegenprotoc-gen-lean4-grpcText path + real CodeGeneratorRequest path

Allowlist: ALTS / GCE channel credentials (see Grpc.Gcp).

Build

./scripts/fetch-openssl-headers.sh   # if libssl-dev is unavailable
lake build
lake build Proofs                    # compile-time pure-codec theorems
lake build bytesTests hpackTests h2Tests grpcTests trailersLoopback
./.lake/build/bin/grpcTests
./scripts/build_native.sh            # optional zlib_helper for peer gzip (+ tls_proxy)

Formal proofs of high-leverage pure codecs (status codes, BE ints, gRPC framing, varints, HPACK integers, …): docs/proofs.md.

Quick start

./scripts/gen-helloworld.sh   # typed stubs → Examples/Helloworld/Generated.lean
lake build helloworldServer helloworldClient
./.lake/build/bin/helloworldServer &
./.lake/build/bin/helloworldClient 127.0.0.1 50051 World

Full walkthrough: docs/getting-started.md. Cookbooks: unary, streaming, interceptors / mTLS.

Interop

./scripts/run-go-to-lean.sh                 # Go client → Lean server
GRPC_PORT=10001 ./scripts/interop-go-lean.sh
./scripts/run-python-to-lean.sh             # Python client → Lean
GRPC_PORT=10001 ./scripts/interop-lean-python.sh
./scripts/run-rust-to-lean.sh               # Rust (tonic) client → Lean
GRPC_PORT=10001 ./scripts/interop-lean-rust.sh
./scripts/interop-compress-go-lean.sh       # gzip both directions (Go gzip server)
./scripts/interop-tls-go-lean.sh            # in-process TLS Lean → Go
./scripts/run-adc-smoke.sh                  # ADC against local mock
./scripts/run-xds-ads-smoke.sh              # Fake ADS chain → unary
./scripts/run-codegen-fixture.sh
./scripts/run-soak.sh
./scripts/h2spec.sh

Helloworld / RouteGuide / soak

lake build helloworldServer helloworldClient benchSoak
./.lake/build/bin/helloworldServer &
./.lake/build/bin/helloworldClient 127.0.0.1 50051 World
./.lake/build/bin/benchSoak 127.0.0.1 50051 30

License

SPDX Apache-2.0 — see LICENSE (full terms) and NOTICE (copyright + third-party interop protos). Independent protocol implementation note: docs/provenance.md.