aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-containers/docker/files/0001-dynbinary-use-go-cross-compiler.patch
blob: 696eeaa79bb7fb5b624359ca852bfc81bcca0879 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
 
@@ -78,7 +57,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" "$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" "$GO_PACKAGE"
 )
 
 echo "Created binary: $DEST/$BINARY_FULLNAME"