From 9da59512523f97d89bcd3e0a3382418c5f878602 Mon Sep 17 00:00:00 2001 From: Angelos Kolaitis Date: Tue, 27 Feb 2024 20:02:19 +0200 Subject: [PATCH] followup fixes - use bin/dynamic/lib for dqlite shared libraries - configurable build-scripts directory - use go install for dqlite cmd tool --- .github/workflows/go.yaml | 2 +- Makefile | 39 ++++++++++++++++++-------------------- hack/dynamic-go-install.sh | 10 ++++++++++ hack/static-go-install.sh | 10 ++++++++++ 4 files changed, 39 insertions(+), 22 deletions(-) create mode 100755 hack/dynamic-go-install.sh create mode 100755 hack/static-go-install.sh diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 3579d66e..b6813280 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -138,7 +138,7 @@ jobs: - name: Build shared binaries run: | make -j dynamic - export LD_LIBRARY_PATH=bin/dynamic + export LD_LIBRARY_PATH=bin/dynamic/lib ./bin/dynamic/k8s-dqlite --help ./bin/dynamic/k8s-dqlite migrator --help diff --git a/Makefile b/Makefile index 7c910162..aa18993b 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +DQLITE_BUILD_SCRIPTS_DIR ?= $(shell pwd)/hack GO_SOURCES = $(shell find . -name '*.go') ## Development @@ -6,53 +7,49 @@ go.fmt: go fmt ./... go.vet: - ./hack/static-go-vet.sh ./... + $(DQLITE_BUILD_SCRIPTS_DIR)/static-go-vet.sh ./... go.test: go test -tags=libsqlite3 -v ./test go.test.dqlite: - ./hack/static-go-test.sh -v ./test + $(DQLITE_BUILD_SCRIPTS_DIR)/static-go-test.sh -v ./test go.bench: go test -tags=libsqlite3 -v ./test -run "^$$" -bench "Benchmark" -benchmem go.bench.dqlite: - ./hack/static-go-test.sh -v ./test -run "^$$" -bench "Benchmark" -benchmem + $(DQLITE_BUILD_SCRIPTS_DIR)/static-go-test.sh -v ./test -run "^$$" -bench "Benchmark" -benchmem ## Static Builds static: bin/static/k8s-dqlite bin/static/dqlite -deps/static/lib/libdqlite.a: - ./hack/static-dqlite.sh +$(DQLITE_BUILD_SCRIPTS_DIR)/.deps/static/lib/libdqlite.a: + $(DQLITE_BUILD_SCRIPTS_DIR)/static-dqlite.sh -bin/static/k8s-dqlite: deps/static/lib/libdqlite.a $(GO_SOURCES) +bin/static/k8s-dqlite: $(DQLITE_BUILD_SCRIPTS_DIR)/.deps/static/lib/libdqlite.a $(GO_SOURCES) mkdir -p bin/static - ./hack/static-go-build.sh -o bin/static/k8s-dqlite ./k8s-dqlite.go + $(DQLITE_BUILD_SCRIPTS_DIR)/static-go-build.sh -o bin/static/k8s-dqlite ./k8s-dqlite.go -bin/static/dqlite: deps/static/lib/libdqlite.a +bin/static/dqlite: $(DQLITE_BUILD_SCRIPTS_DIR)/.deps/static/lib/libdqlite.a mkdir -p bin/static - rm -rf hack/.build/go-dqlite - git clone https://github.com/canonical/go-dqlite --depth 1 -b v1.20.0 hack/.build/go-dqlite - cd hack/.build/go-dqlite && ../../../hack/static-go-build.sh -o ../../../bin/static/dqlite ./cmd/dqlite + GOBIN=$(shell pwd)/bin/static $(DQLITE_BUILD_SCRIPTS_DIR)/static-go-install.sh github.com/canonical/go-dqlite/cmd/dqlite@v1.20.0 ## Dynamic Builds dynamic: bin/dynamic/k8s-dqlite bin/dynamic/dqlite -bin/dynamic/libdqlite.so: - mkdir -p bin/dynamic - ./hack/dynamic-dqlite.sh - cp -rv ./hack/.deps/dynamic/lib/*.so* ./bin/dynamic/ +bin/dynamic/lib/libdqlite.so: + mkdir -p bin/dynamic/lib + $(DQLITE_BUILD_SCRIPTS_DIR)/dynamic-dqlite.sh + cp -rv $(DQLITE_BUILD_SCRIPTS_DIR)/.deps/dynamic/lib/*.so* ./bin/dynamic/lib/ -bin/dynamic/k8s-dqlite: bin/dynamic/libdqlite.so $(GO_SOURCES) +bin/dynamic/k8s-dqlite: bin/dynamic/lib/libdqlite.so $(GO_SOURCES) mkdir -p bin/dynamic - ./hack/dynamic-go-build.sh -o bin/dynamic/k8s-dqlite ./k8s-dqlite.go + $(DQLITE_BUILD_SCRIPTS_DIR)/dynamic-go-build.sh -o bin/dynamic/k8s-dqlite ./k8s-dqlite.go -bin/dynamic/dqlite: bin/dynamic/libdqlite.so +bin/dynamic/dqlite: bin/dynamic/lib/libdqlite.so mkdir -p bin/dynamic - rm -rf hack/.build/go-dqlite - git clone https://github.com/canonical/go-dqlite --depth 1 -b v1.20.0 hack/.build/go-dqlite - cd hack/.build/go-dqlite && ../../../hack/dynamic-go-build.sh -o ../../../bin/dynamic/dqlite ./cmd/dqlite + GOBIN=$(shell pwd)/bin/dynamic $(DQLITE_BUILD_SCRIPTS_DIR)/dynamic-go-install.sh github.com/canonical/go-dqlite/cmd/dqlite@v1.20.0 ## Cleanup clean: diff --git a/hack/dynamic-go-install.sh b/hack/dynamic-go-install.sh new file mode 100755 index 00000000..8fbef01c --- /dev/null +++ b/hack/dynamic-go-install.sh @@ -0,0 +1,10 @@ +#!/bin/bash -xeu + +DIR="$(realpath `dirname "${0}"`)" + +. "${DIR}/dynamic-dqlite.sh" + +go install \ + -tags dqlite,libsqlite3 \ + -ldflags '-s -w' \ + "${@}" diff --git a/hack/static-go-install.sh b/hack/static-go-install.sh new file mode 100755 index 00000000..f42ca893 --- /dev/null +++ b/hack/static-go-install.sh @@ -0,0 +1,10 @@ +#!/bin/bash -xeu + +DIR="$(realpath `dirname "${0}"`)" + +. "${DIR}/static-dqlite.sh" + +go install \ + -tags dqlite,libsqlite3 \ + -ldflags '-s -w -linkmode "external" -extldflags "-static"' \ + "${@}"