Build Python distributions standalone for Windows

pull/7195/head
Masood Malekghassemi 9 years ago
parent 06c857cb86
commit 639bb3996f
  1. 7
      src/python/grpcio/grpc/_cython/cygrpc.pyx
  2. 8
      src/python/grpcio/grpc/_cython/loader.c
  3. 48
      tools/run_tests/build_artifact_python.bat

@ -50,13 +50,6 @@ include "grpc/_cython/_cygrpc/server.pyx.pxi"
def _initialize():
if 'win32' in sys.platform:
filename = pkg_resources.resource_filename(
'grpc._cython', '_windows/grpc_c.64.python')
if not isinstance(filename, bytes):
filename = filename.encode()
if not pygrpc_load_core(filename):
raise ImportError('failed to load core gRPC library')
if not pygrpc_initialize_core():
raise ImportError('failed to initialize core gRPC library')

@ -38,10 +38,14 @@
extern "C" {
#endif /* __cpluslus */
/* TODO(atash) remove cruft */
int pygrpc_load_core(char *path) { return 1; }
// Cython doesn't have Py_AtExit bindings, so we call the C_API directly
int pygrpc_initialize_core(void) {
grpc_init();
return Py_AtExit(grpc_shutdown) < 0 ? 0 : 1;
}
#ifdef __cplusplus
}
#endif /* __cpluslus */

@ -28,33 +28,24 @@
@rem OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set NUGET=C:\nuget\nuget.exe
%NUGET% restore vsprojects\grpc.sln || goto :error
@call vsprojects\build_vs2013.bat vsprojects\grpc.sln /t:grpc_dll /p:Configuration=Release /p:PlatformToolset=v120 /p:Platform=Win32 || goto :error
@call vsprojects\build_vs2013.bat vsprojects\grpc.sln /t:grpc_dll /p:Configuration=Release /p:PlatformToolset=v120 /p:Platform=x64 || goto :error
mkdir src\python\grpcio\grpc\_cython\_windows
@rem TODO(atash): maybe we could avoid the grpc_c.(32|64).python shim below if
@rem this used the right python build?
copy /Y vsprojects\Release\grpc_dll.dll src\python\grpcio\grpc\_cython\_windows\grpc_c.32.python || goto :error
copy /Y vsprojects\x64\Release\grpc_dll.dll src\python\grpcio\grpc\_cython\_windows\grpc_c.64.python || goto :error
set PATH=C:\%1;C:\%1\scripts;C:\msys64\mingw%2\bin;%PATH%
pip install --upgrade six
pip install --upgrade setuptools
pip install -rrequirements.txt
set GRPC_PYTHON_USE_CUSTOM_BDIST=0
set GRPC_PYTHON_BUILD_WITH_CYTHON=1
@rem Because this is windows and *everything seems to hate Windows* we have to
@rem set all of these flags ourselves because Python won't help us (see the
@rem setup.py of the grpcio_tools project).
set GRPC_PYTHON_CFLAGS=-fno-wrapv -frtti -std=c++11
@rem See https://sourceforge.net/p/mingw-w64/bugs/363/
if %2 == 32 (
set GRPC_PYTHON_CFLAGS=%GRPC_PYTHON_CFLAGS% -D_ftime=_ftime32 -D_timeb=__timeb32 -D_ftime_s=_ftime32_s
) else (
set GRPC_PYTHON_CFLAGS=%GRPC_PYTHON_CFLAGS% -D_ftime=_ftime64 -D_timeb=__timeb64
)
@rem Further confusing things, MSYS2's mingw64 tries to dynamically link
@rem libgcc, libstdc++, and winpthreads. We have to override this or our
@rem extensions end up linking to MSYS2 DLLs, which the normal Python on
@ -66,23 +57,18 @@ python -c "from distutils.cygwinccompiler import get_msvcr; print(get_msvcr()[0]
set /p PYTHON_MSVCR=<temp.txt
set GRPC_PYTHON_LDFLAGS=-static-libgcc -static-libstdc++ -mcrtdll=%PYTHON_MSVCR% -static -lpthread
@rem Build gRPC
if %2 == 32 (
python setup.py build_ext -c mingw32
) else (
python setup.py build_ext -c mingw32 -DMS_WIN64
)
python setup.py bdist_wheel
set GRPC_PYTHON_BUILD_WITH_CYTHON=1
@rem Build gRPC Python tools
@rem Set up gRPC Python tools
python tools\distrib\python\make_grpcio_tools.py
if %2 == 32 (
python tools\distrib\python\grpcio_tools\setup.py build_ext -c mingw32
) else (
python tools\distrib\python\grpcio_tools\setup.py build_ext -c mingw32 -DMS_WIN64
)
@rem Build gRPC Python extensions
python setup.py build_ext -c mingw32
python tools\distrib\python\grpcio_tools\setup.py build_ext -c mingw32
@rem Build gRPC Python distributions
python setup.py bdist_wheel
python tools\distrib\python\grpcio_tools\setup.py bdist_wheel
mkdir artifacts

Loading…
Cancel
Save