From b7eaf99a7b04e720f487bb350d0fe58a8a5506d3 Mon Sep 17 00:00:00 2001 From: tdcosta100 Date: Wed, 28 Dec 2022 19:04:12 -0300 Subject: [PATCH] [pthreads] Fix EACCESSVIOLATION in pthread_getname_np and better install handling (#28173) * [pthreads] Fix EACCESSVIOLATION in pthread_getname_np * [pthreads] Use vcpkg options instead custom commands * [pthreads] Update port version * [pthreads] Don't use separate builds for release and debug * [pthreads] Update port version * [pthreads] Cleaner solution for building configuration * [pthreads] Update port version * [pthreads] Correct variable name * [pthreads] Update port version * [pthreads] Make install even more optimized * [pthreads] Update port version * [pthreads] Fix static builds * [pthreads] Update port version * [pthreads] Correct quotes * [pthreads] Update port version * [pthreads] Fix compatibility with UWP * [pthreads] Update port version * [pthreads] Correction in fix-pthread_getname_np.patch * [pthreads] Update port version --- ports/pthreads/fix-install.patch | 53 ++++++++++ ports/pthreads/fix-pthread_getname_np.patch | 26 +++++ ports/pthreads/fix-uwp-linkage.patch | 20 ++++ ports/pthreads/portfile.cmake | 103 ++++++-------------- ports/pthreads/vcpkg.json | 10 +- versions/baseline.json | 2 +- versions/p-/pthreads.json | 5 + 7 files changed, 141 insertions(+), 78 deletions(-) create mode 100644 ports/pthreads/fix-install.patch create mode 100644 ports/pthreads/fix-pthread_getname_np.patch diff --git a/ports/pthreads/fix-install.patch b/ports/pthreads/fix-install.patch new file mode 100644 index 0000000000..afccae9aaa --- /dev/null +++ b/ports/pthreads/fix-install.patch @@ -0,0 +1,53 @@ +diff --git a/Makefile b/Makefile +index a703b9c..b7b5ea7 100644 +--- a/Makefile ++++ b/Makefile +@@ -80,18 +80,27 @@ help: + @ echo nmake clean VSE-static-debug + + all: ++!IF DEFINED(BUILD_STATIC) ++! IF DEFINED(BUILD_RELEASE) + $(MAKE) /E clean VC-static + $(MAKE) /E clean VCE-static + $(MAKE) /E clean VSE-static ++! ELSE + $(MAKE) /E clean VC-static-debug + $(MAKE) /E clean VCE-static-debug + $(MAKE) /E clean VSE-static-debug ++! ENDIF ++!ELSE ++! IF DEFINED(BUILD_RELEASE) + $(MAKE) /E clean VC + $(MAKE) /E clean VCE + $(MAKE) /E clean VSE ++! ELSE + $(MAKE) /E clean VC-debug + $(MAKE) /E clean VCE-debug + $(MAKE) /E clean VSE-debug ++! ENDIF ++!ENDIF + $(MAKE) /E clean + + TEST_ENV = CFLAGS="$(CFLAGS) /DNO_ERROR_DIALOGS" +@@ -218,8 +227,7 @@ install: + if not exist $(LIBDEST) mkdir $(LIBDEST) + if not exist $(HDRDEST) mkdir $(HDRDEST) + if exist pthreadV*.dll copy pthreadV*.dll $(DLLDEST) +- copy pthreadV*.lib $(LIBDEST) +- copy libpthreadV*.lib $(LIBDEST) ++ if exist pthreadV*.lib copy pthreadV*.lib $(LIBDEST) + copy _ptw32.h $(HDRDEST) + copy pthread.h $(HDRDEST) + copy sched.h $(HDRDEST) +@@ -229,8 +237,8 @@ $(DLLS): $(DLL_OBJS) + $(CC) /LDd /Zi $(DLL_OBJS) /link /implib:$*.lib $(XLIBS) /out:$@ + + $(INLINED_STATIC_STAMPS): $(STATIC_OBJS) +- if exist lib$*.lib del lib$*.lib +- lib $(STATIC_OBJS) /out:lib$*.lib ++ if exist $*.lib del $*.lib ++ lib $(STATIC_OBJS) /out:$*.lib + echo. >$@ + + $(SMALL_STATIC_STAMPS): $(STATIC_OBJS_SMALL) diff --git a/ports/pthreads/fix-pthread_getname_np.patch b/ports/pthreads/fix-pthread_getname_np.patch new file mode 100644 index 0000000000..7eaadea54c --- /dev/null +++ b/ports/pthreads/fix-pthread_getname_np.patch @@ -0,0 +1,26 @@ +diff --git a/pthread_getname_np.c b/pthread_getname_np.c +index 8fc32b1..7c18655 100644 +--- a/pthread_getname_np.c ++++ b/pthread_getname_np.c +@@ -59,10 +59,18 @@ pthread_getname_np(pthread_t thr, char *name, int len) + + __ptw32_mcs_lock_acquire (&tp->threadLock, &threadLock); + +- for (s = tp->name, d = name; *s && d < &name[len - 1]; *d++ = *s++) +- {} ++ if(tp->name) ++ { ++ for (s = tp->name, d = name; *s && d < &name[len - 1]; *d++ = *s++) ++ {} ++ ++ *d = '\0'; ++ } ++ else ++ { ++ *name = '\0'; ++ } + +- *d = '\0'; + __ptw32_mcs_lock_release (&threadLock); + + return result; diff --git a/ports/pthreads/fix-uwp-linkage.patch b/ports/pthreads/fix-uwp-linkage.patch index 77d3a5b15a..22a12f846b 100644 --- a/ports/pthreads/fix-uwp-linkage.patch +++ b/ports/pthreads/fix-uwp-linkage.patch @@ -15,3 +15,23 @@ index 1579376..3a7d29b 100644 #if !defined (__PTW32_CONFIG_H) # error "config.h was not #included" #endif + +diff --git a/pthread_cancel.c b/pthread_cancel.c +index fddf216..bf16870 100644 +--- a/pthread_cancel.c ++++ b/pthread_cancel.c +@@ -64,12 +64,12 @@ __ptw32_cancel_callback (ULONG_PTR unused) + DWORD + __ptw32_Registercancellation (PAPCFUNC unused1, HANDLE threadH, DWORD unused2) + { +- CONTEXT context; ++ /*CONTEXT context; + + context.ContextFlags = CONTEXT_CONTROL; + GetThreadContext (threadH, &context); + __PTW32_PROGCTR (context) = (DWORD_PTR) __ptw32_cancel_self; +- SetThreadContext (threadH, &context); ++ SetThreadContext (threadH, &context);*/ + return 0; + } + diff --git a/ports/pthreads/portfile.cmake b/ports/pthreads/portfile.cmake index 722b56e0b2..8f2a804fba 100644 --- a/ports/pthreads/portfile.cmake +++ b/ports/pthreads/portfile.cmake @@ -17,91 +17,44 @@ else() list(APPEND PATCH_FILES use-mt.patch) endif() +list(APPEND PATCH_FILES fix-pthread_getname_np.patch fix-install.patch) + vcpkg_from_sourceforge( - OUT_SOURCE_PATH SOURCE_PATH - REPO pthreads4w - FILENAME "pthreads4w-code-v${VERSION}.zip" - SHA512 49e541b66c26ddaf812edb07b61d0553e2a5816ab002edc53a38a897db8ada6d0a096c98a9af73a8f40c94283df53094f76b429b09ac49862465d8697ed20013 - PATCHES - fix-arm-macro.patch - fix-arm64-version_rc.patch # https://sourceforge.net/p/pthreads4w/code/merge-requests/6/ - ${PATCH_FILES} + OUT_SOURCE_PATH SOURCE_PATH + REPO pthreads4w + FILENAME "pthreads4w-code-v${VERSION}.zip" + SHA512 49e541b66c26ddaf812edb07b61d0553e2a5816ab002edc53a38a897db8ada6d0a096c98a9af73a8f40c94283df53094f76b429b09ac49862465d8697ed20013 + PATCHES + fix-arm-macro.patch + fix-arm64-version_rc.patch # https://sourceforge.net/p/pthreads4w/code/merge-requests/6/ + ${PATCH_FILES} ) -find_program(NMAKE nmake REQUIRED) +file(TO_NATIVE_PATH "${CURRENT_PACKAGES_DIR}/debug" DESTROOT_DEBUG) +file(TO_NATIVE_PATH "${CURRENT_PACKAGES_DIR}" DESTROOT_RELEASE) + +vcpkg_list(SET OPTIONS_DEBUG "DESTROOT=${DESTROOT_DEBUG}") +vcpkg_list(SET OPTIONS_RELEASE "DESTROOT=${DESTROOT_RELEASE}" "BUILD_RELEASE=1") -################ -# Release build -################ -message(STATUS "Building ${TARGET_TRIPLET}-rel") -file(TO_NATIVE_PATH "${CURRENT_PACKAGES_DIR}" INST_DIR_REL) -vcpkg_execute_required_process( - COMMAND "${NMAKE}" -f Makefile all install - "DESTROOT=\"${INST_DIR_REL}\"" - WORKING_DIRECTORY "${SOURCE_PATH}" - LOGNAME nmake-build-${TARGET_TRIPLET}-release -) -file(REMOVE "${CURRENT_PACKAGES_DIR}/bin/pthreadVC3d.dll") -file(REMOVE "${CURRENT_PACKAGES_DIR}/bin/pthreadVCE3d.dll") -file(REMOVE "${CURRENT_PACKAGES_DIR}/bin/pthreadVSE3d.dll") -file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/libpthreadVC3d.lib") -file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/libpthreadVCE3d.lib") -file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/libpthreadVSE3d.lib") -file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/pthreadVC3d.lib") -file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/pthreadVCE3d.lib") -file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/pthreadVSE3d.lib") -if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") - file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/libpthreadVC3.lib") - file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/libpthreadVCE3.lib") - file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/libpthreadVSE3.lib") -endif() if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") - file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin") - file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/bin") - file(RENAME "${CURRENT_PACKAGES_DIR}/lib/libpthreadVC3.lib" "${CURRENT_PACKAGES_DIR}/lib/pthreadVC3.lib") - file(RENAME "${CURRENT_PACKAGES_DIR}/lib/libpthreadVCE3.lib" "${CURRENT_PACKAGES_DIR}/lib/pthreadVCE3.lib") - file(RENAME "${CURRENT_PACKAGES_DIR}/lib/libpthreadVSE3.lib" "${CURRENT_PACKAGES_DIR}/lib/pthreadVSE3.lib") + vcpkg_list(APPEND OPTIONS_DEBUG "BUILD_STATIC=1") + vcpkg_list(APPEND OPTIONS_RELEASE "BUILD_STATIC=1") endif() -message(STATUS "Building ${TARGET_TRIPLET}-rel done") +vcpkg_install_nmake( + CL_LANGUAGE C + SOURCE_PATH "${SOURCE_PATH}" + PROJECT_NAME Makefile + OPTIONS_DEBUG ${OPTIONS_DEBUG} + OPTIONS_RELEASE ${OPTIONS_RELEASE} +) -if(NOT VCPKG_BUILD_TYPE) - ################ - # Debug build - ################ - message(STATUS "Building ${TARGET_TRIPLET}-dbg") - file(TO_NATIVE_PATH "${CURRENT_PACKAGES_DIR}/debug" INST_DIR_DBG) - vcpkg_execute_required_process( - COMMAND "${NMAKE}" /G -f Makefile all install - "DESTROOT=\"${INST_DIR_DBG}\"" - WORKING_DIRECTORY "${SOURCE_PATH}" - LOGNAME nmake-build-${TARGET_TRIPLET}-debug - ) - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/bin/pthreadVC3.dll") - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/bin/pthreadVCE3.dll") - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/bin/pthreadVSE3.dll") - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/libpthreadVC3.lib") - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/libpthreadVCE3.lib") - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/libpthreadVSE3.lib") - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/pthreadVC3.lib") - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/pthreadVCE3.lib") - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/pthreadVSE3.lib") - if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/libpthreadVC3d.lib") - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/libpthreadVCE3d.lib") - file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/libpthreadVSE3d.lib") - endif() - if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") - file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/bin") - file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/libpthreadVC3d.lib" "${CURRENT_PACKAGES_DIR}/debug/lib/pthreadVC3d.lib") - file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/libpthreadVCE3d.lib" "${CURRENT_PACKAGES_DIR}/debug/lib/pthreadVCE3d.lib") - file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/libpthreadVSE3d.lib" "${CURRENT_PACKAGES_DIR}/debug/lib/pthreadVSE3d.lib") - endif() - file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") - message(STATUS "Building ${TARGET_TRIPLET}-dbg done") +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") endif() - file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/PThreads4WConfig.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/PThreads4W") file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper-pthread.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/pthread" RENAME vcpkg-cmake-wrapper.cmake) file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper-pthreads.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/pthreads" RENAME vcpkg-cmake-wrapper.cmake) diff --git a/ports/pthreads/vcpkg.json b/ports/pthreads/vcpkg.json index e7b3fe8a56..127ddf938f 100644 --- a/ports/pthreads/vcpkg.json +++ b/ports/pthreads/vcpkg.json @@ -1,8 +1,14 @@ { "name": "pthreads", "version": "3.0.0", - "port-version": 12, + "port-version": 13, "description": "Meta-package that provides PThreads4W on Windows, or assumes presence of system pthreads on POSIX systems.", "homepage": "https://sourceforge.net/projects/pthreads4w/", - "license": "Apache-2.0" + "license": "Apache-2.0", + "dependencies": [ + { + "name": "vcpkg-cmake-config", + "host": true + } + ] } diff --git a/versions/baseline.json b/versions/baseline.json index 6cb160cbce..3be9961bf6 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -6046,7 +6046,7 @@ }, "pthreads": { "baseline": "3.0.0", - "port-version": 12 + "port-version": 13 }, "ptyqt": { "baseline": "0.6.5", diff --git a/versions/p-/pthreads.json b/versions/p-/pthreads.json index eca688c376..ba81c8c3fb 100644 --- a/versions/p-/pthreads.json +++ b/versions/p-/pthreads.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "f4037e12c8075b814cab20c65509b49bd7f59257", + "version": "3.0.0", + "port-version": 13 + }, { "git-tree": "e000e1dfe6cc2725080cd0e41e04e363cc450bd4", "version": "3.0.0",