Skip to content

Commit

Permalink
fix: make sure CGO_ENABLED is normally off, fixes ddev#6046 (ddev#6050)…
Browse files Browse the repository at this point in the history
… [skip ci]
  • Loading branch information
rfay authored Apr 4, 2024
1 parent be88fdc commit bfbba3e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/master-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ jobs:
if: steps.notarizedmac.outputs.cache-hit != 'true'
run: exit 1

- name: "Verify that cgo_enabled is 0 in Linux binary"
run: |
.gotmp/bin/$(go env GOOS)_$(go env GOARCH)/ddev version
cgo=$(".gotmp/bin/$(go env GOOS)_$(go env GOARCH)/ddev" version 2>/dev/null | awk '/cgo_enabled/ {print $2}')
if [ "${cgo}" != "0" ]; then echo "CGO_ENABLED=${cgo} but it must be 0 in released binary" && exit 10; fi
# Goreleaser does GitHub release artifacts, homebrew, AUR, deb/rpm
- name: goreleaser
uses: goreleaser/goreleaser-action@v5
Expand All @@ -230,6 +236,7 @@ jobs:
version: latest
args: release --clean
env:
CGO_ENABLED: 0
DOCKER_ORG: ddev
GITHUB_TOKEN: ${{ secrets.DDEV_GITHUB_TOKEN }}
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ jobs:
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}

- name: DDEV tests
run: make CGO_ENABLED="${CGO_ENABLED}" BUILDARGS="${BUILDARGS}" TESTARGS="${TESTARGS}" ${MAKE_TARGET}
run: |
make CGO_ENABLED="${CGO_ENABLED}" BUILDARGS="${BUILDARGS}"
cgo=$(.gotmp/bin/$(go env GOOS)_$(go env GOARCH)/ddev version 2>/dev/null | awk '/cgo_enabled/ { print $2 }')
if [ "${CGO_ENABLED}" != "${cgo}" ]; then
echo "CGO_ENABLED=${CGO_ENABLED} but built cgo=${cgo}" && exit 5
fi
make CGO_ENABLED="${CGO_ENABLED}" BUILDARGS="${BUILDARGS}" TESTARGS="${TESTARGS}" ${MAKE_TARGET}
- name: Clean up Homebrew
continue-on-error: true
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ $(TARGETS): mkcert $(GOFILES)
@#echo "LDFLAGS=$(LDFLAGS)";
@rm -f $@
@export TARGET=$(word 3, $(subst /, ,$@)) && \
export GOOS="$${TARGET%_*}" GOARCH="$${TARGET#*_}" GOPATH="$(PWD)/$(GOTMP)" GOCACHE="$(PWD)/$(GOTMP)/.cache" && \
export CGO_ENABLED=$(CGO_ENABLED) GOOS="$${TARGET%_*}" GOARCH="$${TARGET#*_}" GOPATH="$(PWD)/$(GOTMP)" GOCACHE="$(PWD)/$(GOTMP)/.cache" && \
mkdir -p $(GOTMP)/{.cache,pkg,src,bin/$$TARGET} && \
chmod 777 $(GOTMP)/{.cache,pkg,src,bin/$$TARGET} && \
go build -o $(GOTMP)/bin/$$TARGET -installsuffix static $(BUILDARGS) -ldflags " $(LDFLAGS) " $(SRC_AND_UNDER)
Expand Down
2 changes: 2 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os/exec"
"runtime"
"strconv"
"strings"

"github.com/ddev/ddev/pkg/docker"
Expand All @@ -24,6 +25,7 @@ func GetVersionInfo() map[string]string {
versionInfo := make(map[string]string)

versionInfo["DDEV version"] = versionconstants.DdevVersion
versionInfo["cgo_enabled"] = strconv.FormatInt(versionconstants.CGOEnabled, 10)
versionInfo["web"] = docker.GetWebImage()
versionInfo["db"] = docker.GetDBImage(nodeps.MariaDB, "")
versionInfo["router"] = docker.GetRouterImage()
Expand Down
5 changes: 5 additions & 0 deletions pkg/versionconstants/cgo_false.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build !cgo

package versionconstants

const CGOEnabled = 0
5 changes: 5 additions & 0 deletions pkg/versionconstants/cgo_true.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build cgo

package versionconstants

const CGOEnabled = 1

0 comments on commit bfbba3e

Please sign in to comment.