summaryrefslogtreecommitdiff
path: root/other
diff options
context:
space:
mode:
authorMaxim Biro <nurupo.contributions@gmail.com>2017-02-16 05:18:17 -0500
committerMaxim Biro <nurupo.contributions@gmail.com>2018-01-25 16:04:54 -0500
commite672b6f09218b61248a265a9a7ce3c0d3158ff48 (patch)
tree85e2971a8e6df5b080427213ef2c2ed7f94287f6 /other
parent29cd93a49c4ea30105e861e2b6b5fc41e329efef (diff)
Add Dockerfile for Windows cross-compilation
Diffstat (limited to 'other')
-rw-r--r--other/docker/windows/Dockerfile32
-rw-r--r--other/docker/windows/build_dependencies.sh89
-rw-r--r--other/docker/windows/build_toxcore.sh164
-rw-r--r--other/docker/windows/get_packages.sh55
4 files changed, 340 insertions, 0 deletions
diff --git a/other/docker/windows/Dockerfile b/other/docker/windows/Dockerfile
new file mode 100644
index 00000000..176c3937
--- /dev/null
+++ b/other/docker/windows/Dockerfile
@@ -0,0 +1,32 @@
1FROM debian:stretch-slim
2
3# Build-time enviroment variables
4ARG VERSION_SODIUM=1.0.16
5ARG VERSION_OPUS=v1.2.1
6ARG VERSION_VPX=v1.6.1
7ARG VERSION_CHECK=0.12.0
8
9ARG SUPPORT_TEST=false
10ARG SUPPORT_ARCH_i686=true
11ARG SUPPORT_ARCH_x86_64=true
12
13# Make those available when running the container
14ENV SUPPORT_TEST=${SUPPORT_TEST}
15ENV SUPPORT_ARCH_i686=${SUPPORT_ARCH_i686}
16ENV SUPPORT_ARCH_x86_64=${SUPPORT_ARCH_x86_64}
17
18ADD get_packages.sh .
19RUN sh ./get_packages.sh
20
21ADD build_dependencies.sh .
22RUN sh ./build_dependencies.sh
23
24ADD build_toxcore.sh .
25
26ENV ENABLE_TEST=false
27ENV ALLOW_TEST_FAILURE=false
28ENV ENABLE_ARCH_i686=true
29ENV ENABLE_ARCH_x86_64=true
30ENV EXTRA_CMAKE_FLAGS="-DWARNINGS=OFF -DBOOTSTRAP_DAEMON=OFF -DTEST_TIMEOUT_SECONDS=300"
31
32CMD sh ./build_toxcore.sh
diff --git a/other/docker/windows/build_dependencies.sh b/other/docker/windows/build_dependencies.sh
new file mode 100644
index 00000000..f3d4b603
--- /dev/null
+++ b/other/docker/windows/build_dependencies.sh
@@ -0,0 +1,89 @@
1#!/usr/bin/env sh
2
3set -e -x
4
5#=== Cross-Compile Dependencies ===
6
7build()
8{
9 ARCH=${1}
10
11 echo "Building for ${ARCH} architecture"
12
13 # set some things
14 WINDOWS_TOOLCHAIN=${ARCH}-w64-mingw32
15
16 # prefix that we will copy to the user
17 PREFIX_DIR="/root/prefix/${ARCH}"
18 # prefix for things that shouldn't be copied to the user
19 EXTRA_PREFIX_DIR="/root/extra-prefix/${ARCH}"
20 mkdir -p "${PREFIX_DIR}" "${EXTRA_PREFIX_DIR}"
21
22 export MAKEFLAGS=j$(nproc)
23 export CFLAGS=-O3
24
25 cd /tmp
26
27 echo
28 echo "=== Building Sodium ${VERSION_SODIUM} ${ARCH} ==="
29 git clone --depth=1 --branch="${VERSION_SODIUM}" https://github.com/jedisct1/libsodium
30 cd libsodium
31 ./autogen.sh
32 ./configure --host="${WINDOWS_TOOLCHAIN}" --prefix="${PREFIX_DIR}" --disable-shared --enable-static
33 make
34 make install
35 cd ..
36
37 echo
38 echo "=== Building Opus ${VERSION_OPUS} ${ARCH} ==="
39 git clone --depth=1 --branch="${VERSION_OPUS}" https://github.com/xiph/opus
40 cd opus
41 ./autogen.sh
42 ./configure --host="${WINDOWS_TOOLCHAIN}" --prefix="${PREFIX_DIR}" --disable-extra-programs --disable-doc --disable-shared --enable-static
43 make
44 make install
45 cd ..
46
47 echo
48 echo "=== Building VPX ${VERSION_VPX} ${ARCH} ==="
49 LIB_VPX_TARGET=""
50 if [ "${ARCH}" = "i686" ]; then
51 LIB_VPX_TARGET=x86-win32-gcc
52 else
53 LIB_VPX_TARGET=x86_64-win64-gcc
54 fi
55 git clone --depth=1 --branch="${VERSION_VPX}" https://github.com/webmproject/libvpx
56 cd libvpx
57 CROSS="${WINDOWS_TOOLCHAIN}"- ./configure --target="${LIB_VPX_TARGET}" --prefix="${PREFIX_DIR}" --disable-examples --disable-unit-tests --disable-shared --enable-static
58 make
59 make install
60 cd ..
61
62 if [ "${SUPPORT_TEST}" = "true" ]; then
63 echo
64 echo "=== Building Check ${VERSION_CHECK} ${ARCH} ==="
65 git clone --depth=1 --branch="${VERSION_CHECK}" https://github.com/libcheck/check
66 cd check
67 autoreconf --install
68 ./configure --host="${WINDOWS_TOOLCHAIN}" --prefix="${EXTRA_PREFIX_DIR}"
69 make
70 make install
71 cd ..
72 fi
73
74 rm -rf /tmp/*
75}
76
77if [ "${SUPPORT_ARCH_i686}" = "true" ]; then
78 build i686
79fi
80
81if [ "${SUPPORT_ARCH_x86_64}" = "true" ]; then
82 build x86_64
83fi
84
85tree /root
86
87echo
88echo "Built dependencies successfully!"
89echo
diff --git a/other/docker/windows/build_toxcore.sh b/other/docker/windows/build_toxcore.sh
new file mode 100644
index 00000000..0f4c2731
--- /dev/null
+++ b/other/docker/windows/build_toxcore.sh
@@ -0,0 +1,164 @@
1#!/usr/bin/env sh
2
3set -e -x
4
5#=== Cross-Compile Toxcore ===
6
7build()
8{
9 ARCH=${1}
10
11 echo "Building for ${ARCH} architecture"
12
13 # set some things
14
15 WINDOWS_TOOLCHAIN=${ARCH}-w64-mingw32
16
17 # toxcore dependencies that we will copy to the user for static build of toxcore (e.g. vpx, opus, sodium)
18 DEP_PREFIX_DIR="/root/prefix/${ARCH}"
19
20 # toxcore dependencies that user doesn't need in build result (e.g. libcheck used for testing toxcore)
21 EXTRA_DEP_PREFIX_DIR="/root/extra-prefix/${ARCH}"
22 mkdir -p "${EXTRA_DEP_PREFIX_DIR}"
23
24 # where to put the result of this particular build
25 RESULT_PREFIX_DIR="/prefix/${ARCH}"
26 mkdir -p "${RESULT_PREFIX_DIR}"
27
28 # where to install static/shared toxcores before deciding whether they should be copied over to the user
29 STATIC_TOXCORE_PREFIX_DIR="/tmp/static_prefix"
30 SHARED_TOXCORE_PREFIX_DIR="/tmp/shared_prefix"
31 mkdir -p "${STATIC_TOXCORE_PREFIX_DIR}" "${SHARED_TOXCORE_PREFIX_DIR}"
32
33 export MAKEFLAGS=j$(nproc)
34 export CFLAGS=-O3
35
36 echo
37 echo "=== Building toxcore ${ARCH} ==="
38 export PKG_CONFIG_PATH="${DEP_PREFIX_DIR}/lib/pkgconfig:${EXTRA_DEP_PREFIX_DIR}/lib/pkgconfig"
39
40 cp /toxcore /tmp/toxcore -R
41 cd /tmp/toxcore/build
42 echo "
43 SET(CMAKE_SYSTEM_NAME Windows)
44
45 SET(CMAKE_C_COMPILER ${WINDOWS_TOOLCHAIN}-gcc)
46 SET(CMAKE_CXX_COMPILER ${WINDOWS_TOOLCHAIN}-g++)
47 SET(CMAKE_RC_COMPILER ${WINDOWS_TOOLCHAIN}-windres)
48
49 SET(CMAKE_FIND_ROOT_PATH /usr/${WINDOWS_TOOLCHAIN} ${DEP_PREFIX_DIR} ${EXTRA_DEP_PREFIX_DIR})
50 " > windows_toolchain.cmake
51
52 if [ "${ENABLE_TEST}" = "true" ]; then
53 echo "SET(CROSSCOMPILING_EMULATOR /usr/bin/wine)" >> windows_toolchain.cmake
54 fi
55
56 cmake -DCMAKE_TOOLCHAIN_FILE=windows_toolchain.cmake \
57 -DCMAKE_INSTALL_PREFIX="${STATIC_TOXCORE_PREFIX_DIR}" \
58 -DENABLE_SHARED=OFF \
59 -DENABLE_STATIC=ON \
60 ${EXTRA_CMAKE_FLAGS} \
61 ..
62 cmake --build . --target install
63
64 if [ "${ENABLE_TEST}" = "true" ]; then
65 rm -rf /root/.wine
66
67 # setup wine
68 if [ "${ARCH}" = "i686" ]; then
69 export WINEARCH=win32
70 else
71 export WINEARCH=win64
72 fi
73
74 winecfg
75 export CTEST_OUTPUT_ON_FAILURE=1
76 # add libgcc_s_sjlj-1.dll libwinpthread-1.dll libcheck-0.dll into PATH env var of wine
77 export WINEPATH=`cd /usr/lib/gcc/${WINDOWS_TOOLCHAIN}/*posix/ ; winepath -w $(pwd)`\;`winepath -w /usr/${WINDOWS_TOOLCHAIN}/lib/`\;`winepath -w ${EXTRA_DEP_PREFIX_DIR}/bin`
78
79 if [ "${ALLOW_TEST_FAILURE}" = "true" ]; then
80 set +e
81 fi
82 cmake --build . --target test
83 if [ "${ALLOW_TEST_FAILURE}" = "true" ]; then
84 set -e
85 fi
86 fi
87
88 # move static dependencies
89 cp "${STATIC_TOXCORE_PREFIX_DIR}"/* "${RESULT_PREFIX_DIR}" -R
90 cp "${DEP_PREFIX_DIR}"/* "${RESULT_PREFIX_DIR}" -R
91
92 # make libtox.dll
93 cd "${SHARED_TOXCORE_PREFIX_DIR}"
94 for archive in ${STATIC_TOXCORE_PREFIX_DIR}/lib/libtox*.a
95 do
96 ${WINDOWS_TOOLCHAIN}-ar xv ${archive}
97 done
98 ${WINDOWS_TOOLCHAIN}-gcc -Wl,--export-all-symbols \
99 -Wl,--out-implib=libtox.dll.a \
100 -shared \
101 -o libtox.dll \
102 *.obj \
103 ${STATIC_TOXCORE_PREFIX_DIR}/lib/*.a \
104 ${DEP_PREFIX_DIR}/lib/*.a \
105 /usr/${WINDOWS_TOOLCHAIN}/lib/libwinpthread.a \
106 -liphlpapi \
107 -lws2_32 \
108 -static-libgcc
109 cp libtox.dll.a ${RESULT_PREFIX_DIR}/lib
110 mkdir -p ${RESULT_PREFIX_DIR}/bin
111 cp libtox.dll ${RESULT_PREFIX_DIR}/bin
112
113 rm -rf /tmp/*
114
115 # remove everything from include directory except tox headers
116 mv ${RESULT_PREFIX_DIR}/include/tox ${RESULT_PREFIX_DIR}/tox
117 rm -rf ${RESULT_PREFIX_DIR}/include/*
118 mv ${RESULT_PREFIX_DIR}/tox ${RESULT_PREFIX_DIR}/include/tox
119
120 sed -i "s|^prefix=.*|prefix=${RESULT_PREFIX_DIR}|g" ${RESULT_PREFIX_DIR}/lib/pkgconfig/*.pc
121 sed -i "s|^libdir=.*|libdir=${RESULT_PREFIX_DIR}/lib|g" ${RESULT_PREFIX_DIR}/lib/*.la
122}
123
124#=== Test Supported vs. Enabled ===
125
126if [ "${ENABLE_ARCH_i686}" != "true" ] && [ "${ENABLE_ARCH_x86_64}" != "true" ]; then
127 echo "Error: No architecture specified. Set either ENABLE_ARCH_i686 or ENABLE_ARCH_x86_64 or both."
128 exit 1
129fi
130
131if [ "${ENABLE_ARCH_i686}" = "true" ] && [ "${SUPPORT_ARCH_i686}" != "true" ]; then
132 echo "Error: Can't build for i686 architecture because the image was created without SUPPORT_ARCH_i686 set"
133 exit 1
134fi
135
136if [ "${ENABLE_ARCH_x86_64}" = "true" ] && [ "${SUPPORT_ARCH_x86_64}" != "true" ]; then
137 echo "Error: Can't build for x86_64 architecture because the image was created without SUPPORT_ARCH_x86_64 set"
138 exit 1
139fi
140
141if [ "${ENABLE_TEST}" = "true" ] && [ "${SUPPORT_TEST}" != "true" ]; then
142 echo "Error: Can't build with tests because the image was created without SUPPORT_TEST set"
143 exit 1
144fi
145
146#=== Build ===
147
148if [ "${ENABLE_ARCH_i686}" = "true" ]; then
149 build i686
150fi
151
152if [ "${ENABLE_ARCH_x86_64}" = "true" ]; then
153 build x86_64
154fi
155
156
157tree -h /prefix
158
159echo
160echo "Built toxcore successfully!"
161echo
162
163# since we are building as root
164chmod 777 /prefix -R
diff --git a/other/docker/windows/get_packages.sh b/other/docker/windows/get_packages.sh
new file mode 100644
index 00000000..e3fb51f5
--- /dev/null
+++ b/other/docker/windows/get_packages.sh
@@ -0,0 +1,55 @@
1#!/usr/bin/env sh
2
3set -e -x
4
5#=== Install Packages ===
6
7apt-get update
8
9# Arch-independent packages required for building toxcore's dependencies and toxcore itself
10apt-get install -y \
11 autoconf \
12 automake \
13 ca-certificates \
14 cmake \
15 git \
16 libtool \
17 libc-dev \
18 make \
19 pkg-config \
20 tree \
21 yasm
22
23# Arch-dependent packages required for building toxcore's dependencies and toxcore itself
24if [ "${SUPPORT_ARCH_i686}" = "true" ]; then
25 apt-get install -y \
26 g++-mingw-w64-i686 \
27 gcc-mingw-w64-i686
28fi
29
30if [ "${SUPPORT_ARCH_x86_64}" = "true" ]; then
31 apt-get install -y \
32 g++-mingw-w64-x86-64 \
33 gcc-mingw-w64-x86-64
34fi
35
36# Pacakges needed for running toxcore tests
37if [ "${SUPPORT_TEST}" = "true" ]; then
38 apt-get install -y \
39 curl \
40 texinfo
41
42 dpkg --add-architecture i386
43 apt-get update
44 apt-get install -y \
45 wine \
46 wine32 \
47 wine64
48fi
49
50# Clean up to reduce image size
51apt-get clean
52rm -rf \
53 /var/lib/apt/lists/* \
54 /tmp/* \
55 /var/tmp/*