Skip to content

feat: add boringcrypto builds for linux #9528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ CODER_ARCH_IMAGE_PREREQUISITES := \
build/coder_$(VERSION)_%.tar.gz
endif

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

clean:
rm -rf build site/out
Expand Down Expand Up @@ -222,6 +225,12 @@ $(CODER_ALL_BINARIES): go.mod go.sum \
build_args+=(--slim)
fi

# boringcrypto is only supported on Linux
# boringcrypto uses CGO, which isn't supported when cross compiling architectures
if [[ "$$os" == "linux" ]] && [[ "${local_os}" == "linux" ]] && [[ "$$arch" == "${local_arch}" ]]; then
build_args+=(--boringcrypto)
fi

./scripts/build_go.sh "$${build_args[@]}"

if [[ "$$mode" == "slim" ]]; then
Expand Down
7 changes: 7 additions & 0 deletions buildinfo/boring.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build boringcrypto

package buildinfo

import "crypto/boring"

var boringcrypto = boring.Enabled()
4 changes: 4 additions & 0 deletions buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func IsAGPL() bool {
return strings.Contains(agpl, "t")
}

func IsBoringCrypto() bool {
return boringcrypto
}

// ExternalURL returns a URL referencing the current Coder version.
// For production builds, this will link directly to a release.
// For development builds, this will link to a commit.
Expand Down
5 changes: 5 additions & 0 deletions buildinfo/notboring.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build !boringcrypto

package buildinfo

var boringcrypto = false
25 changes: 15 additions & 10 deletions cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (
// versionInfo wraps the stuff we get from buildinfo so that it's
// easier to emit in different formats.
type versionInfo struct {
Version string `json:"version"`
BuildTime time.Time `json:"build_time"`
ExternalURL string `json:"external_url"`
Slim bool `json:"slim"`
AGPL bool `json:"agpl"`
Version string `json:"version"`
BuildTime time.Time `json:"build_time"`
ExternalURL string `json:"external_url"`
Slim bool `json:"slim"`
AGPL bool `json:"agpl"`
BoringCrypto bool `json:"boring_crypto"`
}

// String() implements Stringer
Expand All @@ -28,6 +29,9 @@ func (vi versionInfo) String() string {
_, _ = str.WriteString("(AGPL) ")
}
_, _ = str.WriteString(vi.Version)
if vi.BoringCrypto {
_, _ = str.WriteString(" BoringCrypto")
}

if !vi.BuildTime.IsZero() {
_, _ = str.WriteString(" " + vi.BuildTime.Format(time.UnixDate))
Expand All @@ -45,11 +49,12 @@ func (vi versionInfo) String() string {
func defaultVersionInfo() *versionInfo {
buildTime, _ := buildinfo.Time()
return &versionInfo{
Version: buildinfo.Version(),
BuildTime: buildTime,
ExternalURL: buildinfo.ExternalURL(),
Slim: buildinfo.IsSlim(),
AGPL: buildinfo.IsAGPL(),
Version: buildinfo.Version(),
BuildTime: buildTime,
ExternalURL: buildinfo.ExternalURL(),
Slim: buildinfo.IsSlim(),
AGPL: buildinfo.IsAGPL(),
BoringCrypto: buildinfo.IsBoringCrypto(),
}
}

Expand Down
22 changes: 19 additions & 3 deletions scripts/build_go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

set -euo pipefail
# shellcheck source=scripts/lib.sh
Expand All @@ -34,8 +37,9 @@ slim="${CODER_SLIM_BUILD:-0}"
sign_darwin="${CODER_SIGN_DARWIN:-0}"
output_path=""
agpl="${CODER_BUILD_AGPL:-0}"
boringcrypto=${CODER_BUILD_BORINGCRYPTO:-0}

args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin -- "$@")"
args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin,boringcrypto -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
Expand Down Expand Up @@ -68,6 +72,10 @@ while true; do
sign_darwin=1
shift
;;
--boringcrypto)
boringcrypto=1
shift
;;
--)
shift
break
Expand Down Expand Up @@ -140,7 +148,15 @@ cmd_path="./enterprise/cmd/coder"
if [[ "$agpl" == 1 ]]; then
cmd_path="./cmd/coder"
fi
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" GOARM="$arm_version" go build \

cgo=0
goexp=""
if [[ "$boringcrypto" == 1 ]]; then
cgo=1
goexp="boringcrypto"
fi

GOEXPERIMENT="$goexp" CGO_ENABLED="$cgo" GOOS="$os" GOARCH="$arch" GOARM="$arm_version" go build \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does -boringcrypto also need to be added to go build args?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, I tested coder version on a binary I built. GOEXPERIMENT=boringcrypto is enough.

"${build_args[@]}" \
"$cmd_path" 1>&2

Expand Down