Skip to content

Commit

Permalink
Allow builds without libdqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
marco6 committed Jun 27, 2024
1 parent 36366fd commit 3441866
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() },
})
}
22 changes: 6 additions & 16 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//go:build dqlite

package cmd

import (
"fmt"
"runtime"

"github.com/spf13/cobra"
)

/*
Expand Down Expand Up @@ -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
}
9 changes: 9 additions & 0 deletions cmd/version_no_dqlite.go
Original file line number Diff line number Diff line change
@@ -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\"")
}
2 changes: 2 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dqlite

package server

import (
Expand Down
39 changes: 39 additions & 0 deletions pkg/server/server_no_dqlite.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 3441866

Please sign in to comment.