From f4c879e525a56e81cda63db18624e5de18a593bd Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 12 Jul 2025 23:15:18 +0200 Subject: [PATCH] build: switch from protoc to buf to build protobuf --- .github/workflows/ci.yml | 6 +----- .gitlab-ci.yml | 2 +- Makefile | 7 +++---- bin/protoc-gen-go | 2 -- buf.gen.yaml | 7 +++++++ console/data/docs/01-install.md | 4 ++-- flake.nix | 3 +-- go.mod | 6 +++--- nix/vendorHash.txt | 2 +- 9 files changed, 19 insertions(+), 20 deletions(-) delete mode 100755 bin/protoc-gen-go create mode 100644 buf.gen.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81a13219..53b3fd7e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,7 +48,7 @@ jobs: - name: Setup uses: ./.github/actions/setup - name: Install dependencies - run: sudo apt-get install -qqy shared-mime-info curl protobuf-compiler + run: sudo apt-get install -qqy shared-mime-info curl # Build and test - name: Build @@ -93,8 +93,6 @@ jobs: persist-credentials: false - name: Setup uses: ./.github/actions/setup - - name: Install dependencies - run: brew install protobuf # Build and test - name: Build @@ -157,8 +155,6 @@ jobs: uses: ./.github/actions/setup with: go-version: ${{ matrix.go-version }} - - name: Install dependencies - run: sudo apt-get install -qqy protobuf-compiler - name: Build run: make && ./bin/akvorado version - uses: actions/cache/save@v4 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 54f77e8e..182f41c0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,7 +23,7 @@ run tests: # past but this is a slight burden to maintain in addition to GitHub CI. # Check commit ceaa6ebf8ef6 for the last version supporting functional # tests. - - time apk add --no-cache git make gcc musl-dev shared-mime-info npm curl protoc + - time apk add --no-cache git make gcc musl-dev shared-mime-info npm curl - export GOMODCACHE=$PWD/.go-cache - npm config --user set cache $PWD/.npm-cache - time go mod download diff --git a/Makefile b/Makefile index d3ea18f2..742d965f 100644 --- a/Makefile +++ b/Makefile @@ -59,17 +59,16 @@ GOIMPORTS = go tool goimports GOTESTSUM = go tool gotestsum MOCKGEN = go tool mockgen PIGEON = go tool pigeon -PROTOC = protoc -PROTOC_GEN_GO = bin/protoc-gen-go REVIVE = go tool revive WWHRD = go tool wwhrd +BUF = go run github.com/bufbuild/buf/cmd/buf@v1.55.1 # Generated files .DELETE_ON_ERROR: -common/pb/rawflow.pb.go: common/pb/rawflow.proto ; $(info $(M) compiling protocol buffers definition…) - $Q $(PROTOC) -I=. --plugin=$(PROTOC_GEN_GO) --go_out=. --go_opt=module=$(MODULE) $< +common/pb/rawflow.pb.go: %.pb.go: buf.gen.yaml %.proto ; $(info $(M) compiling protocol buffers definition…) + $Q $(BUF) generate --path $(@:.pb.go=.proto) common/clickhousedb/mocks/mock_driver.go: go.mod ; $(info $(M) generate mocks for ClickHouse driver…) $Q $(MOCKGEN) -package mocks -build_constraint "!release" -destination $@ \ diff --git a/bin/protoc-gen-go b/bin/protoc-gen-go deleted file mode 100755 index 90ca6f62..00000000 --- a/bin/protoc-gen-go +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -go tool protoc-gen-go "$@" diff --git a/buf.gen.yaml b/buf.gen.yaml new file mode 100644 index 00000000..64ef098f --- /dev/null +++ b/buf.gen.yaml @@ -0,0 +1,7 @@ +--- +version: v2 +plugins: + - local: [ "go", "tool", "protoc-gen-go" ] + out: . + opt: + - paths=source_relative diff --git a/console/data/docs/01-install.md b/console/data/docs/01-install.md index ced19e88..1ba881a4 100644 --- a/console/data/docs/01-install.md +++ b/console/data/docs/01-install.md @@ -31,12 +31,12 @@ Currently, only a pre-built binary for Linux x86-64 is provided. ## Compilation from source -You need a proper installation of [Go](https://go.dev/doc/install) (1.24+) and +You need a proper installation of [Go](https://go.dev/doc/install) (1.24+), and [NodeJS](https://nodejs.org/en/download/) (20+) with NPM (6+). For example, on Debian: ```console -# apt install golang nodejs npm protobuf-compiler +# apt install golang nodejs npm # go version go version go1.24.1 linux/amd64 # node --version diff --git a/flake.nix b/flake.nix index 0c02df6b..5d258b51 100644 --- a/flake.nix +++ b/flake.nix @@ -55,7 +55,7 @@ find . -print0 | xargs -0 touch -d @0 make all \ - PROTOC=${pkgs.protobuf}/bin/protoc \ + BUF=${pkgs.buf}/bin/buf \ ASNS_URL=${asn2org}/asns.csv \ SERVICES_URL=${ianaServiceNames} ''; @@ -111,7 +111,6 @@ nodejs pkgs.git pkgs.curl - pkgs.protobuf ]; }; }); diff --git a/go.mod b/go.mod index fcedd121..1d00923f 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module akvorado go 1.24 require ( + github.com/ClickHouse/ch-go v0.66.1 github.com/ClickHouse/clickhouse-go/v2 v2.37.2 github.com/IBM/sarama v1.45.2 github.com/alecthomas/chroma v0.10.0 @@ -26,7 +27,6 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 github.com/hashicorp/go-version v1.7.0 github.com/itchyny/gojq v0.12.17 - github.com/jhump/protoreflect v1.17.0 github.com/kentik/patricia v1.2.1 github.com/kylelemons/godebug v1.1.0 github.com/mattn/go-isatty v0.0.20 @@ -50,7 +50,6 @@ require ( golang.org/x/oauth2 v0.30.0 golang.org/x/sys v0.33.0 golang.org/x/text v0.26.0 - golang.org/x/time v0.12.0 google.golang.org/grpc v1.72.2 google.golang.org/protobuf v1.36.6 gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 @@ -66,7 +65,6 @@ require ( github.com/AlekSi/gocov-xml v1.1.0 // indirect github.com/AlekSi/pointer v1.2.0 // indirect github.com/BurntSushi/toml v1.4.0 // indirect - github.com/ClickHouse/ch-go v0.66.1 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/andybalholm/brotli v1.1.1 // indirect github.com/axw/gocov v1.2.1 // indirect @@ -134,6 +132,7 @@ require ( github.com/jcmturner/rpc/v2 v2.0.3 // indirect github.com/jellydator/ttlcache/v2 v2.11.1 // indirect github.com/jessevdk/go-flags v1.5.0 // indirect + github.com/jhump/protoreflect v1.17.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/josharian/native v1.1.0 // indirect @@ -199,6 +198,7 @@ require ( golang.org/x/net v0.41.0 // indirect golang.org/x/sync v0.15.0 // indirect golang.org/x/term v0.32.0 // indirect + golang.org/x/time v0.12.0 // indirect golang.org/x/tools v0.33.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/nix/vendorHash.txt b/nix/vendorHash.txt index 0cb330cf..32e15c58 100644 --- a/nix/vendorHash.txt +++ b/nix/vendorHash.txt @@ -1 +1 @@ -sha256-TeYE1s4Yw4Ag2IbmP/bNgzP+XoOiup+gXm25nNaeTAU= +sha256-Ejw42fH6T+qZXeR5lJ9ThmzXTWnRg1fSnh70La8LmGw=