Browse Source
Merge pull request #1962 from linusyang92/master
Merge pull request #1962 from linusyang92/master
Re-add MinGW compilation supportpull/1963/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 757 additions and 47 deletions
Split View
Diff Options
-
16configure.ac
-
42docker/mingw/Dockerfile
-
38docker/mingw/Makefile
-
80docker/mingw/build.sh
-
71docker/mingw/deps.sh
-
85docker/mingw/prepare.sh
-
45src/Makefile.am
-
3src/aead.c
-
2src/crypto.c
-
2src/crypto.h
-
8src/json.c
-
49src/local.c
-
2src/netutils.c
-
4src/netutils.h
-
4src/plugin.c
-
13src/resolv.c
-
2src/resolv.h
-
47src/server.c
-
2src/stream.h
-
2src/tls.c
-
39src/tunnel.c
-
19src/udprelay.c
-
20src/utils.c
-
48src/utils.h
-
75src/winsock.c
-
86src/winsock.h
@ -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 |
|||
# <http://www.gnu.org/licenses/>. |
|||
# |
|||
|
|||
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" |
@ -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
|
|||
# <http://www.gnu.org/licenses/>.
|
|||
#
|
|||
|
|||
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 |
@ -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 |
|||
# <http://www.gnu.org/licenses/>. |
|||
# |
|||
|
|||
# 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} |
|||
} |
@ -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 |
|||
# <http://www.gnu.org/licenses/>. |
|||
# |
|||
|
|||
# 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 |
|||
} |
@ -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 |
|||
# <http://www.gnu.org/licenses/>. |
|||
# |
|||
|
|||
# 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 |
|||
} |
@ -0,0 +1,75 @@ |
|||
/* |
|||
* winsock.c - Windows socket compatibility layer |
|||
* |
|||
* Copyright (C) 2013 - 2018, Max Lv <max.c.lv@gmail.com> |
|||
* |
|||
* 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 |
|||
* <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifdef __MINGW32__ |
|||
|
|||
#include "winsock.h" |
|||
#include "utils.h" |
|||
|
|||
void |
|||
winsock_init(void) |
|||
{ |
|||
int ret; |
|||
WSADATA wsa_data; |
|||
ret = WSAStartup(MAKEWORD(2, 2), &wsa_data); |
|||
if (ret != 0) { |
|||
FATAL("Failed to initialize winsock"); |
|||
} |
|||
} |
|||
|
|||
void |
|||
winsock_cleanup(void) |
|||
{ |
|||
WSACleanup(); |
|||
} |
|||
|
|||
int |
|||
setnonblocking(SOCKET socket) |
|||
{ |
|||
u_long arg = 1; |
|||
return ioctlsocket(socket, FIONBIO, &arg); |
|||
} |
|||
|
|||
void |
|||
ss_error(const char *s) |
|||
{ |
|||
char *msg = NULL; |
|||
DWORD err = WSAGetLastError(); |
|||
FormatMessage( |
|||
FORMAT_MESSAGE_ALLOCATE_BUFFER | |
|||
FORMAT_MESSAGE_FROM_SYSTEM | |
|||
FORMAT_MESSAGE_IGNORE_INSERTS, |
|||
NULL, err, |
|||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
|||
(LPTSTR)&msg, 0, NULL); |
|||
if (msg != NULL) { |
|||
// Remove trailing newline character |
|||
ssize_t len = strlen(msg) - 1; |
|||
if (len >= 0 && msg[len] == '\n') { |
|||
msg[len] = '\0'; |
|||
} |
|||
LOGE("%s: [%ld] %s", s, err, msg); |
|||
LocalFree(msg); |
|||
} |
|||
} |
|||
|
|||
#endif // __MINGW32__ |
@ -0,0 +1,86 @@ |
|||
/* |
|||
* winsock.h - Windows socket compatibility layer |
|||
* |
|||
* Copyright (C) 2013 - 2018, Max Lv <max.c.lv@gmail.com> |
|||
* |
|||
* 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 |
|||
* <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef _WINSOCK_H |
|||
#define _WINSOCK_H |
|||
|
|||
#ifdef __MINGW32__ |
|||
|
|||
#ifndef WIN32_LEAN_AND_MEAN |
|||
#define WIN32_LEAN_AND_MEAN |
|||
#endif |
|||
|
|||
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600 |
|||
#undef _WIN32_WINNT |
|||
#endif |
|||
|
|||
#ifndef _WIN32_WINNT |
|||
#define _WIN32_WINNT 0x0600 |
|||
#endif |
|||
|
|||
#include <windows.h> |
|||
#include <winsock2.h> |
|||
#include <ws2tcpip.h> |
|||
|
|||
// Override error number |
|||
#ifdef errno |
|||
#undef errno |
|||
#endif |
|||
#define errno WSAGetLastError() |
|||
|
|||
#ifdef EWOULDBLOCK |
|||
#undef EWOULDBLOCK |
|||
#endif |
|||
#define EWOULDBLOCK WSAEWOULDBLOCK |
|||
|
|||
#ifdef CONNECT_IN_PROGRESS |
|||
#undef CONNECT_IN_PROGRESS |
|||
#endif |
|||
#define CONNECT_IN_PROGRESS WSAEWOULDBLOCK |
|||
|
|||
// Override close function |
|||
#define close(fd) closesocket(fd) |
|||
|
|||
// Override MinGW functions |
|||
#define setsockopt(a,b,c,d,e) setsockopt(a,b,c,(const char *)(d),e) |
|||
#define inet_ntop(a,b,c,d) inet_ntop(a,(void *)(b),c,d) |
|||
|
|||
// Override Windows built-in functions |
|||
#ifdef ERROR |
|||
#undef ERROR |
|||
#endif |
|||
#define ERROR(s) ss_error(s) |
|||
#ifndef _UTILS_H |
|||
void ss_error(const char *s); |
|||
#endif |
|||
|
|||
// Missing unistd.h functions |
|||
#define sleep(x) Sleep((x) * 1000) |
|||
|
|||
// Winsock compatibility functions |
|||
int setnonblocking(SOCKET socket); |
|||
void winsock_init(void); |
|||
void winsock_cleanup(void); |
|||
|
|||
#endif // __MINGW32__ |
|||
|
|||
#endif // _WINSOCK_H |
Write
Preview
Loading…
Cancel
Save