Skip to content

Commit bbe9884

Browse files
committed
Link dynamically or statically depending on build flags
This lets us specify which set of rules to link to libgit2 we'll use during build. Together with the changes to the Makefile, this lets you specify make install or make install-static to build either dynamically against the system-provided library or against the version specified in the submodule. The dynamic linking against the system library is still the default in order to allow for the Go toolchain to build it when it's used as a dependency.
1 parent f0554d8 commit bbe9884

File tree

6 files changed

+38
-2
lines changed

6 files changed

+38
-2
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "vendor/libgit2"]
2+
path = vendor/libgit2
3+
url = https://github.com/libgit2/libgit2

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
default: test
22

3+
build-libgit2:
4+
./script/build-libgit2-static.sh
5+
6+
test-static: build-libgit2
7+
go run script/check-MakeGitError-thread-lock.go
8+
go test -tags static ./...
9+
10+
build-static: build-libgit2
11+
go build -tags static ./...
12+
13+
install-static: build-libgit2
14+
go install -tags static ./...
15+
316
test:
417
go run script/check-MakeGitError-thread-lock.go
518
go test ./...
619

7-
install: build-libgit2
20+
install:
821
go install ./...

git.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package git
33
/*
44
#include <git2.h>
55
#include <git2/sys/openssl.h>
6-
#cgo pkg-config: libgit2
76
87
#if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 25
98
# error "Invalid libgit2 version; this git2go supports libgit2 v0.25"

git_dynamic.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build !static
2+
3+
package git
4+
5+
/*
6+
#cgo pkg-config: libgit2
7+
#include <git2.h>
8+
*/
9+
import "C"

git_static.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// +build static
2+
3+
package git
4+
5+
/*
6+
#cgo CFLAGS: -I${SRCDIR}/vendor/libgit2/include
7+
#cgo LDFLAGS: -L${SRCDIR}/vendor/libgit2/build/ -lgit2
8+
#cgo windows LDFLAGS: -lwinhttp
9+
#cgo !windows pkg-config: --static ${SRCDIR}/vendor/libgit2/build/libgit2.pc
10+
*/
11+
import "C"

vendor/libgit2

Submodule libgit2 added at 2fcb870

0 commit comments

Comments
 (0)