buildout.cfg 5.41 KB
Newer Older
Kirill Smelkov's avatar
Kirill Smelkov committed
1 2
# Go language - https://golang.org/
[buildout]
3 4
extends =
  ../findutils/buildout.cfg
5
  ../gcc/buildout.cfg
6
  ../git/buildout.cfg
7
  ../pkgconfig/buildout.cfg
8
  ./buildout.hash.cfg
9

Kirill Smelkov's avatar
Kirill Smelkov committed
10
parts = gowork go
Kirill Smelkov's avatar
Kirill Smelkov committed
11

12
# ---- Go builds itself ----
Kirill Smelkov's avatar
Kirill Smelkov committed
13 14 15

[golang-common]
recipe = slapos.recipe.cmmi
16
shared = true
Kirill Smelkov's avatar
Kirill Smelkov committed
17
configure-command = :
18
location = @@LOCATION@@
Kirill Smelkov's avatar
Kirill Smelkov committed
19
make-binary =
20
make-targets= cd src && unset GOBIN && ./all.bash && cp -alf .. ${:location}
21 22
# some testdata files have an issue with slapos.extension.strip.
post-install = ${findutils:location}/bin/find ${:location}/src -type d -name testdata -exec rm -rf {} \; || true
Kirill Smelkov's avatar
Kirill Smelkov committed
23 24 25 26 27 28
environment =
  GOROOT_FINAL=${:location}
  ${:environment-extra}

[golang14]
<= golang-common
29 30 31
# https://golang.org/doc/install/source#bootstrapFromSource
url = https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz
md5sum = dbf727a4b0e365bf88d97cbfde590016
Kirill Smelkov's avatar
Kirill Smelkov committed
32
environment-extra =
33
make-targets= cd src && unset GOBIN && ./make.bash && cp -alf .. ${:location}
Kirill Smelkov's avatar
Kirill Smelkov committed
34 35


36 37
[golang1.12]
<= golang-common
38 39
url = https://golang.org/dl/go1.12.17.src.tar.gz
md5sum = 6b607fc795391dc609ffd79ebf41f080
40

41
# go1.12 needs go1.4 to bootstrap
Kirill Smelkov's avatar
Kirill Smelkov committed
42 43 44
environment-extra =
  GOROOT_BOOTSTRAP=${golang14:location}

Kirill Smelkov's avatar
Kirill Smelkov committed
45 46
[golang1.15]
<= golang-common
47 48
url = https://golang.org/dl/go1.15.10.src.tar.gz
md5sum = 898a4aea4bf5d4adc924154e347acfa3
Kirill Smelkov's avatar
Kirill Smelkov committed
49 50 51 52 53

# go1.15 needs go1.4 to bootstrap
environment-extra =
  GOROOT_BOOTSTRAP=${golang14:location}

Kirill Smelkov's avatar
Kirill Smelkov committed
54 55
[golang1.16]
<= golang-common
56 57
url = https://golang.org/dl/go1.16.2.src.tar.gz
md5sum = 516f63e11c64b1984045c035d4c2f65d
Kirill Smelkov's avatar
Kirill Smelkov committed
58 59 60 61 62

# go1.16 needs go1.4 to bootstrap
environment-extra =
  GOROOT_BOOTSTRAP=${golang14:location}

Kirill Smelkov's avatar
Kirill Smelkov committed
63

64 65
# ---- infrastructure to build Go workspaces / projects ----

