Skip to content

Commit 4c0de11

Browse files
authored
feat: allow CGO_ENABLED to be configurable for development (#676)
1 parent 79d5be6 commit 4c0de11

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

manifest.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ arguments:
88
description: "Use non-deprecated protobuf modules for Go"
99
schema:
1010
type: boolean
11+
enableCgo:
12+
description: "Enables compiling Go binaries with cgo."
13+
schema:
14+
type: boolean

root/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ TAGS :=
2828
BINDIR := $(CURDIR)/bin
2929
BIN_NAME := $(APP)
3030
PKGDIR := github.com/$(ORG)/$(APP)
31-
CGO_ENABLED ?= 1
31+
CGO_ENABLED ?= $(shell "$(CURDIR)/scripts/shell-wrapper.sh cgo-enabled.sh")
3232
TOOL_DEPS := ${GO}
3333

3434
# formatters / misc
@@ -177,13 +177,13 @@ run:: pre-run build
177177
## devspace-watch: watch source files and build them for linux. To be used with devspace using `devenv apps run --sync-binaries .`
178178
.PHONY: devspace-watch
179179
devspace-watch:
180-
@DEVBOX_LOGFMT="$(LOGFMT)" BUILD_FOR_GOOS="linux" CGO_ENABLED=0 SKIP_TRIMPATH="true" SKIP_STARTING_APP="true" DLV_PORT=42097 $(AIR)
180+
@DEVBOX_LOGFMT="$(LOGFMT)" BUILD_FOR_GOOS="linux" CGO_ENABLED=$(CGO_ENABLED) SKIP_TRIMPATH="true" SKIP_STARTING_APP="true" DLV_PORT=42097 $(AIR)
181181

182182
## devspace: build sources for linux with debugging symbols. To be used with devspace using `devenv apps run --sync-binaries .`
183183
.PHONY: devspace
184184
devspace:
185-
@DEVBOX_LOGFMT="$(LOGFMT)" BUILD_FOR_GOOS="linux" CGO_ENABLED=0 SKIP_TRIMPATH="true" SKIP_STARTING_APP="true" DLV_PORT=42097 $(MAGE_CMD) gobuild
186-
@DEVBOX_LOGFMT="$(LOGFMT)" BUILD_FOR_GOOS="linux" CGO_ENABLED=0 $(MAGE_CMD) e2etestbuild
185+
@DEVBOX_LOGFMT="$(LOGFMT)" BUILD_FOR_GOOS="linux" CGO_ENABLED=$(CGO_ENABLED) SKIP_TRIMPATH="true" SKIP_STARTING_APP="true" DLV_PORT=42097 $(MAGE_CMD) gobuild
186+
@DEVBOX_LOGFMT="$(LOGFMT)" BUILD_FOR_GOOS="linux" CGO_ENABLED=$(CGO_ENABLED) $(MAGE_CMD) e2etestbuild
187187
@echo "Use 'devenv apps run --sync-binaries .' to sync binaries to devspace pod"
188188

189189
## dev: run the service

shell/cgo-enabled.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
# This is a small script to determine whether a service manifest has
3+
# explicitly enabled compiling with CGo, and print out the appropriate
4+
# value for the CGO_ENABLED environment variable. Defaults to disabled.
5+
6+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
7+
# shellcheck source=./lib/bootstrap.sh
8+
source "$DIR/lib/bootstrap.sh"
9+
10+
if [[ "$(yq -r ".arguments.enableCgo" <"$(get_service_yaml)")" == "true" ]]; then
11+
echo "1"
12+
else
13+
echo "0"
14+
fi

0 commit comments

Comments
 (0)