Skip to content

Commit b997563

Browse files
committed
chore: embed static files in debug builds
1 parent 3e6e1e6 commit b997563

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

scripts/build_go.sh

Lines changed: 11 additions & 1 deletion
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
@@ -122,6 +127,11 @@ if [[ "$agpl" == 1 ]]; then
122127
fi
123128
build_args+=(-ldflags "${ldflags[*]}")
124129

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

scripts/coder-dev.sh

Lines changed: 16 additions & 2 deletions
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)