diff options
author | Masood Malekghassemi <atash@google.com> | 2016-06-05 17:04:44 -0700 |
---|---|---|
committer | Masood Malekghassemi <atash@google.com> | 2016-07-08 12:36:15 -0700 |
commit | 639bb3996fa5b4f9d1785376c19ab69f747e0da8 (patch) | |
tree | 51b991523b794c0a5f594e0c946105fa2e8c95ed | |
parent | 06c857cb86586755ab5f01f1a8fecc614f23dffa (diff) |
Build Python distributions standalone for Windows
-rw-r--r-- | src/python/grpcio/grpc/_cython/cygrpc.pyx | 7 | ||||
-rw-r--r-- | src/python/grpcio/grpc/_cython/loader.c | 8 | ||||
-rw-r--r-- | tools/run_tests/build_artifact_python.bat | 48 |
3 files changed, 23 insertions, 40 deletions
diff --git a/src/python/grpcio/grpc/_cython/cygrpc.pyx b/src/python/grpcio/grpc/_cython/cygrpc.pyx index 7a8d0dd8a1..e055d321bc 100644 --- a/src/python/grpcio/grpc/_cython/cygrpc.pyx +++ b/src/python/grpcio/grpc/_cython/cygrpc.pyx @@ -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') diff --git a/src/python/grpcio/grpc/_cython/loader.c b/src/python/grpcio/grpc/_cython/loader.c index 750a9f6fa3..34bd897549 100644 --- a/src/python/grpcio/grpc/_cython/loader.c +++ b/src/python/grpcio/grpc/_cython/loader.c @@ -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 */ diff --git a/tools/run_tests/build_artifact_python.bat b/tools/run_tests/build_artifact_python.bat index 295347e947..7c8c2aa12d 100644 --- a/tools/run_tests/build_artifact_python.bat +++ b/tools/run_tests/build_artifact_python.bat @@ -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 |