Skip to content

Commit bd752a6

Browse files
authored
chore: embed static files in debug builds (#12449)
1 parent 3e6e1e6 commit bd752a6

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

scripts/build_go.sh

+15-3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ sign_darwin="${CODER_SIGN_DARWIN:-0}"
3838
output_path=""
3939
agpl="${CODER_BUILD_AGPL:-0}"
4040
boringcrypto=${CODER_BUILD_BORINGCRYPTO:-0}
41+
debug=0
4142

42-
args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin,boringcrypto -- "$@")"
43+
args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin,boringcrypto,debug -- "$@")"
4344
eval set -- "$args"
4445
while true; do
4546
case "$1" in
@@ -76,6 +77,10 @@ while true; do
7677
boringcrypto=1
7778
shift
7879
;;
80+
--debug)
81+
debug=1
82+
shift
83+
;;
7984
--)
8085
shift
8186
break
@@ -102,10 +107,12 @@ if [[ "$sign_darwin" == 1 ]]; then
102107
fi
103108

104109
ldflags=(
105-
-s
106-
-w
107110
-X "'github.com/coder/coder/v2/buildinfo.tag=$version'"
108111
)
112+
# Disable deubgger information if not building a binary for debuggers.
113+
if [[ "$debug" == 0 ]]; then
114+
ldflags+=(-s -w)
115+
fi
109116

110117
# We use ts_omit_aws here because on Linux it prevents Tailscale from importing
111118
# github.com/aws/aws-sdk-go-v2/aws, which adds 7 MB to the binary.
@@ -122,6 +129,11 @@ if [[ "$agpl" == 1 ]]; then
122129
fi
123130
build_args+=(-ldflags "${ldflags[*]}")
124131

132+
# Disable optimizations if building a binary for debuggers.
133+
if [[ "$debug" == 1 ]]; then
134+
build_args+=(-gcflags "all=-N -l")
135+
fi
136+
125137
# Compute default output path.
126138
if [[ "$output_path" == "" ]]; then
127139
mkdir -p "build"

scripts/coder-dev.sh

+16-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pushd "$PROJECT_ROOT"
3232
mkdir -p ./.coderv2
3333
CODER_DEV_BIN="$(realpath "$RELATIVE_BINARY_PATH")"
3434
CODER_DEV_DIR="$(realpath ./.coderv2)"
35+
CODER_DELVE_DEBUG_BIN=$(realpath "./build/coder_debug_${GOOS}_${GOARCH}")
3536
popd
3637

3738
case $BINARY_TYPE in
@@ -59,7 +60,20 @@ esac
5960
runcmd=("${CODER_DEV_BIN}")
6061
if [[ "${DEBUG_DELVE}" == 1 ]]; then
6162
set -x
62-
runcmd=(dlv debug --headless --continue --listen 127.0.0.1:12345 --accept-multiclient ./cmd/coder --)
63+
build_flags=(
64+
--os "$GOOS"
65+
--arch "$GOARCH"
66+
--output "$CODER_DELVE_DEBUG_BIN"
67+
--debug
68+
)
69+
if [[ "$BINARY_TYPE" == "coder-slim" ]]; then
70+
build_flags+=(--slim)
71+
fi
72+
# All the prerequisites should be built above when we refreshed the regular
73+
# binary, so we can just build the debug binary here without having to worry
74+
# about/use the makefile.
75+
./scripts/build_go.sh "${build_flags[@]}"
76+
runcmd=(dlv exec --headless --continue --listen 127.0.0.1:12345 --accept-multiclient "$CODER_DELVE_DEBUG_BIN" --)
6377
fi
6478

65-
CGO_ENABLED=0 exec "${runcmd[@]}" --global-config "${CODER_DEV_DIR}" "$@"
79+
exec "${runcmd[@]}" --global-config "${CODER_DEV_DIR}" "$@"

0 commit comments

Comments
 (0)