Skip to content

Commit

Permalink
Merge pull request #91 from canonical/KU-401/followup
Browse files Browse the repository at this point in the history
Follow up fixes on k8s-dqlite build process
  • Loading branch information
neoaggelos authored Feb 28, 2024
2 parents 27066fb + 9da5951 commit 4bf13af
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 18 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DQLITE_BUILD_SCRIPTS_DIR ?= $(shell pwd)/hack
GO_SOURCES = $(shell find . -name '*.go')

## Development
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions hack/dynamic-go-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -xeu

DIR="$(realpath `dirname "${0}"`)"

. "${DIR}/dynamic-dqlite.sh"

go install \
-tags dqlite,libsqlite3 \
-ldflags '-s -w' \
"${@}"
10 changes: 10 additions & 0 deletions hack/static-go-install.sh
Original file line number Diff line number Diff line change
@@ -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"' \
"${@}"

0 comments on commit 4bf13af

Please sign in to comment.