From 9245902cf55665b9881885d14cdb6226bc2be819 Mon Sep 17 00:00:00 2001 From: Marco Manino Date: Thu, 27 Jun 2024 08:17:17 +0200 Subject: [PATCH] Allow builds without libdqlite --- Makefile | 8 +++---- cmd/root.go | 5 +++++ cmd/version.go | 22 ++++++------------- cmd/version_no_dqlite.go | 9 ++++++++ pkg/server/server.go | 2 ++ pkg/server/server_no_dqlite.go | 39 ++++++++++++++++++++++++++++++++++ 6 files changed, 65 insertions(+), 20 deletions(-) create mode 100644 cmd/version_no_dqlite.go create mode 100644 pkg/server/server_no_dqlite.go diff --git a/Makefile b/Makefile index aa18993b..da8bf958 100644 --- a/Makefile +++ b/Makefile @@ -10,16 +10,16 @@ go.vet: $(DQLITE_BUILD_SCRIPTS_DIR)/static-go-vet.sh ./... go.test: - go test -tags=libsqlite3 -v ./test + go test -v -p 1 ./... go.test.dqlite: - $(DQLITE_BUILD_SCRIPTS_DIR)/static-go-test.sh -v ./test + $(DQLITE_BUILD_SCRIPTS_DIR)/static-go-test.sh -v ./... go.bench: - go test -tags=libsqlite3 -v ./test -run "^$$" -bench "Benchmark" -benchmem + go test -tags=libsqlite3 -v ./... -run "^$$" -bench "Benchmark" -benchmem go.bench.dqlite: - $(DQLITE_BUILD_SCRIPTS_DIR)/static-go-test.sh -v ./test -run "^$$" -bench "Benchmark" -benchmem + $(DQLITE_BUILD_SCRIPTS_DIR)/static-go-test.sh -v ./... -run "^$$" -bench "Benchmark" -benchmem ## Static Builds static: bin/static/k8s-dqlite bin/static/dqlite diff --git a/cmd/root.go b/cmd/root.go index 652926a8..4a624c54 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -155,4 +155,9 @@ func init() { rootCmd.Flags().BoolVar(&rootCmdOpts.etcdMode, "etcd-mode", false, "Run in etcd mode") rootCmd.AddCommand(dbctl.Command) + + rootCmd.AddCommand(&cobra.Command{ + Use: "version", + RunE: func(cmd *cobra.Command, args []string) error { return printVersions() }, + }) } diff --git a/cmd/version.go b/cmd/version.go index ae2a3dec..8b86c868 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -1,10 +1,10 @@ +//go:build dqlite + package cmd import ( "fmt" "runtime" - - "github.com/spf13/cobra" ) /* @@ -48,18 +48,8 @@ void print_dqlite_library_versions() { */ import "C" -var ( - versionCmd = &cobra.Command{ - Use: "version", - RunE: func(cmd *cobra.Command, args []string) error { - fmt.Println("go:", runtime.Version()) - C.print_dqlite_library_versions() - - return nil - }, - } -) - -func init() { - rootCmd.AddCommand(versionCmd) +func printVersions() error { + fmt.Println("go:", runtime.Version()) + C.print_dqlite_library_versions() + return nil } diff --git a/cmd/version_no_dqlite.go b/cmd/version_no_dqlite.go new file mode 100644 index 00000000..f18353b6 --- /dev/null +++ b/cmd/version_no_dqlite.go @@ -0,0 +1,9 @@ +//go:build !dqlite + +package cmd + +import "fmt" + +func printVersions() error { + return fmt.Errorf("dqlite is not supported, compile with \"-tags dqlite\"") +} diff --git a/pkg/server/server.go b/pkg/server/server.go index 7c37e8c4..564d3e84 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -1,3 +1,5 @@ +//go:build dqlite + package server import ( diff --git a/pkg/server/server_no_dqlite.go b/pkg/server/server_no_dqlite.go new file mode 100644 index 00000000..56ba5c0c --- /dev/null +++ b/pkg/server/server_no_dqlite.go @@ -0,0 +1,39 @@ +//go:build !dqlite + +package server + +import ( + "context" + "errors" + "time" +) + +var errNoDqlite = errors.New("dqlite is not supported, compile with \"-tags dqlite\"") +var closedCh = make(chan struct{}) + +func init() { + close(closedCh) +} + +type Server struct{} + +func (*Server) Start(ctx context.Context) error { return errNoDqlite } +func (*Server) MustStop() <-chan struct{} { return closedCh } +func (*Server) Shutdown(ctx context.Context) error { return errNoDqlite } + +func New( + dir string, + listen string, + enableTLS bool, + diskMode bool, + clientSessionCacheSize uint, + minTLSVersion string, + watchAvailableStorageInterval time.Duration, + watchAvailableStorageMinBytes uint64, + lowAvailableStorageAction string, + admissionControlPolicy string, + admissionControlPolicyLimitMaxConcurrentTxn int64, + admissionControlOnlyWriteQueries bool, +) (*Server, error) { + return nil, errNoDqlite +}