From 49765579f1b39b1e62a3be2006d093a3aca5181b Mon Sep 17 00:00:00 2001 From: Peifeng Qiu Date: Wed, 8 Jul 2020 19:08:54 +0900 Subject: [PATCH] Fix pygresql windows build (#10420) - CMakeLists.txt moved to gpMgmt/bin/pythonSrc/PyGreSQL - Unpack source code from gpMgmt/bin/pythonSrc/ext/PyGreSQL-*.tar.gz - Add declaration to force dllexport on init_pg - Remove the pygresql level folder. All files are moved up. --- README.windows.md | 6 ++- .../scripts/compile_gpdb_remote_windows.bash | 1 + .../scripts/compile_gpdb_remote_windows.bat | 2 +- .../install/src/windows/greenplum-clients.wxs | 14 +++-- gpMgmt/bin/pythonSrc/PyGreSQL/CMakeLists.txt | 52 +++++++++++++++++++ 5 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 gpMgmt/bin/pythonSrc/PyGreSQL/CMakeLists.txt diff --git a/README.windows.md b/README.windows.md index 10d0a887a8..902b7ada30 100644 --- a/README.windows.md +++ b/README.windows.md @@ -113,7 +113,9 @@ nmake install NODEBUG=1 # Build steps -Replace with real location of your gpdb source code. +Replace with real location of your gpdb source code. Make sure you have +also cloned the submodule at gpMgmt\bin\pythonSrc\ext. + We will install client package to C:\greenplum-db-devel. If you want another location, make sure you've replaced C:\greenplum-db-devel in the following scripts. @@ -142,7 +144,7 @@ cmake --build . --config Release --target INSTALL 4. Build pygresql, needed by gpload ``` -cd \gpMgmt\bin\pythonSrc\PyGreSQL-4.0 +cd \gpMgmt\bin\pythonSrc\PyGreSQL mkdir build cd build cmake -DCMAKE_PREFIX_PATH=C:\greenplum-db-devel -DCMAKE_INSTALL_PREFIX:PATH=C:\greenplum-db-devel -G "Visual Studio 15 2017 Win64" .. diff --git a/concourse/scripts/compile_gpdb_remote_windows.bash b/concourse/scripts/compile_gpdb_remote_windows.bash index 544f133004..3cb7807f05 100755 --- a/concourse/scripts/compile_gpdb_remote_windows.bash +++ b/concourse/scripts/compile_gpdb_remote_windows.bash @@ -50,6 +50,7 @@ function remote_clone() { git clone "${GIT_URI}" gpdb_src cd gpdb_src git reset --hard "${GIT_COMMIT}" + git submodule update --init --recursive EOF } diff --git a/concourse/scripts/compile_gpdb_remote_windows.bat b/concourse/scripts/compile_gpdb_remote_windows.bat index 3746fc81bd..b6f12ec625 100644 --- a/concourse/scripts/compile_gpdb_remote_windows.bat +++ b/concourse/scripts/compile_gpdb_remote_windows.bat @@ -15,7 +15,7 @@ cmake --build . --config Release --target ALL_BUILD cmake --build . --config Release --target INSTALL REM build pygresql -cd %WORK_DIR%\gpdb_src\gpMgmt\bin\pythonSrc\PyGreSQL-4.0 +cd %WORK_DIR%\gpdb_src\gpMgmt\bin\pythonSrc\PyGreSQL mkdir build cd build cmake -DCMAKE_PREFIX_PATH=%WORK_DIR%\greenplum-db-devel -DCMAKE_INSTALL_PREFIX:PATH=%WORK_DIR%\greenplum-db-devel -G "Visual Studio 15 2017 Win64" .. diff --git a/gpAux/client/install/src/windows/greenplum-clients.wxs b/gpAux/client/install/src/windows/greenplum-clients.wxs index 742703a529..d464332867 100755 --- a/gpAux/client/install/src/windows/greenplum-clients.wxs +++ b/gpAux/client/install/src/windows/greenplum-clients.wxs @@ -1142,14 +1142,12 @@ If you want to review or change any of your installation settings, click Back. C - - - - - - - - + + + + + + diff --git a/gpMgmt/bin/pythonSrc/PyGreSQL/CMakeLists.txt b/gpMgmt/bin/pythonSrc/PyGreSQL/CMakeLists.txt new file mode 100644 index 0000000000..ce1b626d3c --- /dev/null +++ b/gpMgmt/bin/pythonSrc/PyGreSQL/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 3.12) + +set (CMAKE_CONFIGURATION_TYPES Release RelWithDebInfo) +project(pygresql C) + +find_package(Python2 COMPONENTS Interpreter Development) +if (Python2_FOUND) + include_directories(${Python2_INCLUDE_DIRS}) +else () + message(FATAL_ERROR "python2 not found") +endif(Python2_FOUND) + +file(GLOB SRC_TARBALL ${CMAKE_CURRENT_SOURCE_DIR}/../ext/PyGreSQL-*.tar.gz) +if (NOT SRC_TARBALL) + message(FATAL_ERROR "PyGreSQL source tarball not found, run git submodule update --init --recursive") +endif() + +execute_process(COMMAND tar -xf ${SRC_TARBALL} --strip-components=1 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + +file(READ pgmodule.c PGMODULE_LINES) +file(WRITE pgmodule.c "__declspec(dllexport) void init_pg(void);\n") +file(APPEND pgmodule.c "${PGMODULE_LINES}") + +add_definitions("/D FRONTEND") + +set (CPPFLAGS "/MP /wd4996 /wd4018 /wd4090 /wd4102 /wd4244 /wd4267 /wd4273 /wd4715") +add_definitions("${CPPFLAGS}") + +file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py" "") +set(GPDB_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../) +include_directories(${GPDB_SRC_DIR}/src/include + ${GPDB_SRC_DIR}/src/interfaces/libpq + ${GPDB_SRC_DIR}/src/include/port + ${GPDB_SRC_DIR}/src/include/port/win32 + ${GPDB_SRC_DIR}/src/include/port/win32_msvc + ${GPDB_SRC_DIR}/src/port + ${Python2_INCLUDE_DIRS}) +link_directories(${CMAKE_PREFIX_PATH}/lib) +find_library(LIBPQ NAMES libpq HINTS ${CMAKE_INSTALL_PREFIX}/LIB) +find_library(LIBPGPORT NAMES libpgport HINTS ${CMAKE_INSTALL_PREFIX}/LIB) +find_library(LIBPGCOMMON NAMES libpgcommon HINTS ${CMAKE_INSTALL_PREFIX}/LIB) + +add_library (pygresql SHARED pgmodule.c) +target_link_libraries(pygresql ${LIBPQ} ${LIBPGPORT} ${LIBPGCOMMON} ws2_32 secur32 ${Python2_LIBRARIES}) + +set_target_properties(pygresql PROPERTIES OUTPUT_NAME "_pg") +set_target_properties(pygresql PROPERTIES SUFFIX ".pyd") +install(TARGETS pygresql DESTINATION lib/python) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pg.py DESTINATION lib/python) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pgdb.py DESTINATION lib/python) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py DESTINATION lib/python) \ No newline at end of file -- GitLab