Skip to content

chore: embed static files in debug builds #12449

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 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 15 additions & 3 deletions scripts/build_go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ sign_darwin="${CODER_SIGN_DARWIN:-0}"
output_path=""
agpl="${CODER_BUILD_AGPL:-0}"
boringcrypto=${CODER_BUILD_BORINGCRYPTO:-0}
debug=0

args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin,boringcrypto -- "$@")"
args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin,boringcrypto,debug -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
Expand Down Expand Up @@ -76,6 +77,10 @@ while true; do
boringcrypto=1
shift
;;
--debug)
debug=1
shift
;;
--)
shift
break
Expand All @@ -102,10 +107,12 @@ if [[ "$sign_darwin" == 1 ]]; then
fi

ldflags=(
-s
-w
-X "'github.com/coder/coder/v2/buildinfo.tag=$version'"
)
# Disable deubgger information if not building a binary for debuggers.
if [[ "$debug" == 0 ]]; then
ldflags+=(-s -w)
fi

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

# Disable optimizations if building a binary for debuggers.
if [[ "$debug" == 1 ]]; then
build_args+=(-gcflags "all=-N -l")
fi

# Compute default output path.
if [[ "$output_path" == "" ]]; then
mkdir -p "build"
Expand Down
18 changes: 16 additions & 2 deletions scripts/coder-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pushd "$PROJECT_ROOT"
mkdir -p ./.coderv2
CODER_DEV_BIN="$(realpath "$RELATIVE_BINARY_PATH")"
CODER_DEV_DIR="$(realpath ./.coderv2)"
CODER_DELVE_DEBUG_BIN=$(realpath "./build/coder_debug_${GOOS}_${GOARCH}")
popd

case $BINARY_TYPE in
Expand Down Expand Up @@ -59,7 +60,20 @@ esac
runcmd=("${CODER_DEV_BIN}")
if [[ "${DEBUG_DELVE}" == 1 ]]; then
set -x
runcmd=(dlv debug --headless --continue --listen 127.0.0.1:12345 --accept-multiclient ./cmd/coder --)
build_flags=(
--os "$GOOS"
--arch "$GOARCH"
--output "$CODER_DELVE_DEBUG_BIN"
--debug
)
if [[ "$BINARY_TYPE" == "coder-slim" ]]; then
build_flags+=(--slim)
fi
# All the prerequisites should be built above when we refreshed the regular
# binary, so we can just build the debug binary here without having to worry
# about/use the makefile.
./scripts/build_go.sh "${build_flags[@]}"
runcmd=(dlv exec --headless --continue --listen 127.0.0.1:12345 --accept-multiclient "$CODER_DELVE_DEBUG_BIN" --)
fi

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