Skip to content

Commit

Permalink
Migrate to static building to remove dependency to libgit2
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmeyer committed Jan 15, 2021
1 parent 35fbb5a commit 2cfe722
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 25 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up Go 1.15
uses: actions/setup-go@v2
Expand All @@ -20,41 +22,35 @@ jobs:
sudo apt-get update -y \
&& sudo apt-get install -y cmake pkg-config gcc libssh2-1-dev libssl-dev
- name: set up git2go for static mode
run: |
git clone https://github.com/libgit2/git2go
cd git2go/
git checkout release-1.1
git submodule update --init # get libgit2
make install-static
- name: get dependencies
run: |
go get -v -t -d ./...
bin/setup
- name: test
run: bin/test
env:
GO_TAGS: static

- name: build linux amd64
run: bin/build
env:
GOOS: linux
GOARCH: amd64
BUILD_TAGS: static
GO_TAGS: static

- name: build windows amd64
run: bin/build
env:
GOOS: windows
GOARCH: amd64
BUILD_TAGS: static
GO_TAGS: static

- name: build darwin amd64
run: bin/build
env:
GOOS: darwin
GOARCH: amd64
BUILD_TAGS: static
GO_TAGS: static

- name: package software for linux amd64
run: bin/package
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,42 @@ lg build -V
After building letters, you will find a directory called `letters` in the
current directory.
## Development
### Build letter-generator from its sources
~~~
bin/setup
bin/build
bin/test
~~~
### Central configuration file for helper scripts
Configuration for helper scripts is done via environment variables in [`env.sh`](env.sh).
### Upgrade git2go / libgit2
See https://github.com/libgit2/git2go#master-branch-or-vendored-static-linking
for more information about this.
If you plan to upgrade your version, you need to modify a few files.
1. Update version for "libgit2" in `env.sh`
~~~bash
: ${LIBGIT2_TAG:=release-1.1}
~~~
2. Update version of "git2go" in `go.mod`
~~~bash
# [...]
github.com/libgit2/git2go/v31 v31.4.7
# [...]
replace github.com/libgit2/git2go/v31 => ./ext_deps/git2go
~~~
## Copyright
(c) 2021, Dennis Günnewig
9 changes: 2 additions & 7 deletions bin/build
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#!/usr/bin/env bash

: ${GOOS:=linux}
: ${GOARCH:=amd64}
: ${GO_TAGS:=static,system_libgit2}
source ./env.sh

COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null)
BUILD_DATE=$(date +%FT%T%z)
VERSION=$(git tag | sort | tail -n 1)
VERSION=${VERSION/v/};
echo --- Build letter-generator

echo GO111MODULE=on CGO_ENABLED=1 go build --tags ${GO_TAGS} $* -ldflags "-w -s -X main.AppVersionNumber=${VERSION} -X main.CommitHash=${COMMIT_HASH} -X main.BuildDate=${BUILD_DATE}" -o dist/${GOOS}/${GOARCH}/lg ./cmd/lg
GO111MODULE=on CGO_ENABLED=1 go build --tags ${GO_TAGS} $* -ldflags "-w -s -X main.AppVersionNumber=${VERSION} -X main.CommitHash=${COMMIT_HASH} -X main.BuildDate=${BUILD_DATE}" -o dist/${GOOS}/${GOARCH}/lg ./cmd/lg
14 changes: 13 additions & 1 deletion bin/setup
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#!/bin/bash

echo install libgit2
source ./env.sh

echo --- Build static git2go

git submodule update --init # get git2go
cd ext_deps/git2go
git checkout ${LIBGIT2_TAG}
git submodule update --init # get libgit2
make install-static
cd -

echo
echo --- Install dependencies
echo go get -d -v ./...
go get -d -v ./...
5 changes: 3 additions & 2 deletions bin/test
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env sh
#!/usr/bin/env bash

: ${GO_TAGS:=static,system_libgit2}
source ./env.sh

echo --- Test letter-generator
go test --tags ${GO_TAGS} -v ./... $*
9 changes: 9 additions & 0 deletions env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
: ${GOOS:=linux}
: ${GOARCH:=amd64}
: ${GO_TAGS:=static}
: ${LIBGIT2_TAG:=release-1.1}

