Skip to content

Commit 79cd604

Browse files
authored
feat: add boringcrypto builds for linux (#9528)
* feat: add boringcrypto builds for linux Signed-off-by: Spike Curtis <spike@coder.com> * strip debug symbols, add BoringCryto to buildinfo Signed-off-by: Spike Curtis <spike@coder.com> * Fix TestVersion Signed-off-by: Spike Curtis <spike@coder.com> --------- Signed-off-by: Spike Curtis <spike@coder.com>
1 parent ce08c47 commit 79cd604

File tree

7 files changed

+61
-14
lines changed

7 files changed

+61
-14
lines changed

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ CODER_ARCH_IMAGE_PREREQUISITES := \
105105
build/coder_$(VERSION)_%.tar.gz
106106
endif
107107

108+
# used to decide if we can build with boringcrypto
109+
local_os:=$(shell go env GOHOSTOS)
110+
local_arch:=$(shell go env GOHOSTARCH)
108111

109112
clean:
110113
rm -rf build site/out
@@ -222,6 +225,12 @@ $(CODER_ALL_BINARIES): go.mod go.sum \
222225
build_args+=(--slim)
223226
fi
224227

228+
# boringcrypto is only supported on Linux
229+
# boringcrypto uses CGO, which isn't supported when cross compiling architectures
230+
if [[ "$$os" == "linux" ]] && [[ "${local_os}" == "linux" ]] && [[ "$$arch" == "${local_arch}" ]]; then
231+
build_args+=(--boringcrypto)
232+
fi
233+
225234
./scripts/build_go.sh "$${build_args[@]}"
226235

227236
if [[ "$$mode" == "slim" ]]; then

buildinfo/boring.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build boringcrypto
2+
3+
package buildinfo
4+
5+
import "crypto/boring"
6+
7+
var boringcrypto = boring.Enabled()

buildinfo/buildinfo.go

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ func IsAGPL() bool {
8787
return strings.Contains(agpl, "t")
8888
}
8989

90+
func IsBoringCrypto() bool {
91+
return boringcrypto
92+
}
93+
9094
// ExternalURL returns a URL referencing the current Coder version.
9195
// For production builds, this will link directly to a release.
9296
// For development builds, this will link to a commit.

buildinfo/notboring.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build !boringcrypto
2+
3+
package buildinfo
4+
5+
var boringcrypto = false

cli/version.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import (
1313
// versionInfo wraps the stuff we get from buildinfo so that it's
1414
// easier to emit in different formats.
1515
type versionInfo struct {
16-
Version string `json:"version"`
17-
BuildTime time.Time `json:"build_time"`
18-
ExternalURL string `json:"external_url"`
19-
Slim bool `json:"slim"`
20-
AGPL bool `json:"agpl"`
16+
Version string `json:"version"`
17+
BuildTime time.Time `json:"build_time"`
18+
ExternalURL string `json:"external_url"`
19+
Slim bool `json:"slim"`
20+
AGPL bool `json:"agpl"`
21+
BoringCrypto bool `json:"boring_crypto"`
2122
}
2223

2324
// String() implements Stringer
@@ -28,6 +29,9 @@ func (vi versionInfo) String() string {
2829
_, _ = str.WriteString("(AGPL) ")
2930
}
3031
_, _ = str.WriteString(vi.Version)
32+
if vi.BoringCrypto {
33+
_, _ = str.WriteString(" BoringCrypto")
34+
}
3135

3236
if !vi.BuildTime.IsZero() {
3337
_, _ = str.WriteString(" " + vi.BuildTime.Format(time.UnixDate))
@@ -45,11 +49,12 @@ func (vi versionInfo) String() string {
4549
func defaultVersionInfo() *versionInfo {
4650
buildTime, _ := buildinfo.Time()
4751
return &versionInfo{
48-
Version: buildinfo.Version(),
49-
BuildTime: buildTime,
50-
ExternalURL: buildinfo.ExternalURL(),
51-
Slim: buildinfo.IsSlim(),
52-
AGPL: buildinfo.IsAGPL(),
52+
Version: buildinfo.Version(),
53+
BuildTime: buildTime,
54+
ExternalURL: buildinfo.ExternalURL(),
55+
Slim: buildinfo.IsSlim(),
56+
AGPL: buildinfo.IsAGPL(),
57+
BoringCrypto: buildinfo.IsBoringCrypto(),
5358
}
5459
}
5560

cli/version_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Full build of Coder, supports the  server  subcomm
3434
"build_time": "0001-01-01T00:00:00Z",
3535
"external_url": "https://github.com/coder/coder",
3636
"slim": false,
37-
"agpl": false
37+
"agpl": false,
38+
"boring_crypto": false
3839
}
3940
`
4041
for _, tt := range []struct {

scripts/build_go.sh

+19-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# This script builds a single Go binary of Coder with the given parameters.
44
#
5-
# Usage: ./build_go.sh [--version 1.2.3-devel+abcdef] [--os linux] [--arch amd64] [--output path/to/output] [--slim] [--agpl]
5+
# Usage: ./build_go.sh [--version 1.2.3-devel+abcdef] [--os linux] [--arch amd64] [--output path/to/output] [--slim] [--agpl] [--boringcrypto]
66
#
77
# Defaults to linux:amd64 with slim disabled, but can be controlled with GOOS,
88
# GOARCH and CODER_SLIM_BUILD=1. If no version is specified, defaults to the
@@ -22,6 +22,9 @@
2222
#
2323
# If the --agpl parameter is specified, builds only the AGPL-licensed code (no
2424
# Coder enterprise features).
25+
#
26+
# If the --boringcrypto parameter is specified, builds use boringcrypto instead of
27+
# the standard go crypto libraries.
2528

2629
set -euo pipefail
2730
# shellcheck source=scripts/lib.sh
@@ -34,8 +37,9 @@ slim="${CODER_SLIM_BUILD:-0}"
3437
sign_darwin="${CODER_SIGN_DARWIN:-0}"
3538
output_path=""
3639
agpl="${CODER_BUILD_AGPL:-0}"
40+
boringcrypto=${CODER_BUILD_BORINGCRYPTO:-0}
3741

38-
args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin -- "$@")"
42+
args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin,boringcrypto -- "$@")"
3943
eval set -- "$args"
4044
while true; do
4145
case "$1" in
@@ -68,6 +72,10 @@ while true; do
6872
sign_darwin=1
6973
shift
7074
;;
75+
--boringcrypto)
76+
boringcrypto=1
77+
shift
78+
;;
7179
--)
7280
shift
7381
break
@@ -140,7 +148,15 @@ cmd_path="./enterprise/cmd/coder"
140148
if [[ "$agpl" == 1 ]]; then
141149
cmd_path="./cmd/coder"
142150
fi
143-
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" GOARM="$arm_version" go build \
151+
152+
cgo=0
153+
goexp=""
154+
if [[ "$boringcrypto" == 1 ]]; then
155+
cgo=1
156+
goexp="boringcrypto"
157+
fi
158+
159+
GOEXPERIMENT="$goexp" CGO_ENABLED="$cgo" GOOS="$os" GOARCH="$arch" GOARM="$arm_version" go build \
144160
"${build_args[@]}" \
145161
"$cmd_path" 1>&2
146162

0 commit comments

Comments
 (0)