Browse code

Merge pull request #39090 from cpuguy83/cross_support_goarm

Add support for setting GOARM in cross target.

Sebastiaan van Stijn authored on 2019/04/18 07:53:12
Showing 3 changed files
... ...
@@ -80,6 +80,7 @@ case "$(go env GOOS)/$(go env GOARCH)" in
80 80
 esac
81 81
 
82 82
 echo "Building: $DEST/$BINARY_FULLNAME"
83
+echo "GOOS=\"${GOOS}\" GOARCH=\"${GOARCH}\" GOARM=\"${GOARM}\""
83 84
 go build \
84 85
 	-o "$DEST/$BINARY_FULLNAME" \
85 86
 	"${BUILDFLAGS[@]}" \
... ...
@@ -18,8 +18,14 @@ for platform in ${DOCKER_CROSSPLATFORMS}; do
18 18
 	(
19 19
 		export KEEPDEST=1
20 20
 		export DEST="${DEST}/${platform}" # bundles/VERSION/cross/GOOS/GOARCH/docker-VERSION
21
-		export GOOS=${platform%/*}
22
-		export GOARCH=${platform##*/}
21
+		export GOOS=${platform%%/*}
22
+		export GOARCH=${platform#*/}
23
+
24
+		if [[ "${GOARCH}" = "arm/"* ]]; then
25
+			GOARM=${GOARCH##*/v}
26
+			GOARCH=${GOARCH%/v*}
27
+			export GOARM
28
+		fi
23 29
 
24 30
 		echo "Cross building: ${DEST}"
25 31
 		mkdir -p "${DEST}"
... ...
@@ -233,6 +233,27 @@ following:
233 233
 This will create "./bundles/$VERSION/dynbinary-client/docker-$VERSION", which for
234 234
 client-only builds is the important file to grab and install as appropriate.
235 235
 
236
+### Cross Compilation
237
+
238
+Limited cross compilation is supported due to requiring cgo for critical
239
+functionality (such as seccomp support).
240
+
241
+To cross compile run `make cross`. You can specify the platforms to target by
242
+setting the `DOCKER_CROSSPLATFORMS` environment variable to a list of platforms
243
+in the format `<GOOS>/<GOARCH>`. Specify multiple platforms by using a space
244
+in between each desired platform.
245
+
246
+For setting arm variants, you can specify the `GOARM` value by append `/v<GOARM>`
247
+to your `<GOOS>/arm`. Example:
248
+
249
+```
250
+make DOCKER_CROSSPLATFORMS=linux/arm/v7 cross
251
+```
252
+
253
+This will create a linux binary targeting arm 7.
254
+
255
+See `hack/make/.binary` for supported cross compliation platforms.
256
+
236 257
 ## System Dependencies
237 258
 
238 259
 ### Runtime Dependencies