: ${COMMIT_HASH:=$(git rev-parse --short HEAD 2>/dev/null)}
: ${BUILD_DATE:=$(date +%FT%T%z)}
: ${VERSION:=$(git tag | sort | tail -n 1)}
: ${VERSION:=${VERSION/v/}}
2 changes: 1 addition & 1 deletion ext_deps/git2go
Submodule git2go updated 75 files
+1 −1 .github/workflows/backport.yml
+6 −13 .github/workflows/ci.yml
+0 −5 .travis.yml
+0 −14 Build_system_dynamic.go
+0 −14 Build_system_static.go
+3 −5 Makefile
+0 −2 blame.go
+30 −3 blob.go
+1 −1 branch.go
+2 −2 branch_test.go
+70 −101 checkout.go
+16 −21 cherrypick.go
+1 −1 cherrypick_test.go
+40 −63 clone.go
+2 −3 clone_test.go
+35 −163 credentials.go
+0 −184 deprecated.go
+174 −236 diff.go
+23 −18 diff_test.go
+0 −63 errorclass_string.go
+0 −69 errorcode_string.go
+2 −2 features.go
+96 −114 git.go
+2 −2 git_bundled_static.go
+14 −0 git_system_dynamic.go
+14 −0 git_system_static.go
+5 −25 git_test.go
+1 −5 go.mod
+3 −9 go.sum
+20 −61 index.go
+14 −11 indexer.go
+1 −1 indexer_test.go
+1 −1 mempack_test.go
+35 −123 merge.go
+0 −61 merge_test.go
+1 −1 note_test.go
+8 −8 object.go
+6 −6 object_test.go
+29 −25 odb.go
+1 −1 odb_test.go
+17 −18 packbuilder.go
+4 −9 patch.go
+2 −5 push_test.go
+43 −85 rebase.go
+15 −15 rebase_test.go
+11 −50 reference.go
+2 −25 reference_test.go
+142 −283 remote.go
+8 −295 remote_test.go
+1 −10 repository.go
+2 −9 reset.go
+1 −1 reset_test.go
+31 −34 revert.go
+2 −13 script/build-libgit2.sh
+0 −8 settings.go
+1 −9 settings_test.go
+70 −64 stash.go
+2 −2 stash_test.go
+20 −51 submodule.go
+20 −20 tag.go
+0 −1 testdata/TestGitRepository.git/HEAD
+0 −6 testdata/TestGitRepository.git/config
+0 −1 testdata/TestGitRepository.git/description
+0 −6 testdata/TestGitRepository.git/info/exclude
+0 −8 testdata/TestGitRepository.git/info/refs
+ testdata/TestGitRepository.git/objects/info/commit-graph
+0 −2 testdata/TestGitRepository.git/objects/info/packs
+ testdata/TestGitRepository.git/objects/pack/pack-ccace4e169a0858c13d9ae781a91d76fc33769b8.bitmap
+ testdata/TestGitRepository.git/objects/pack/pack-ccace4e169a0858c13d9ae781a91d76fc33769b8.idx
+ testdata/TestGitRepository.git/objects/pack/pack-ccace4e169a0858c13d9ae781a91d76fc33769b8.pack
+0 −9 testdata/TestGitRepository.git/packed-refs
+0 −1 testdata/TestGitRepository.git/refs/heads/master
+16 −30 tree.go
+1 −1 walk.go
+79 −358 wrapper.c
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/feduxorg/letter-generator

go 1.12

//replace github.com/libgit2/git2go => github.com/maxmeyer/git2go v0.28.4

require (
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/libgit2/git2go/v31 v31.4.7
Expand All @@ -17,3 +15,5 @@ require (
golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78 // indirect
gopkg.in/yaml.v2 v2.4.0
)

replace github.com/libgit2/git2go/v31 => ./ext_deps/git2go
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c h1:9HhBz5L/UjnK9XLtiZhYAdue5BVKep3PMmS2LuPDt8k=
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
Expand All @@ -54,6 +55,7 @@ golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
Expand Down

0 comments on commit 2cfe722

Please sign in to comment.