From fd557739724dbe7fcdd190017c7279e88699566d Mon Sep 17 00:00:00 2001 From: Linus Yang Date: Thu, 8 Mar 2018 03:20:04 +0800 Subject: [PATCH] Use docker to build MinGW port --- docker/mingw/Dockerfile | 42 ++++++++++++++++++++ docker/mingw/Makefile | 38 ++++++++++++++++++ docker/mingw/build.sh | 80 ++++++++++++++++++++++++++++++++++++++ docker/mingw/deps.sh | 71 ++++++++++++++++++++++++++++++++++ docker/mingw/prepare.sh | 85 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 316 insertions(+) create mode 100644 docker/mingw/Dockerfile create mode 100644 docker/mingw/Makefile create mode 100644 docker/mingw/build.sh create mode 100644 docker/mingw/deps.sh create mode 100644 docker/mingw/prepare.sh diff --git a/docker/mingw/Dockerfile b/docker/mingw/Dockerfile new file mode 100644 index 00000000..050fb847 --- /dev/null +++ b/docker/mingw/Dockerfile @@ -0,0 +1,42 @@ +# +# Dockerfile for building MinGW port +# +# This file is part of the shadowsocks-libev. +# +# shadowsocks-libev is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# shadowsocks-libev is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with shadowsocks-libev; see the file COPYING. If not, see +# . +# + +FROM debian:testing + +ARG REPO=shadowsocks +ARG REV=master + +ADD prepare.sh / + +RUN \ + /bin/bash -c "source /prepare.sh && dk_prepare" && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /build + +RUN /bin/bash -c "source /prepare.sh && dk_download" + +ADD deps.sh / +RUN /bin/bash -c "source /deps.sh && dk_deps" + +ADD build.sh / + +ARG REBUILD=0 + +RUN /bin/bash -c "source /build.sh && dk_build && dk_package" diff --git a/docker/mingw/Makefile b/docker/mingw/Makefile new file mode 100644 index 00000000..92c0122a --- /dev/null +++ b/docker/mingw/Makefile @@ -0,0 +1,38 @@ +# +# Makefile for building MinGW port +# +# This file is part of the shadowsocks-libev. +# +# shadowsocks-libev is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# shadowsocks-libev is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with shadowsocks-libev; see the file COPYING. If not, see +# . +# + +REPO=shadowsocks +REV=master +IMAGE=ss-build-mingw +DIST=ss-libev-win-dist.tar.gz + +all: build + +build: + docker build --force-rm -t $(IMAGE) \ + --build-arg REV=$(REV) --build-arg REPO=$(REPO) \ + --build-arg REBUILD="$$(date +%Y-%m-%d-%H-%M-%S)" . + docker run --rm --entrypoint cat $(IMAGE) /bin.tgz > $(DIST) + +clean: + rm -f $(DIST) + docker rmi $(IMAGE) || true + +.PHONY: all clean build diff --git a/docker/mingw/build.sh b/docker/mingw/build.sh new file mode 100644 index 00000000..da89871b --- /dev/null +++ b/docker/mingw/build.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# +# Functions for building MinGW port in Docker +# +# This file is part of the shadowsocks-libev. +# +# shadowsocks-libev is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# shadowsocks-libev is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with shadowsocks-libev; see the file COPYING. If not, see +# . +# + +# Exit on error +set -e + +. /prepare.sh + +build_proj() { + arch=$1 + host=$arch-w64-mingw32 + prefix=${DIST}/$arch + dep=${PREFIX}/$arch + + cd "$SRC" + git clone ${PROJ_URL} proj + cd proj + git checkout ${PROJ_REV} + git submodule update --init + ./autogen.sh + ./configure --host=${host} --prefix=${prefix} \ + --disable-documentation \ + --with-ev="$dep" \ + --with-mbedtls="$dep" \ + --with-sodium="$dep" \ + --with-pcre="$dep" \ + --with-cares="$dep" \ + CFLAGS="-DCARES_STATICLIB -DPCRE_STATIC" + make clean + make LDFLAGS="-all-static -L${dep}/lib" + make install-strip +} + +dk_build() { + for arch in i686 x86_64; do + build_proj $arch + done +} + +dk_package() { + rm -rf "$BASE/pack" + mkdir -p "$BASE/pack" + cd "$BASE/pack" + mkdir -p ss-libev-${PROJ_REV} + cd ss-libev-${PROJ_REV} + for bin in local server tunnel; do + cp ${DIST}/i686/bin/ss-${bin}.exe ss-${bin}-x86.exe + cp ${DIST}/x86_64/bin/ss-${bin}.exe ss-${bin}-x64.exe + done + pushd "$SRC/proj" + GIT_REV="$(git rev-parse --short HEAD)" + popd + echo "SHA1 checksum for build $(date +"%y%m%d")-${GIT_REV}" > checksum + for f in *.exe; do + echo " $f:" >> checksum + echo " $(sha1sum $f | cut -d ' ' -f 1)" >> checksum + done + sed -e 's/$/\r/' checksum > checksum.txt + rm -f checksum + cd .. + tar zcf /bin.tgz ss-libev-${PROJ_REV} +} diff --git a/docker/mingw/deps.sh b/docker/mingw/deps.sh new file mode 100644 index 00000000..0ee99454 --- /dev/null +++ b/docker/mingw/deps.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# +# Functions for building MinGW port in Docker +# +# This file is part of the shadowsocks-libev. +# +# shadowsocks-libev is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# shadowsocks-libev is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with shadowsocks-libev; see the file COPYING. If not, see +# . +# + +# Exit on error +set -e + +. /prepare.sh + +build_deps() { + arch=$1 + host=$arch-w64-mingw32 + prefix=${PREFIX}/$arch + args="--host=${host} --prefix=${prefix} --disable-shared --enable-static" + + # libev + cd "$SRC/$LIBEV_SRC" + ./configure $args + make clean + make install + + # mbedtls + cd "$SRC/$MBEDTLS_SRC" + make clean + make lib WINDOWS=1 CC="${host}-gcc" AR="${host}-ar" + make install DESTDIR="${prefix}" + + # sodium + cd "$SRC/$SODIUM_SRC" + ./configure $args + make clean + make install + + # pcre + cd "$SRC/$PCRE_SRC" + ./configure $args \ + --enable-jit --disable-cpp \ + --enable-unicode-properties \ + --enable-pcre16 --enable-pcre32 + make clean + make install + + # c-ares + cd "$SRC/$CARES_SRC" + ./configure $args + make clean + make install +} + +dk_deps() { + for arch in i686 x86_64; do + build_deps $arch + done +} diff --git a/docker/mingw/prepare.sh b/docker/mingw/prepare.sh new file mode 100644 index 00000000..d6b9b143 --- /dev/null +++ b/docker/mingw/prepare.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# +# Functions for building MinGW port in Docker +# +# This file is part of the shadowsocks-libev. +# +# shadowsocks-libev is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# shadowsocks-libev is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with shadowsocks-libev; see the file COPYING. If not, see +# . +# + +# Exit on error +set -e + +# Build options +BASE="/build" +PREFIX="$BASE/stage" +SRC="$BASE/src" +DIST="$BASE/dist" + +# Project URL +PROJ_SITE=$REPO # Change REPO in Makefile +PROJ_REV=$REV # Change REV in Makefile +PROJ_URL=https://github.com/${PROJ_SITE}/shadowsocks-libev.git + +# Libraries from project + +## libev for MinGW +LIBEV_VER=mingw +LIBEV_SRC=libev-${LIBEV_VER} +LIBEV_URL=https://github.com/${PROJ_SITE}/libev/archive/${LIBEV_VER}.tar.gz + +## mbedTLS for MinGW +MBEDTLS_VER=mingw +MBEDTLS_SRC=mbedtls-${MBEDTLS_VER} +MBEDTLS_URL=https://github.com/${PROJ_SITE}/mbedtls/archive/${MBEDTLS_VER}.tar.gz + +# Public libraries + +## Sodium +SODIUM_VER=1.0.16 +SODIUM_SRC=libsodium-${SODIUM_VER} +SODIUM_URL=https://download.libsodium.org/libsodium/releases/${SODIUM_SRC}.tar.gz + +## PCRE +PCRE_VER=8.41 +PCRE_SRC=pcre-${PCRE_VER} +PCRE_URL=https://ftp.pcre.org/pub/pcre/${PCRE_SRC}.tar.gz + +## c-ares +CARES_VER=1.14.0 +CARES_SRC=c-ares-${CARES_VER} +CARES_URL=https://c-ares.haxx.se/download/${CARES_SRC}.tar.gz + +# Build steps + +dk_prepare() { + apt-get update -y + apt-get install --no-install-recommends -y \ + mingw-w64 aria2 git make automake autoconf libtool ca-certificates +} + +dk_download() { + mkdir -p "${SRC}" + cd "${SRC}" + DOWN="aria2c --file-allocation=trunc -s10 -x10 -j10 -c" + for pkg in LIBEV SODIUM MBEDTLS PCRE CARES; do + src=${pkg}_SRC + url=${pkg}_URL + out="${!src}".tar.gz + $DOWN ${!url} -o "${out}" + echo "Unpacking ${out}..." + tar zxf ${out} + done +}