Skip to content

Commit

Permalink
Merge pull request #266 from mergestat/vendor-libgit2
Browse files Browse the repository at this point in the history
feat: vendor `libgit2` (via `git2go`)
  • Loading branch information
patrickdevivo authored Mar 8, 2022
2 parents 25d389e + 4395283 commit 7f969dc
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ jobs:

- name: Check out source
uses: actions/checkout@v1
with:
submodules: recursive

- name: Install libgit2
run: sudo ./scripts/install_libgit2.sh
run: make libgit2

- name: Build
run: make
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ jobs:

- name: Check out source
uses: actions/checkout@v1
with:
submodules: recursive

- name: Install libgit2
run: sudo ./scripts/install_libgit2.sh
run: make libgit2

- name: Vet
run: make vet
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "git2go"]
path = git2go
url = https://github.com/libgit2/git2go
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"go.buildFlags": [
"-tags='libsqlite3'"
],
"go.testFlags": ["-v", "-tags=libsqlite3,static,system_libgit2"],
"go.testFlags": ["-v", "-tags=libsqlite3,static"],
"go.vetFlags": ["-tags=libsqlite3"],
"go.toolsEnvVars": {
"GOFLAGS": "-tags='libsqlite3'",
Expand Down
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
FROM golang:1.17-buster as builder
WORKDIR /app
COPY scripts .
RUN apt-get update && apt-get -y install cmake libssl-dev
RUN ./install_libgit2.sh
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN make libgit2
RUN make

FROM debian:buster-slim
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ ifeq ($(shell uname -s),Darwin)
export CGO_LDFLAGS = -Wl,-undefined,dynamic_lookup
endif

# target to build and install libgit2
libgit2:
cd git2go; make install-static

# target to build a dynamic extension that can be loaded at runtime
.build/libmergestat.so: $(shell find . -type f -name '*.go' -o -name '*.c')
$(call log, $(CYAN), "building $@")
@go build -buildmode=c-shared -o $@ -tags="system_libgit2,shared" shared.go
@go build -buildmode=c-shared -o $@ -tags="static,shared" shared.go
$(call log, $(GREEN), "built $@")

# target to compile mergestat executable
.build/mergestat: $(shell find . -type f -name '*.go' -o -name '*.c')
$(call log, $(CYAN), "building $@")
@go build -o $@ -tags="static,system_libgit2" mergestat.go
@go build -o $@ -tags="static" mergestat.go
$(call log, $(GREEN), "built $@")

# target to download latest sqlite3 amalgamation code
Expand All @@ -43,7 +47,7 @@ clean:
# target for common golang tasks

# go build tags used by test, vet and more
TAGS = "static,system_libgit2"
TAGS = "static"

update:
go get -tags=$(TAGS) -u ./...
Expand Down
1 change: 1 addition & 0 deletions git2go
Submodule git2go added at eae007
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace github.com/libgit2/git2go/v33 => ./git2go
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk=
github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/libgit2/git2go/v33 v33.0.9 h1:4ch2DJed6IhJO28BEohkUoGvxLsRzUjxljoNFJ6/O78=
github.com/libgit2/git2go/v33 v33.0.9/go.mod h1:KdpqkU+6+++4oHna/MIOgx4GCQ92IPCdpVRMRI80J+4=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
Expand Down

0 comments on commit 7f969dc

Please sign in to comment.