From aa202df2835be088a6c1eeb4705a915122a60af4 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Sat, 9 Jun 2018 01:20:20 -0400 Subject: [PATCH] windows-(x86|x64): Optimize images introducing "common.windows" * Avoid duplication introducing common script * Optimize image size reducing the number of RUN instructions --- Makefile | 5 +- common.windows | 115 ++++++++++++++++++++++++++++++++++++++ windows-x64/Dockerfile | 88 ----------------------------- windows-x64/Dockerfile.in | 20 +++++++ windows-x64/settings.mk | 4 -- windows-x86/Dockerfile | 88 ----------------------------- windows-x86/Dockerfile.in | 21 +++++++ windows-x86/settings.mk | 4 -- 8 files changed, 159 insertions(+), 186 deletions(-) create mode 100644 common.windows delete mode 100644 windows-x64/Dockerfile create mode 100644 windows-x64/Dockerfile.in delete mode 100644 windows-x64/settings.mk delete mode 100644 windows-x86/Dockerfile create mode 100644 windows-x86/Dockerfile.in delete mode 100644 windows-x86/settings.mk diff --git a/Makefile b/Makefile index 4700cfa..dda7f54 100644 --- a/Makefile +++ b/Makefile @@ -16,13 +16,13 @@ BIN = ./bin STANDARD_IMAGES = linux-s390x android-arm android-arm64 linux-x86 linux-x64 linux-arm64 linux-armv5 linux-armv6 linux-armv7 linux-mips linux-mipsel linux-ppc64le windows-x86 windows-x64 # Generated Dockerfiles. -GEN_IMAGES = linux-s390x linux-mips manylinux-x86 manylinux-x64 browser-asmjs linux-arm64 +GEN_IMAGES = linux-s390x linux-mips manylinux-x86 manylinux-x64 browser-asmjs linux-arm64 windows-x86 windows-x64 GEN_IMAGE_DOCKERFILES = $(addsuffix /Dockerfile,$(GEN_IMAGES)) # These images are expected to have explicit rules for *both* build and testing NON_STANDARD_IMAGES = browser-asmjs manylinux-x64 manylinux-x86 -DOCKER_COMPOSITE_SOURCES = common.docker common.debian common.manylinux common.crosstool +DOCKER_COMPOSITE_SOURCES = common.docker common.debian common.manylinux common.crosstool common.windows # This list all available images IMAGES = $(STANDARD_IMAGES) $(NON_STANDARD_IMAGES) @@ -59,6 +59,7 @@ $(GEN_IMAGE_DOCKERFILES) Dockerfile: %Dockerfile: %Dockerfile.in $(DOCKER_COMPOS -e '/common.debian/ r common.debian' \ -e '/common.manylinux/ r common.manylinux' \ -e '/common.crosstool/ r common.crosstool' \ + -e '/common.windows/ r common.windows' \ $< > $@ # diff --git a/common.windows b/common.windows new file mode 100644 index 0000000..da751c9 --- /dev/null +++ b/common.windows @@ -0,0 +1,115 @@ + +# +# Before including this script, make sure to set: +# +# WINEARCH environment variable to either "win64" or "win32" +# MXE_TARGET_ARCH argument to either "x86_64" or "i686". See http://mxe.cc/ +# +# For example: +# +# ENV WINEARCH win64 +# ARG MXE_TARGET_ARCH=x86_64 +# + +# mxe master 2017-10-25 +ARG MXE_GIT_TAG=994ad47302e8811614b7eb49fc05234942b95b89 + +ENV CMAKE_TOOLCHAIN_FILE /usr/src/mxe/usr/${MXE_TARGET_ARCH}-w64-mingw32.static/share/cmake/mxe-conf.cmake + +ARG DEBIAN_FRONTEND=noninteractive + +# +# WINE is used as an emulator for try_run and tests with CMake. +# +# Other dependencies are from the listed MXE requirements: +# http://mxe.cc/#requirements +# 'cmake' is omitted because it is installed from source in the base image +# +RUN \ + apt-get update && \ + apt-get -y install \ + autoconf \ + automake \ + autopoint \ + bash \ + bison \ + bzip2 \ + flex \ + gettext \ + git \ + g++ \ + g++-multilib \ + gperf \ + intltool \ + libffi-dev \ + libgdk-pixbuf2.0-dev \ + libtool-bin \ + libltdl-dev \ + libssl-dev \ + libxml-parser-perl \ + libc6-dev-i386 \ + make \ + openssl \ + p7zip-full \ + patch \ + perl \ + pkg-config \ + python \ + ruby \ + scons \ + sed \ + unzip \ + wget \ + wine \ + xz-utils \ + && \ + # + # Install Wine + # + dpkg --add-architecture i386 && \ + apt-get update && \ + apt-get install -y wine32 && \ + wine hostname && \ + # + # Download MXE sources + # + cd /usr/src && \ + git clone https://github.com/mxe/mxe.git && \ + cd mxe && \ + git checkout ${MXE_GIT_TAG} && \ + # + # Configure "settings.mk" required to build MXE + # + cd /usr/src/mxe && \ + echo "MXE_TARGETS := ${MXE_TARGET_ARCH}-w64-mingw32.static" > settings.mk && \ + echo "LOCAL_PKG_LIST := gcc" >> settings.mk && \ + echo ".DEFAULT local-pkg-list:" >> settings.mk && \ + echo "local-pkg-list: \$(LOCAL_PKG_LIST)" >> settings.mk && \ + # + # Build MXE + # + cd /usr/src/mxe && \ + make -j$(nproc) && \ + # + # Update MXE toolchain file + # + echo 'set(CMAKE_CROSSCOMPILING_EMULATOR "/usr/bin/wine")' >> ${CMAKE_TOOLCHAIN_FILE} && \ + # + # Replace cmake and cpack binaries + # + cd /usr/bin && \ + rm cmake cpack && \ + ln -s /usr/src/mxe/usr/bin/${MXE_TARGET_ARCH}-w64-mingw32.static-cmake cmake && \ + ln -s /usr/src/mxe/usr/bin/${MXE_TARGET_ARCH}-w64-mingw32.static-cpack cpack + +ENV PATH ${PATH}:/usr/src/mxe/usr/bin +ENV CROSS_TRIPLE ${MXE_TARGET_ARCH}-w64-mingw32.static +ENV AS=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-as \ + AR=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-ar \ + CC=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-gcc \ + CPP=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-cpp \ + CXX=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-g++ \ + LD=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-ld \ + FC=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-gfortran + +WORKDIR /work diff --git a/windows-x64/Dockerfile b/windows-x64/Dockerfile deleted file mode 100644 index 6005047..0000000 --- a/windows-x64/Dockerfile +++ /dev/null @@ -1,88 +0,0 @@ -FROM dockcross/base:latest -MAINTAINER Matt McCormick "matt.mccormick@kitware.com" - -# WINE is used as an emulator for try_run and tests with CMake. -# Other dependencies are from the listed MXE requirements: -# http://mxe.cc/#requirements -# 'cmake' is omitted because it is installed from source in the base image -RUN apt-get update && apt-get -y install \ - autoconf \ - automake \ - autopoint \ - bash \ - bison \ - bzip2 \ - flex \ - gettext \ - git \ - g++ \ - g++-multilib \ - gperf \ - intltool \ - libffi-dev \ - libgdk-pixbuf2.0-dev \ - libtool-bin \ - libltdl-dev \ - libssl-dev \ - libxml-parser-perl \ - libc6-dev-i386 \ - make \ - openssl \ - p7zip-full \ - patch \ - perl \ - pkg-config \ - python \ - ruby \ - scons \ - sed \ - unzip \ - wget \ - wine \ - xz-utils -# Set up wine -RUN dpkg --add-architecture i386 && \ - apt-get update && \ - apt-get install -y wine32 -ENV WINEARCH win64 -RUN wine hostname - -WORKDIR /usr/src -# mxe master 2017-10-25 -RUN git clone https://github.com/mxe/mxe.git && \ - cd mxe && \ - git checkout 994ad47302e8811614b7eb49fc05234942b95b89 -WORKDIR /usr/src/mxe -COPY settings.mk /usr/src/mxe/ -RUN make -j$(nproc) - -ENV PATH ${PATH}:/usr/src/mxe/usr/bin -ENV CROSS_TRIPLE x86_64-w64-mingw32.static -ENV AS=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-as \ - AR=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-ar \ - CC=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-gcc \ - CPP=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-cpp \ - CXX=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-g++ \ - LD=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-ld \ - FC=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-gfortran - -ENV DEFAULT_DOCKCROSS_IMAGE dockcross/windows-x64 -WORKDIR /work - -ENV CMAKE_TOOLCHAIN_FILE /usr/src/mxe/usr/x86_64-w64-mingw32.static/share/cmake/mxe-conf.cmake -RUN echo 'set(CMAKE_CROSSCOMPILING_EMULATOR "/usr/bin/wine")' >> ${CMAKE_TOOLCHAIN_FILE} -RUN cd /usr/local/bin \ - && rm cmake \ - && ln -s /usr/src/mxe/usr/bin/x86_64-w64-mingw32.static-cmake cmake \ - && ln -s /usr/src/mxe/usr/bin/x86_64-w64-mingw32.static-cpack cpack - -# Build-time metadata as defined at http://label-schema.org -ARG BUILD_DATE -ARG IMAGE -ARG VCS_REF -ARG VCS_URL -LABEL org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.name=$IMAGE \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vcs-url=$VCS_URL \ - org.label-schema.schema-version="1.0" diff --git a/windows-x64/Dockerfile.in b/windows-x64/Dockerfile.in new file mode 100644 index 0000000..b1bec6a --- /dev/null +++ b/windows-x64/Dockerfile.in @@ -0,0 +1,20 @@ +FROM dockcross/base:latest +MAINTAINER Matt McCormick "matt.mccormick@kitware.com" + +ENV WINEARCH win64 +ARG MXE_TARGET_ARCH=x86_64 + +#include "common.windows" + +ENV DEFAULT_DOCKCROSS_IMAGE dockcross/windows-x64 + +# Build-time metadata as defined at http://label-schema.org +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/windows-x64/settings.mk b/windows-x64/settings.mk deleted file mode 100644 index 1f8e4ef..0000000 --- a/windows-x64/settings.mk +++ /dev/null @@ -1,4 +0,0 @@ -MXE_TARGETS := x86_64-w64-mingw32.static -LOCAL_PKG_LIST := gcc -.DEFAULT local-pkg-list: -local-pkg-list: $(LOCAL_PKG_LIST) diff --git a/windows-x86/Dockerfile b/windows-x86/Dockerfile deleted file mode 100644 index 542d3a6..0000000 --- a/windows-x86/Dockerfile +++ /dev/null @@ -1,88 +0,0 @@ -FROM dockcross/base:latest -MAINTAINER Matt McCormick "matt.mccormick@kitware.com" - -# WINE is used as an emulator for try_run and tests with CMake. -# Other dependencies are from the listed MXE requirements: -# http://mxe.cc/#requirements -# 'cmake' is omitted because it is installed from source in the base image -RUN apt-get update && apt-get -y --force-yes install \ - autoconf \ - automake \ - autopoint \ - bash \ - bison \ - bzip2 \ - flex \ - gettext \ - git \ - g++ \ - g++-multilib \ - gperf \ - intltool \ - libffi-dev \ - libgdk-pixbuf2.0-dev \ - libtool-bin \ - libltdl-dev \ - libssl-dev \ - libxml-parser-perl \ - libc6-dev-i386 \ - make \ - openssl \ - p7zip-full \ - patch \ - perl \ - pkg-config \ - python \ - ruby \ - scons \ - sed \ - unzip \ - wget \ - wine \ - xz-utils -# Set up wine -RUN dpkg --add-architecture i386 && \ - apt-get update && \ - apt-get install -y wine32 -ENV WINEARCH win32 -RUN wine hostname - -WORKDIR /usr/src -# mxe master 2017-10-25 -RUN git clone https://github.com/mxe/mxe.git && \ - cd mxe && \ - git checkout 994ad47302e8811614b7eb49fc05234942b95b89 -WORKDIR /usr/src/mxe -COPY settings.mk /usr/src/mxe/ -RUN make -j$(nproc) - -ENV PATH ${PATH}:/usr/src/mxe/usr/bin -ENV CROSS_TRIPLE i686-w64-mingw32.static -ENV AS=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-as \ - AR=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-ar \ - CC=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-gcc \ - CPP=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-cpp \ - CXX=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-g++ \ - LD=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-ld \ - FC=/usr/src/mxe/usr/bin/${CROSS_TRIPLE}-gfortran - -ENV DEFAULT_DOCKCROSS_IMAGE dockcross/windows-x86 -WORKDIR /work - -ENV CMAKE_TOOLCHAIN_FILE /usr/src/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake -RUN echo 'set(CMAKE_CROSSCOMPILING_EMULATOR "/usr/bin/wine")' >> ${CMAKE_TOOLCHAIN_FILE} -RUN cd /usr/local/bin \ - && rm cmake \ - && ln -s /usr/src/mxe/usr/bin/i686-w64-mingw32.static-cmake cmake \ - && ln -s /usr/src/mxe/usr/bin/i686-w64-mingw32.static-cpack cpack - -# Build-time metadata as defined at http://label-schema.org -ARG BUILD_DATE -ARG IMAGE -ARG VCS_REF -ARG VCS_URL -LABEL org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.name=$IMAGE \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vcs-url=$VCS_URL \ - org.label-schema.schema-version="1.0" diff --git a/windows-x86/Dockerfile.in b/windows-x86/Dockerfile.in new file mode 100644 index 0000000..a21f1dc --- /dev/null +++ b/windows-x86/Dockerfile.in @@ -0,0 +1,21 @@ +FROM dockcross/base:latest +MAINTAINER Matt McCormick "matt.mccormick@kitware.com" + +ENV WINEARCH win32 +ARG MXE_TARGET_ARCH=i686 + +#include "common.windows" + +ENV DEFAULT_DOCKCROSS_IMAGE dockcross/windows-x86 +WORKDIR /work + +# Build-time metadata as defined at http://label-schema.org +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/windows-x86/settings.mk b/windows-x86/settings.mk deleted file mode 100644 index 582532f..0000000 --- a/windows-x86/settings.mk +++ /dev/null @@ -1,4 +0,0 @@ -MXE_TARGETS := i686-w64-mingw32.static -LOCAL_PKG_LIST := gcc -.DEFAULT local-pkg-list: -local-pkg-list: $(LOCAL_PKG_LIST)