Переглянути джерело

make windows cross compile static daemon work

Signed-off-by: Jessica Frazelle <acidburn@docker.com>
Jessica Frazelle 10 роки тому
батько
коміт
e62745922f
3 змінених файлів з 15 додано та 0 видалено
  1. 1 0
      Dockerfile
  2. 13 0
      hack/make/binary
  3. 1 0
      hack/make/cross

+ 1 - 0
Dockerfile

@@ -40,6 +40,7 @@ RUN apt-get update && apt-get install -y \
 	createrepo \
 	createrepo \
 	curl \
 	curl \
 	dpkg-sig \
 	dpkg-sig \
+	gcc-mingw-w64 \
 	git \
 	git \
 	iptables \
 	iptables \
 	libapparmor-dev \
 	libapparmor-dev \

+ 13 - 0
hack/make/binary

@@ -7,6 +7,18 @@ BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"
 
 
 source "${MAKEDIR}/.go-autogen"
 source "${MAKEDIR}/.go-autogen"
 
 
+(
+if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then
+	# must be cross-compiling!
+	case "$(go env GOOS)/$(go env GOARCH)" in
+		windows/amd64)
+			export CC=x86_64-w64-mingw32-gcc
+			export CGO_ENABLED=1
+			export LDFLAGS_STATIC_DOCKER="${LDFLAGS_STATIC_DOCKER/-linkmode external/} -extld=${CC}"
+			;;
+	esac
+fi
+
 echo "Building: $DEST/$BINARY_FULLNAME"
 echo "Building: $DEST/$BINARY_FULLNAME"
 go build \
 go build \
 	-o "$DEST/$BINARY_FULLNAME" \
 	-o "$DEST/$BINARY_FULLNAME" \
@@ -16,6 +28,7 @@ go build \
 		$LDFLAGS_STATIC_DOCKER
 		$LDFLAGS_STATIC_DOCKER
 	" \
 	" \
 	./docker
 	./docker
+)
 
 
 echo "Created binary: $DEST/$BINARY_FULLNAME"
 echo "Created binary: $DEST/$BINARY_FULLNAME"
 ln -sf "$BINARY_FULLNAME" "$DEST/docker$BINARY_EXTENSION"
 ln -sf "$BINARY_FULLNAME" "$DEST/docker$BINARY_EXTENSION"

+ 1 - 0
hack/make/cross

@@ -5,6 +5,7 @@ set -e
 declare -A daemonSupporting
 declare -A daemonSupporting
 daemonSupporting=(
 daemonSupporting=(
 	[linux/amd64]=1
 	[linux/amd64]=1
+	[windows/amd64]=1
 )
 )
 
 
 # if we have our linux/amd64 version compiled, let's symlink it in
 # if we have our linux/amd64 version compiled, let's symlink it in