From b3256d9058aa93176190cb69f73afb72f0730100 Mon Sep 17 00:00:00 2001 From: Ryan Graham Date: Tue, 8 May 2018 15:47:34 -0700 Subject: static: use pkg-config exclusively when using it When using the static linking option on platforms that use pkg-config, use ONLY pkg-config to get the CFLAGS and LDFLAGS. This prevents pulling in dependencies and flags for any non-vendored version that may be present on the host. The main practical effect of this is that if someone doesn't need/want any sort of remote access support at all they can completely disable libcurl, libssh2, libssl, etc and produce a smaller/simpler binary and greatly simplify their build-time dependencies. When done properly, the generated pkg-config file will tell cgo everything it needs to know. This also prevents confusion if there is a system copy of libgit2 that is being given priority over the vendored build. Signed-off-by: Ryan Graham --- script/build-libgit2-static.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'script/build-libgit2-static.sh') diff --git a/script/build-libgit2-static.sh b/script/build-libgit2-static.sh index 5723721..1568ece 100755 --- a/script/build-libgit2-static.sh +++ b/script/build-libgit2-static.sh @@ -16,4 +16,4 @@ cmake -DTHREADSAFE=ON \ -DCMAKE_INSTALL_PREFIX=../install \ .. && -cmake --build . +cmake --build . --target install -- cgit v1.2.3 From f3c487966d53ad78e25d2e6750414009f5606dbb Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sat, 5 Jan 2019 20:13:01 +0000 Subject: Improve the static build script This change: * Uses the installed version of both the library and the pkgconfig file, which fixes path resolution on Ubuntu Xenial. * Uses quoting liberally so that paths with spaces in them are correctly handled. * Moves the build+install directories to static-build/ in the git2go repository to avoid having a dirty vendor/libgit2 checkout. --- .gitignore | 1 + git_static.go | 6 +++--- script/build-libgit2-static.sh | 15 ++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 .gitignore (limited to 'script/build-libgit2-static.sh') diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..edc18d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/static-build/ diff --git a/git_static.go b/git_static.go index 243669f..547ae8a 100644 --- a/git_static.go +++ b/git_static.go @@ -3,9 +3,9 @@ package git /* -#cgo windows CFLAGS: -I${SRCDIR}/vendor/libgit2/include -#cgo windows LDFLAGS: -L${SRCDIR}/vendor/libgit2/build/ -lgit2 -lwinhttp -#cgo !windows pkg-config: --static ${SRCDIR}/vendor/libgit2/build/libgit2.pc +#cgo windows CFLAGS: -I${SRCDIR}/static-build/install/include/ +#cgo windows LDFLAGS: -L${SRCDIR}/static-build/install/lib/ -lgit2 -lwinhttp +#cgo !windows pkg-config: --static ${SRCDIR}/static-build/install/lib/pkgconfig/libgit2.pc #include #if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 27 diff --git a/script/build-libgit2-static.sh b/script/build-libgit2-static.sh index 1568ece..680dd93 100755 --- a/script/build-libgit2-static.sh +++ b/script/build-libgit2-static.sh @@ -2,18 +2,19 @@ set -ex -VENDORED_PATH=vendor/libgit2 +ROOT="$(cd "$0/../.." && echo "${PWD}")" +BUILD_PATH="${ROOT}/static-build" +VENDORED_PATH="${ROOT}/vendor/libgit2" -cd $VENDORED_PATH && -mkdir -p install/lib && -mkdir -p build && -cd build && +mkdir -p "${BUILD_PATH}/build" "${BUILD_PATH}/install/lib" + +cd "${BUILD_PATH}/build" && cmake -DTHREADSAFE=ON \ -DBUILD_CLAR=OFF \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_C_FLAGS=-fPIC \ -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_INSTALL_PREFIX=../install \ - .. && + -DCMAKE_INSTALL_PREFIX="${BUILD_PATH}/install" \ + "${VENDORED_PATH}" && cmake --build . --target install -- cgit v1.2.3 From 13090d85b44a9ff5f5781f28ef1807fbc6ecb864 Mon Sep 17 00:00:00 2001 From: Jon Miller Date: Tue, 7 May 2019 11:36:34 -0400 Subject: script/build-libgit2-static.sh: correctly set ROOT The ROOT variable is not being set correctly. Need to use dirname against $0 as well as only go up one directory instead of two. --- script/build-libgit2-static.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'script/build-libgit2-static.sh') diff --git a/script/build-libgit2-static.sh b/script/build-libgit2-static.sh index 680dd93..4d89fba 100755 --- a/script/build-libgit2-static.sh +++ b/script/build-libgit2-static.sh @@ -2,7 +2,7 @@ set -ex -ROOT="$(cd "$0/../.." && echo "${PWD}")" +ROOT="$(cd "$(dirname "$0")/.." && echo "${PWD}")" BUILD_PATH="${ROOT}/static-build" VENDORED_PATH="${ROOT}/vendor/libgit2" -- cgit v1.2.3 From 57ab6bc351f96caabdeb58a5092c9dda51962603 Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Tue, 13 Aug 2019 20:15:01 +0200 Subject: script: tell libgit2 to use the builtin regex backend --- script/build-libgit2-static.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'script/build-libgit2-static.sh') diff --git a/script/build-libgit2-static.sh b/script/build-libgit2-static.sh index 680dd93..096c5c6 100755 --- a/script/build-libgit2-static.sh +++ b/script/build-libgit2-static.sh @@ -12,6 +12,7 @@ cd "${BUILD_PATH}/build" && cmake -DTHREADSAFE=ON \ -DBUILD_CLAR=OFF \ -DBUILD_SHARED_LIBS=OFF \ + -DREGEX_BACKEND=builtin \ -DCMAKE_C_FLAGS=-fPIC \ -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ -DCMAKE_INSTALL_PREFIX="${BUILD_PATH}/install" \ -- cgit v1.2.3 From 26edffd5f57618d2927926fde4c4ac1fcba5d84a Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sat, 22 Feb 2020 23:07:08 +0000 Subject: Update CI configuration This change: * Updates the GitHub actions so that they run different commands for the dynamic and static flavors of libgit2. * Updates the .travis.yml file so that it does roughly the same as the GitHub actions. * Adds the release-* branches to the CI configurations. --- .github/workflows/ci.yml | 64 +++++++++++++++++++++++++++++++++++++++-- .gitignore | 1 + .travis.yml | 16 +++++++---- Makefile | 47 ++++++++++++++++++++++++++---- script/build-libgit2-dynamic.sh | 5 ++++ script/build-libgit2-static.sh | 20 ++----------- script/build-libgit2.sh | 46 +++++++++++++++++++++++++++++ 7 files changed, 166 insertions(+), 33 deletions(-) create mode 100755 script/build-libgit2-dynamic.sh create mode 100755 script/build-libgit2.sh (limited to 'script/build-libgit2-static.sh') diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d058ec6..931cc09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,15 +4,16 @@ on: push: branches: - master + - release-* - v* jobs: - build: + build-legacy: strategy: fail-fast: false matrix: - go: [ '1.9', '1.10', '1.11', '1.12' , '1.13'] + go: [ '1.9', '1.10' ] name: Go ${{ matrix.go }} runs-on: ubuntu-18.04 @@ -23,9 +24,66 @@ jobs: with: go-version: ${{ matrix.go }} id: go + - name: Check out code into the GOPATH + uses: actions/checkout@v1 + with: + fetch-depth: 1 + path: src/github.com/${{ github.repository }} + - name: Build + env: + GOPATH: /home/runner/work/git2go + run: | + git submodule update --init + make build-libgit2-static + go get --tags "static" github.com/${{ github.repository }}/... + go build --tags "static" github.com/${{ github.repository }}/... + - name: Test + env: + GOPATH: /home/runner/work/git2go + run: make test-static + + build-static: + strategy: + fail-fast: false + matrix: + go: [ '1.11', '1.12', '1.13' ] + name: Go ${{ matrix.go }} + + runs-on: ubuntu-18.04 + + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go }} + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + - name: Build + run: | + git submodule update --init + make build-libgit2-static + - name: Test + run: make test-static + + build-dynamic: + strategy: + fail-fast: false + name: Go (dynamic) + + runs-on: ubuntu-18.04 + + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: '1.13' + id: go - name: Check out code into the Go module directory uses: actions/checkout@v1 - name: Build run: | git submodule update --init - make test-static + make build-libgit2-dynamic + - name: Test + run: make test-dynamic diff --git a/.gitignore b/.gitignore index edc18d5..713781b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /static-build/ +/dynamic-build/ diff --git a/.travis.yml b/.travis.yml index 7d53122..b25a052 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,25 +1,29 @@ language: go go: + - "1.9" + - "1.10" - "1.11" - "1.12" - "1.13" - tip -script: make test-static +install: + - make build-libgit2-static + - go get --tags "static" ./... + +script: + - make test-static matrix: allow_failures: - go: tip git: - submodules: false - -before_install: - - git submodule update --init + submodules: true branches: only: - master - /v\d+/ - - next + - /release-.*/ diff --git a/Makefile b/Makefile index 4dffce0..182c53e 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,53 @@ default: test -test: build-libgit2 +# System library +# ============== +# This uses whatever version of libgit2 can be found in the system. +test: go run script/check-MakeGitError-thread-lock.go go test --count=1 ./... -install: build-libgit2 +install: go install ./... -build-libgit2: +# Bundled dynamic library +# ======================= +# In order to avoid having to manipulate `git_dynamic.go`, which would prevent +# the system-wide libgit2.so from being used in a sort of ergonomic way, this +# instead moves the complexity of overriding the paths so that the built +# libraries can be found by the build and tests. +.PHONY: build-libgit2-dynamic +build-libgit2-dynamic: + ./script/build-libgit2-dynamic.sh + +dynamic-build/install/lib/libgit2.so: + ./script/build-libgit2-dynamic.sh + +test-dynamic: dynamic-build/install/lib/libgit2.so + PKG_CONFIG_PATH=dynamic-build/install/lib/pkgconfig \ + go run script/check-MakeGitError-thread-lock.go + PKG_CONFIG_PATH=dynamic-build/install/lib/pkgconfig \ + LD_LIBRARY_PATH=dynamic-build/install/lib \ + go test --count=1 ./... + +install-dynamic: dynamic-build/install/lib/libgit2.so + PKG_CONFIG_PATH=dynamic-build/install/lib/pkgconfig \ + go install ./... + +# Bundled static library +# ====================== +# This is mostly used in tests, but can also be used to provide a +# statically-linked library with the bundled version of libgit2. +.PHONY: build-libgit2-static +build-libgit2-static: ./script/build-libgit2-static.sh -install-static: build-libgit2 - go install --tags "static" ./... +static-build/install/lib/libgit2.a: + ./script/build-libgit2-static.sh -test-static: build-libgit2 +test-static: static-build/install/lib/libgit2.a go run script/check-MakeGitError-thread-lock.go go test --count=1 --tags "static" ./... + +install-static: static-build/install/lib/libgit2.a + go install --tags "static" ./... diff --git a/script/build-libgit2-dynamic.sh b/script/build-libgit2-dynamic.sh new file mode 100755 index 0000000..af037f3 --- /dev/null +++ b/script/build-libgit2-dynamic.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +exec "$(dirname "$0")/build-libgit2.sh" --dynamic diff --git a/script/build-libgit2-static.sh b/script/build-libgit2-static.sh index 26efc8e..1d28898 100755 --- a/script/build-libgit2-static.sh +++ b/script/build-libgit2-static.sh @@ -1,21 +1,5 @@ #!/bin/sh -set -ex +set -e -ROOT="$(cd "$(dirname "$0")/.." && echo "${PWD}")" -BUILD_PATH="${ROOT}/static-build" -VENDORED_PATH="${ROOT}/vendor/libgit2" - -mkdir -p "${BUILD_PATH}/build" "${BUILD_PATH}/install/lib" - -cd "${BUILD_PATH}/build" && -cmake -DTHREADSAFE=ON \ - -DBUILD_CLAR=OFF \ - -DBUILD_SHARED_LIBS=OFF \ - -DREGEX_BACKEND=builtin \ - -DCMAKE_C_FLAGS=-fPIC \ - -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_INSTALL_PREFIX="${BUILD_PATH}/install" \ - "${VENDORED_PATH}" && - -cmake --build . --target install +exec "$(dirname "$0")/build-libgit2.sh" --static diff --git a/script/build-libgit2.sh b/script/build-libgit2.sh new file mode 100755 index 0000000..acbc84a --- /dev/null +++ b/script/build-libgit2.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# Since CMake cannot build the static and dynamic libraries in the same +# directory, this script helps build both static and dynamic versions of it and +# have the common flags in one place instead of split between two places. + +set -e + +if [ "$#" -eq "0" ]; then + echo "Usage: $0 <--dynamic|--static>">&2 + exit 1 +fi + +ROOT="$(cd "$(dirname "$0")/.." && echo "${PWD}")" +VENDORED_PATH="${ROOT}/vendor/libgit2" + +case "$1" in + --static) + BUILD_PATH="${ROOT}/static-build" + BUILD_SHARED_LIBS=OFF + ;; + + --dynamic) + BUILD_PATH="${ROOT}/dynamic-build" + BUILD_SHARED_LIBS=ON + ;; + + *) + echo "Usage: $0 <--dynamic|--static>">&2 + exit 1 + ;; +esac + +mkdir -p "${BUILD_PATH}/build" "${BUILD_PATH}/install/lib" + +cd "${BUILD_PATH}/build" && +cmake -DTHREADSAFE=ON \ + -DBUILD_CLAR=OFF \ + -DBUILD_SHARED_LIBS"=${BUILD_SHARED_LIBS}" \ + -DREGEX_BACKEND=builtin \ + -DCMAKE_C_FLAGS=-fPIC \ + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ + -DCMAKE_INSTALL_PREFIX="${BUILD_PATH}/install" \ + "${VENDORED_PATH}" && + +exec cmake --build . --target install -- cgit v1.2.3