Skip to content

Commit 536bacb

Browse files
committed
libgit2: upgrade to golang-with-libgit2 v0.1.4
Upgrade to golang-with-libgit2 v0.1.4 and use libgit2 which is compiled without being linked to libssh2 and openssl. Signed-off-by: Sanskar Jaiswal <[email protected]>
1 parent 3ad7bc9 commit 536bacb

File tree

6 files changed

+25
-183
lines changed

6 files changed

+25
-183
lines changed

ATTRIBUTIONS.md

-90
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,6 @@ code of their open source projects along with license information below.
55
We acknowledge and are grateful to these developers for their contributions
66
to open source.
77

8-
## libssh2
9-
10-
Libssh2 was obtained in source-code form from its github repository:
11-
https://github.com/libssh2/libssh2/
12-
13-
No changes were made to its original source code.
14-
15-
Copyright notice (https://raw.githubusercontent.com/libssh2/libssh2/master/COPYING):
16-
17-
/* Copyright (c) 2004-2007 Sara Golemon <[email protected]>
18-
* Copyright (c) 2005,2006 Mikhail Gusarov <[email protected]>
19-
* Copyright (c) 2006-2007 The Written Word, Inc.
20-
* Copyright (c) 2007 Eli Fant <[email protected]>
21-
* Copyright (c) 2009-2021 Daniel Stenberg
22-
* Copyright (C) 2008, 2009 Simon Josefsson
23-
* Copyright (c) 2000 Markus Friedl
24-
* Copyright (c) 2015 Microsoft Corp.
25-
* All rights reserved.
26-
*
27-
* Redistribution and use in source and binary forms,
28-
* with or without modification, are permitted provided
29-
* that the following conditions are met:
30-
*
31-
* Redistributions of source code must retain the above
32-
* copyright notice, this list of conditions and the
33-
* following disclaimer.
34-
*
35-
* Redistributions in binary form must reproduce the above
36-
* copyright notice, this list of conditions and the following
37-
* disclaimer in the documentation and/or other materials
38-
* provided with the distribution.
39-
*
40-
* Neither the name of the copyright holder nor the names
41-
* of any other contributors may be used to endorse or
42-
* promote products derived from this software without
43-
* specific prior written permission.
44-
*
45-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
46-
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
47-
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48-
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
50-
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51-
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
52-
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
53-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
55-
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
56-
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
57-
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
58-
* OF SUCH DAMAGE.
59-
*/
60-
61-
***
62-
638
## libgit2
649

6510
Libgit2 was obtained in source-code form from its github repository:
@@ -1254,38 +1199,3 @@ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
12541199
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
12551200
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
12561201
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1257-
1258-
***
1259-
1260-
## zlib
1261-
1262-
Zlib was obtained in binary form via official distribution channels.
1263-
No changes were made to its original source code.
1264-
1265-
Copyright notice (https://zlib.net/zlib_license.html):
1266-
1267-
/* zlib.h -- interface of the 'zlib' general purpose compression library
1268-
version 1.2.11, January 15th, 2017
1269-
1270-
Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
1271-
1272-
This software is provided 'as-is', without any express or implied
1273-
warranty. In no event will the authors be held liable for any damages
1274-
arising from the use of this software.
1275-
1276-
Permission is granted to anyone to use this software for any purpose,
1277-
including commercial applications, and to alter it and redistribute it
1278-
freely, subject to the following restrictions:
1279-
1280-
1. The origin of this software must not be misrepresented; you must not
1281-
claim that you wrote the original software. If you use this software
1282-
in a product, an acknowledgment in the product documentation would be
1283-
appreciated but is not required.
1284-
2. Altered source versions must be plainly marked as such, and must not be
1285-
misrepresented as being the original software.
1286-
3. This notice may not be removed or altered from any source distribution.
1287-
1288-
Jean-loup Gailly Mark Adler
1289-
1290-
1291-
*/

Dockerfile

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ ARG BASE_VARIANT=alpine
22
ARG GO_VERSION=1.17
33
ARG XX_VERSION=1.1.0
44

5-
ARG LIBGIT2_IMG=ghcr.io/fluxcd/golang-with-libgit2-all
6-
ARG LIBGIT2_TAG=v0.1.2
5+
ARG LIBGIT2_IMG=ghcr.io/fluxcd/golang-with-libgit2-only
6+
ARG LIBGIT2_TAG=v0.1.4
77

88
FROM ${LIBGIT2_IMG}:${LIBGIT2_TAG} AS libgit2-libs
99

@@ -82,9 +82,8 @@ ENV CGO_ENABLED=1
8282

8383
# Instead of using xx-go, (cross) compile with vanilla go leveraging musl tool chain.
8484
RUN export $(cat build/musl/$(xx-info alpine-arch).env | xargs) && \
85-
export LIBRARY_PATH="/usr/local/$(xx-info triple):/usr/local/$(xx-info triple)/lib64" && \
86-
export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig:/usr/local/$(xx-info triple)/lib64/pkgconfig" && \
87-
export CGO_LDFLAGS="$(pkg-config --static --libs --cflags libssh2 openssl libgit2) -static" && \
85+
export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig" && \
86+
export CGO_LDFLAGS="$(pkg-config --static --libs --cflags libgit2) -static" && \
8887
GOARCH=$TARGETARCH go build \
8988
-ldflags "-s -w" \
9089
-tags 'netgo,osusergo,static_build' \

Makefile

+4-21
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ IMG ?= fluxcd/source-controller
33
TAG ?= latest
44

55
# Base image used to build the Go binary
6-
LIBGIT2_IMG ?= ghcr.io/fluxcd/golang-with-libgit2-all
7-
LIBGIT2_TAG ?= v0.1.2
6+
LIBGIT2_IMG ?= ghcr.io/fluxcd/golang-with-libgit2-only
7+
LIBGIT2_TAG ?= v0.1.4
88

99
# Allows for defining additional Go test args, e.g. '-tags integration'.
1010
GO_TEST_ARGS ?= -race
@@ -32,33 +32,16 @@ ENVTEST_BIN_VERSION ?= 1.19.2
3232
# Caches libgit2 versions per tag, "forcing" rebuild only when needed.
3333
LIBGIT2_PATH := $(BUILD_DIR)/libgit2/$(LIBGIT2_TAG)
3434
LIBGIT2_LIB_PATH := $(LIBGIT2_PATH)/lib
35-
LIBGIT2_LIB64_PATH := $(LIBGIT2_PATH)/lib64
3635
LIBGIT2 := $(LIBGIT2_LIB_PATH)/libgit2.a
3736
MUSL-CC =
3837

3938
export CGO_ENABLED=1
4039
export PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig
41-
export LIBRARY_PATH=$(LIBGIT2_LIB_PATH)
42-
export CGO_CFLAGS=-I$(LIBGIT2_PATH)/include -I$(LIBGIT2_PATH)/include/openssl
43-
44-
45-
# The pkg-config command will yield warning messages until libgit2 is downloaded.
46-
ifeq ($(shell uname -s),Darwin)
47-
export CGO_LDFLAGS=$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs --static --cflags libssh2 openssl libgit2 2>/dev/null)
40+
export CGO_LDFLAGS=$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs --static --cflags libgit2 2>/dev/null)
4841
GO_STATIC_FLAGS=-ldflags "-s -w" -tags 'netgo,osusergo,static_build$(addprefix ,,$(GO_TAGS))'
49-
else
50-
export PKG_CONFIG_PATH:=$(PKG_CONFIG_PATH):$(LIBGIT2_LIB64_PATH)/pkgconfig
51-
export LIBRARY_PATH:=$(LIBRARY_PATH):$(LIBGIT2_LIB64_PATH)
52-
export CGO_LDFLAGS=$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs --static --cflags libssh2 openssl libgit2 2>/dev/null)
53-
endif
54-
5542