66
# gowork is the top-level section that defines Go workspace.
67
#
68 69 70
# It specifies global settings that are used to build Go programs:
#
# - Go toolchain to use, e.g.
71 72
#
#   [gowork]
73
#   golang = ${golang1.15:location}
74
#
75 76
# - For Cgo support pkg-config is made pre-available by gowork, and users
#   should list paths where to search for pkg-config files, e.g. this way:
77 78 79 80 81 82
#
#   [gowork]
#   cpkgpath =
#       ${sqlite3:location}/lib/pkgconfig
#       ${zlib:location}/lib/pkgconfig
#
83
# - It is also possible to specify Go build flags used for compilation e.g. this way:
84 85 86
#
#   [gowork]
#   buildflags = -race
Kirill Smelkov's avatar
Kirill Smelkov committed
87
#
88 89 90 91 92 93 94
# - If some environment variables are needed during the build, they can be
#   added with environment option, e.g. this way:
#
#   [gowork]
#   environment =
#     CGO_ENABLED = 1
#     FOO = bar
95
#
96 97
# Users can also add `install` field to [gowork] to request Go programs to be
# automatically installed, for example:
98 99 100
#
#   [gowork]
#   install =
101 102 103
#       lab.nexedi.com/kirr/neo/go/...@v0.0.0-20210103165133-f3effa6c535f
#       golang.org/x/tools/gopls@v0.4.3
#       ${helloweb:location}/go:./...
104 105
#
#
Kirill Smelkov's avatar
Kirill Smelkov committed
106 107 108 109 110 111 112 113 114 115 116
# ${go:exe} is standalone executable that runs go in activated gowork environment.
[go]
recipe  = slapos.recipe.template:jinja2
exe     = ${buildout:bin-directory}/go
rendered= ${:exe}
mode    = 755
template= inline:
  #!/bin/sh -e
  . ${gowork:env.sh}
  exec go "$@"

117
[gowork]
118 119 120
directory = ${gowork.dir:directory}
src	= ${gowork.dir:src}
bin	= ${gowork.dir:bin}
121 122 123
depends = ${gowork.goinstall:recipe}

# go version used for the workspace (possible to override in applications)
124
golang  = ${golang1.16:location}
125

126 127 128
# no special build flags by default
buildflags =

129 130 131
# empty pkg-config path by default
cpkgpath =

132 133 134
# by default don't `go install` anything
install =

135 136 137
# empty key=value environment by default
environment =

138 139 140 141 142 143 144 145 146
# everything is done by dependent parts
recipe  = plone.recipe.command
command = :

# env.sh for compiling and running go programs
env.sh  = ${gowork-env.sh:output}

[gowork-env.sh]
recipe	= slapos.recipe.template
147
url     = ${:_profile_base_location_}/${:filename}
148 149
output	= ${gowork.dir:directory}/env.sh
depends = ${gowork.dir:recipe}
150

151 152 153 154
[gowork.dir]
directory = ${buildout:directory}/go.work
src	= ${:directory}/src
bin	= ${:directory}/bin
155 156 157 158
# NOTE do not use slapos.cookbook:mkdirectory here - if anything in software (not instance)
# uses slapos.cookbook:* in recipe - slapos.cookbook will get compiled against system
# libxml/libxslt or fail to bootstrap at all if those are not present.
recipe  = plone.recipe.command
159
command = mkdir -p ${:directory}
160 161 162
update-command = ${:command}
stop-on-error = true

163 164
# install go programs
# clients can put program list to install to gowork:install
165 166
[gowork.goinstall]
recipe  = plone.recipe.command
167 168
command = bash -c ". ${gowork:env.sh}
	set -e
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
	for x in $(echo -n '${gowork:install}' |tr '\n' ' '); do
		case "\$x" in

		# external module, e.g. golang.org/x/tools/gopls@v0.4.3
		*@*)
			echo GOMOD \$x
			GO111MODULE=on go install ${gowork:buildflags} -v \$x
			;;

		# locally-cloned module source, e.g. <module-src-location>:./...
		*:*)
			echo GOMODSRC \$x
			dir=\"\$${x%%:*}\"
			arg=\"\$${x#*:}\"
			(cd \$dir && GO111MODULE=on go install ${gowork:buildflags} -v \$arg)
			;;

		# non-module
		*)
			echo GOPKG \$x
			GO111MODULE=off go install ${gowork:buildflags} -v \$x
			;;
		esac
	done
	"
194 195 196 197 198 199 200 201 202 203 204 205 206 207
update-command = ${:command}
stop-on-error = true


[git-repository]
recipe  = slapos.recipe.build:gitclone
git-executable = ${git:location}/bin/git

# a go package should:
# 1) <= go-git-package
# 2) provide go.importpath
# 3) provide repository (which is not the same as importpath in general case)
#
# the list of go packages for a go workspace state can be automatically
208
# generated with the help of gowork-snapshot tool.
209 210
[go-git-package]
<= git-repository
211
location = ${gowork.dir:src}/${:go.importpath}