aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-containers/docker/files/0001-dynbinary-use-go-cross-compiler.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-containers/docker/files/0001-dynbinary-use-go-cross-compiler.patch')
-rw-r--r--recipes-containers/docker/files/0001-dynbinary-use-go-cross-compiler.patch111
1 files changed, 111 insertions, 0 deletions
diff --git a/recipes-containers/docker/files/0001-dynbinary-use-go-cross-compiler.patch b/recipes-containers/docker/files/0001-dynbinary-use-go-cross-compiler.patch
new file mode 100644
index 00000000..160a3bca
--- /dev/null
+++ b/recipes-containers/docker/files/0001-dynbinary-use-go-cross-compiler.patch
@@ -0,0 +1,111 @@
+From 3ce6089417b8c6c4e8279e6ef60213436ebf8793 Mon Sep 17 00:00:00 2001
+From: Bruce Ashfield <bruce.ashfield@gmail.com>
+Date: Tue, 30 Jun 2020 22:23:33 -0400
+Subject: [PATCH] dynbinary: use go cross compiler
+
+MJ: use ${GO} also in "go env" calls, because native go:
+ $ go env GOARM
+ 5
+while go cross compiler for my target:
+ $ ${GO} env GOARM
+ 7
+this can lead to:
+ error: switch '-mcpu=cortex-a9' conflicts with switch '-march=armv5t' [-Werror]
+
+but even after fixing it to use "better" -march it still doesn't match with -mcpu
+set in our GOBUILDFLAGS, causing e.g.:
+ error: switch '-mcpu=cortex-a9' conflicts with switch '-march=armv7-a+simd' [-Werror]
+
+so drop CGO_CFLAGS/CGO_CXXFLAGS as in OE builds we don't need them
+as long as ${GO} and GOBUILDFLAGS are respected
+
+it was added in:
+https://github.com/moby/moby/commit/12558c8d6ea9f388b54eb94ba6b9eb4a9fc5c9f2
+
+and it wasn't an issue before:
+https://github.com/moby/moby/commit/8c12a6648b368cc2acaea0339d6c57c920ed265c
+
+because it was using 'case "${GOARM}" in' and ${GOARM} was empty in our builds
+
+Upstream-Status: Inappropriate [embedded specific]
+
+Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
+Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
+---
+ hack/make/.binary | 37 ++++++++-----------------------------
+ 1 file changed, 8 insertions(+), 29 deletions(-)
+
+Index: import/hack/make/.binary
+===================================================================
+--- import.orig/hack/make/.binary
++++ import/hack/make/.binary
+@@ -3,7 +3,7 @@
+
+ # a helper to provide ".exe" when it's appropriate
+ binary_extension() {
+- if [ "$(go env GOOS)" = 'windows' ]; then
++ if [ "$(${GO} env GOOS)" = 'windows' ]; then
+ echo -n '.exe'
+ fi
+ }
+@@ -16,33 +16,12 @@
+ (
+ export GOGC=${DOCKER_BUILD_GOGC:-1000}
+
+- if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then
+- # must be cross-compiling!
+- if [ "$(go env GOOS)/$(go env GOARCH)" = "linux/arm" ]; then
+- # specify name of the target ARM architecture
+- case "$(go env GOARM)" in
+- 5)
+- export CGO_CFLAGS="-march=armv5t"
+- export CGO_CXXFLAGS="-march=armv5t"
+- ;;
+- 6)
+- export CGO_CFLAGS="-march=armv6"
+- export CGO_CXXFLAGS="-march=armv6"
+- ;;
+- 7)
+- export CGO_CFLAGS="-march=armv7-a"
+- export CGO_CXXFLAGS="-march=armv7-a"
+- ;;
+- esac
+- fi
+- fi
+-
+ # -buildmode=pie is not supported on Windows arm64 and Linux mips*, ppc64be
+ # https://github.com/golang/go/blob/go1.19.4/src/cmd/internal/sys/supported.go#L125-L132
+ if ! [ "$DOCKER_STATIC" = "1" ]; then
+ # -buildmode=pie not supported when -race is enabled
+ if [[ " $BUILDFLAGS " != *" -race "* ]]; then
+- case "$(go env GOOS)/$(go env GOARCH)" in
++ case "$(${GO} env GOOS)/$(${GO} env GOARCH)" in
+ windows/arm64 | linux/mips* | linux/ppc64) ;;
+ *)
+ BUILDFLAGS+=("-buildmode=pie")
+@@ -66,11 +45,11 @@
+ # only necessary for non-sandboxed invocation where TARGETPLATFORM is empty
+ PLATFORM_NAME=$TARGETPLATFORM
+ if [ -z "$PLATFORM_NAME" ]; then
+- PLATFORM_NAME="$(go env GOOS)/$(go env GOARCH)"
+- if [ -n "$(go env GOARM)" ]; then
+- PLATFORM_NAME+="/v$(go env GOARM)"
+- elif [ -n "$(go env GOAMD64)" ] && [ "$(go env GOAMD64)" != "v1" ]; then
+- PLATFORM_NAME+="/$(go env GOAMD64)"
++ PLATFORM_NAME="$(${GO} env GOOS)/$(${GO} env GOARCH)"
++ if [ -n "$(${GO} env GOARM)" ]; then
++ PLATFORM_NAME+="/v$(${GO} env GOARM)"
++ elif [ -n "$(${GO} env GOAMD64)" ] && [ "$(${GO} env GOAMD64)" != "v1" ]; then
++ PLATFORM_NAME+="/$(${GO} env GOAMD64)"
+ fi
+ fi
+
+@@ -82,7 +61,7 @@
+ if [ -n "$DOCKER_DEBUG" ]; then
+ set -x
+ fi
+- ./hack/with-go-mod.sh go build -mod=vendor -modfile=vendor.mod -o "$DEST/$BINARY_FULLNAME" "${BUILDFLAGS[@]}" -ldflags "$LDFLAGS $LDFLAGS_STATIC $DOCKER_LDFLAGS" -gcflags="${GCFLAGS}" "$GO_PACKAGE"
++ ./hack/with-go-mod.sh ${GO} build -trimpath -mod=vendor -modfile=vendor.mod -o "$DEST/$BINARY_FULLNAME" "${BUILDFLAGS[@]}" -ldflags "$LDFLAGS $LDFLAGS_STATIC $DOCKER_LDFLAGS" -gcflags="${GCFLAGS}" "$GO_PACKAGE"
+ )
+
+ echo "Created binary: $DEST/$BINARY_FULLNAME"