5643
ifeq ($(shell uname -s),Linux)
57-
ifeq ($(shell uname -m),x86_64)
58-
# Linux x86_64 seem to be able to cope with the static libraries
59-
# by having only musl-dev installed, without the need of using musl toolchain.
60-
GO_STATIC_FLAGS=-ldflags "-s -w" -tags 'netgo,osusergo,static_build$(addprefix ,,$(GO_TAGS))'
61-
else
44+
ifneq ($(shell uname -m),x86_64)
6245
MUSL-PREFIX=$(BUILD_DIR)/musl/$(shell uname -m)-linux-musl-native/bin/$(shell uname -m)-linux-musl
6346
MUSL-CC=$(MUSL-PREFIX)-gcc
6447
export CC=$(MUSL-PREFIX)-gcc

hack/install-libraries.sh

+9-8
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ extract_libraries(){
7474
}
7575

7676
fix_pkgconfigs(){
77-
DIR="$1"
7877
NEW_DIR="$(/bin/pwd)/build/libgit2/${TAG}"
7978

8079
# Update the prefix paths included in the .pc files.
8180
if [[ $OSTYPE == 'darwin'* ]]; then
82-
INSTALLED_DIR="/Users/runner/work/golang-with-libgit2/golang-with-libgit2/build/${DIR}"
81+
# https://github.com/fluxcd/golang-with-libgit2/blob/v0.1.4/.github/workflows/release.yaml#L158
82+
INSTALLED_DIR="/Users/runner/work/golang-with-libgit2/golang-with-libgit2/build/libgit2-darwin-amd64"
8383

8484
# This will make it easier to update to the location in which they will be used.
8585
# sed has a sight different behaviour in MacOS
@@ -90,7 +90,8 @@ fix_pkgconfigs(){
9090
find "${NEW_DIR}" -type f -name "*.pc" | xargs -I {} sed -i "" "s;${INSTALLED_DIR};${NEW_DIR};g" {}
9191
fi
9292
else
93-
INSTALLED_DIR="/home/runner/work/golang-with-libgit2/golang-with-libgit2/build/${DIR}"
93+
# https://github.com/fluxcd/golang-with-libgit2/blob/v0.1.4/.github/workflows/release.yaml#L52
94+
INSTALLED_DIR="/home/runner/work/golang-with-libgit2/golang-with-libgit2/build/build_libgit2_only"
9495

9596
find "${NEW_DIR}" -type f -name "*.pc" | xargs -I {} sed -i "s;${INSTALLED_DIR};${NEW_DIR};g" {}
9697
fi
@@ -136,17 +137,17 @@ install_libraries(){
136137
fi
137138
fi
138139

139-
FILE_NAME="linux-$(uname -m)-all-libs.tar.gz"
140-
DIR="libgit2-linux-all-libs"
140+
FILE_NAME="linux-x86_64-libgit2-only.tar.gz"
141+
DIR="linux-libgit2-only"
141142
if [[ $OSTYPE == 'darwin'* ]]; then
142-
FILE_NAME="darwin-all-libs.tar.gz"
143-
DIR="darwin-all-libs"
143+
FILE_NAME="darwin-libgit2-only.tar.gz"
144+
DIR="darwin-libgit2-only"
144145
fi
145146

146147
download_files "${FILE_NAME}"
147148
assure_provenance "${FILE_NAME}"
148149
extract_libraries "${FILE_NAME}" "${DIR}"
149-
fix_pkgconfigs "${DIR}"
150+
fix_pkgconfigs
150151
}
151152

152153
install_libraries

hack/update-attributions.sh

-48
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@ code of their open source projects along with license information below.
1212
We acknowledge and are grateful to these developers for their contributions
1313
to open source.
1414
15-
## libssh2
16-
17-
Libssh2 was obtained in source-code form from its github repository:
18-
https://github.com/libssh2/libssh2/
19-
20-
No changes were made to its original source code.
21-
22-
Copyright notice (https://raw.githubusercontent.com/libssh2/libssh2/master/COPYING):
23-
24-
$(curl --max-time 5 -L https://raw.githubusercontent.com/libssh2/libssh2/master/COPYING)
25-
26-
${SPLIT}
27-
2815
## libgit2
2916
3017
Libgit2 was obtained in source-code form from its github repository:
@@ -35,39 +22,4 @@ No changes were made to its original source code.
3522
Copyright notice (https://raw.githubusercontent.com/libgit2/libgit2/main/COPYING):
3623
3724
$(curl --max-time 5 -L https://raw.githubusercontent.com/libgit2/libgit2/main/COPYING)
38-
39-
${SPLIT}
40-
41-
## zlib
42-
43-
Zlib was obtained in binary form via official distribution channels.
44-
No changes were made to its original source code.
45-
46-
Copyright notice (https://zlib.net/zlib_license.html):
47-
48-
/* zlib.h -- interface of the 'zlib' general purpose compression library
49-
version 1.2.11, January 15th, 2017
50-
51-
Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
52-
53-
This software is provided 'as-is', without any express or implied
54-
warranty. In no event will the authors be held liable for any damages
55-
arising from the use of this software.
56-
57-
Permission is granted to anyone to use this software for any purpose,
58-
including commercial applications, and to alter it and redistribute it
59-
freely, subject to the following restrictions:
60-
61-
1. The origin of this software must not be misrepresented; you must not
62-
claim that you wrote the original software. If you use this software
63-
in a product, an acknowledgment in the product documentation would be
64-
appreciated but is not required.
65-
2. Altered source versions must be plainly marked as such, and must not be
66-
misrepresented as being the original software.
67-
3. This notice may not be removed or altered from any source distribution.
68-
69-
Jean-loup Gailly Mark Adler
70-
71-
72-
*/
7325
EOF

tests/fuzz/oss_fuzz_build.sh

+8-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
set -euxo pipefail
1818

19-
LIBGIT2_TAG="${LIBGIT2_TAG:-v0.1.2}"
19+
LIBGIT2_TAG="${LIBGIT2_TAG:-v0.1.4}"
2020
GOPATH="${GOPATH:-/root/go}"
2121
GO_SRC="${GOPATH}/src"
2222
PROJECT_PATH="github.com/fluxcd/source-controller"
@@ -28,9 +28,9 @@ export TARGET_DIR="$(/bin/pwd)/build/libgit2/${LIBGIT2_TAG}"
2828
# For most cases, libgit2 will already be present.
2929
# The exception being at the oss-fuzz integration.
3030
if [ ! -d "${TARGET_DIR}" ]; then
31-
curl -o output.tar.gz -LO "https://github.com/fluxcd/golang-with-libgit2/releases/download/${LIBGIT2_TAG}/linux-$(uname -m)-all-libs.tar.gz"
31+
curl -o output.tar.gz -LO "https://github.com/fluxcd/golang-with-libgit2/releases/download/${LIBGIT2_TAG}/linux-x86_64-libgit2-only.tar.gz"
3232

33-
DIR=libgit2-linux-all-libs
33+
DIR=linux-libgit2-only
3434
NEW_DIR="$(/bin/pwd)/build/libgit2/${LIBGIT2_TAG}"
3535
INSTALLED_DIR="/home/runner/work/golang-with-libgit2/golang-with-libgit2/build/${DIR}"
3636

@@ -49,10 +49,10 @@ fi
4949
apt-get update && apt-get install -y pkg-config
5050

5151
export CGO_ENABLED=1
52-
export LIBRARY_PATH="${TARGET_DIR}/lib:${TARGET_DIR}/lib64"
53-
export PKG_CONFIG_PATH="${TARGET_DIR}/lib/pkgconfig:${TARGET_DIR}/lib64/pkgconfig"
54-
export CGO_CFLAGS="-I${TARGET_DIR}/include -I${TARGET_DIR}/include/openssl"
55-
export CGO_LDFLAGS="$(pkg-config --libs --static --cflags libssh2 openssl libgit2)"
52+
export PKG_CONFIG_PATH="${TARGET_DIR}/lib/pkgconfig"
53+
export CGO_LDFLAGS="$(pkg-config --libs --static --cflags libgit2)"
54+
export LIBRARY_PATH="${TARGET_DIR}/lib"
55+
export CGO_CFLAGS="-I${TARGET_DIR}/include"
5656

5757
go get -d github.com/AdaLogics/go-fuzz-headers
5858

@@ -92,10 +92,7 @@ function go_compile(){
9292
else
9393
go-fuzz -tags gofuzz -func="${function}" -o "${fuzzer}.a" .
9494
${CXX} ${CXXFLAGS} ${LIB_FUZZING_ENGINE} -o "${OUT}/${fuzzer}" \
95-
"${fuzzer}.a" \
96-
"${TARGET_DIR}/lib/libgit2.a" "${TARGET_DIR}/lib/libssh2.a" \
97-
"${TARGET_DIR}/lib/libz.a" "${TARGET_DIR}/lib64/libssl.a" \
98-
"${TARGET_DIR}/lib64/libcrypto.a" \
95+
"${fuzzer}.a" "${TARGET_DIR}/lib/libgit2.a" \
9996
-fsanitize="${SANITIZER}"
10097
fi
10198
}

0 commit comments

Comments
 (0)