From: Viktor Szakats Date: Wed, 27 Nov 2024 15:21:04 +0000 (+0100) Subject: build: fix MSVC UWP builds X-Git-Tag: curl-8_11_1~42 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a72b479decd555c9e9c2c50ded34e317123174f2;p=thirdparty%2Fcurl.git build: fix MSVC UWP builds The MSVC UWP job in CI did not actually enable UWP. Fix this and the fallouts discovered after enabling it. - GHA/windows: make sure to enable UWP in MSVC vcpkg UWP job. Use the CMake options and C flags already used for mingw-w64, but use `WINAPI_FAMILY_PC_APP` instead of the deprecated `WINAPI_FAMILY_APP`. (The former is not supported by mingw-w64, so leave it there as-is.) Follow-up to cb22cfca69bded45bf7f9c72c8e6764990490f11 #14077 - GHA/windows: by default the MSVC UWP job became 2x-3x slower than others after actually enabling UWP. Most of it is caused by CMake/MSBuild automatically building full APPX containers for each `.exe` target. This includes 21 CMake feature detections. Each detection app is built into a 15MB APPX project, with code signing, logos, etc. Example: https://github.com/curl/curl/actions/runs/12056968170/job/33620610958 Disable this overhead for curl build targets via custom `CMAKE_VS_GLOBALS` options. I've found no way to apply them to feature detection targets, so those remain slow. - cmake: automatically enable Unicode for UWP builds. It's required. Also stop enabling it manually in the existing CI job. - tests: fix `getpid()` use for Windows UWP: ``` tests\server\util.c(281,21): warning C4013: 'getpid' undefined; assuming extern returning int ``` Ref: https://github.com/curl/curl/actions/runs/12061215311/job/33632904249#step:11:38 - src/tool_doswin: disable `GetLoadedModulePaths()` for UWP. mingw-w64 UWP was okay with this, but MS SDK headers are not. This makes `--dump-module-paths` return empty for UWP builds. ``` src\tool_doswin.c(620,3): error C2065: 'MODULEENTRY32': undeclared identifier src\tool_doswin.c(626,11): warning C4013: 'CreateToolhelp32Snapshot' undefined; assuming extern returning int src\tool_doswin.c(626,36): error C2065: 'TH32CS_SNAPMODULE': undeclared identifier src\tool_doswin.c(632,7): warning C4013: 'Module32First' undefined; assuming extern returning int ``` Ref: https://github.com/curl/curl/actions/runs/12055081933/job/33614629930#step:9:35 - examples: fix `websocket.c` to include `winsock2.h` before `windows.h` to make it build with MSVC UWP: ``` include\curl\curl.h(143,16): error C2061: syntax error: identifier 'curl_socket_t' include\curl\curl.h(143,16): error C2059: syntax error: ';' include\curl\curl.h(417,52): error C2146: syntax error: missing ')' before identifier 'curlfd' include\curl\curl.h(417,38): error C2081: 'curl_socket_t': name in formal parameter list illegal ``` Ref: https://github.com/curl/curl/actions/runs/12055317910/job/33615644427#step:14:126 - GHA/windows: silence linker warning with MSVC UWP builds: ``` LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification ``` Ref: https://github.com/curl/curl/actions/runs/12055696808/job/33616629610#step:11:38 - GHA/windows: set `/INCREMENTAL:NO` for all MSVC jobs to improve performance a little. - cmake: show `UWP` platform flag. Ref: #15652 Closes #15657 --- diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 3c0b784623..413cd60371 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -178,7 +178,7 @@ jobs: - { build: 'cmake' , sys: 'mingw64', env: 'x86_64' , tflags: '' , config: '-DENABLE_DEBUG=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON -DENABLE_ARES=ON', type: 'Debug', name: 'schannel c-ares U' } - { build: 'cmake' , sys: 'ucrt64' , env: 'ucrt-x86_64' , tflags: 'skiprun' , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON -DENABLE_CURLDEBUG=ON', type: 'Release', name: 'schannel R TrackMemory' } - { build: 'cmake' , sys: 'clang64', env: 'clang-x86_64', tflags: 'skiprun' , config: '-DENABLE_DEBUG=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_OPENSSL=ON -DENABLE_UNICODE=OFF', type: 'Release', name: 'openssl' } - - { build: 'cmake' , sys: 'ucrt64' , env: 'ucrt-x86_64' , tflags: 'skiprun' , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON', type: 'Release', test: 'uwp', name: 'schannel' } + - { build: 'cmake' , sys: 'ucrt64' , env: 'ucrt-x86_64' , tflags: 'skiprun' , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON', type: 'Release', test: 'uwp', name: 'schannel' } - { build: 'cmake' , sys: 'mingw64', env: 'x86_64' , tflags: 'skiprun' , config: '-DENABLE_DEBUG=ON -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON -DCMAKE_VERBOSE_MAKEFILE=ON', type: 'Debug', cflags: '-DCURL_SCHANNEL_DEV_DEBUG', name: 'schannel dev debug' } - { build: 'cmake' , sys: 'mingw32', env: 'i686' , tflags: 'skiprun' , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON', type: 'Release', name: 'schannel R' } fail-fast: false @@ -676,11 +676,20 @@ jobs: timeout-minutes: 5 run: | PATH="/c/msys64/usr/bin:$PATH" + if [ '${{ matrix.plat }}' = 'uwp' ]; then + options+=' -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0' + cflags='-DWINAPI_FAMILY=WINAPI_FAMILY_PC_APP' + ldflags='/OPT:NOREF /OPT:NOICF /APPCONTAINER:NO' + vsglobals=';AppxPackage=false;WindowsAppContainer=false' + fi cmake -B bld ${options} \ "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" \ "-DVCPKG_INSTALLED_DIR=$VCPKG_INSTALLATION_ROOT/installed" \ '-DVCPKG_TARGET_TRIPLET=${{ matrix.arch }}-${{ matrix.plat }}' \ - -DCMAKE_VS_GLOBALS=TrackFileAccess=false \ + "-DCMAKE_C_FLAGS=${cflags}" \ + "-DCMAKE_EXE_LINKER_FLAGS=/INCREMENTAL:NO ${ldflags}" \ + "-DCMAKE_SHARED_LINKER_FLAGS=/INCREMENTAL:NO ${ldflags}" \ + "-DCMAKE_VS_GLOBALS=TrackFileAccess=false${vsglobals}" \ '-DCMAKE_BUILD_TYPE=${{ matrix.type }}' \ -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON \ -DCURL_WERROR=ON \ diff --git a/CMakeLists.txt b/CMakeLists.txt index f6582a0948..3c3326e8df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,9 @@ endif() if(WIN32) set(_target_flags "${_target_flags} WIN32") endif() +if(WINDOWS_STORE) + set(_target_flags "${_target_flags} UWP") +endif() if(CYGWIN) set(_target_flags "${_target_flags} CYGWIN") endif() @@ -178,6 +181,9 @@ if(WIN32) endif() option(ENABLE_UNICODE "Use the Unicode version of the Windows API functions" OFF) + if(WINDOWS_STORE) + set(ENABLE_UNICODE ON) + endif() if(ENABLE_UNICODE) add_definitions("-DUNICODE" "-D_UNICODE") if(MINGW) diff --git a/docs/examples/websocket.c b/docs/examples/websocket.c index 996f2a0245..758ee48e0e 100644 --- a/docs/examples/websocket.c +++ b/docs/examples/websocket.c @@ -28,6 +28,7 @@ #include #include #ifdef _WIN32 +#include #include #define sleep(s) Sleep((DWORD)(s)) #else diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 420a4384ce..50b4479f23 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -465,6 +465,12 @@ #include #endif +#ifdef _WIN32 +#define Curl_getpid() GetCurrentProcessId() +#else +#define Curl_getpid() getpid() +#endif + /* * Large file (>2Gb) support using Win32 functions. */ diff --git a/lib/smb.c b/lib/smb.c index a242fc5c2a..a72ece62ad 100644 --- a/lib/smb.c +++ b/lib/smb.c @@ -27,12 +27,6 @@ #if !defined(CURL_DISABLE_SMB) && defined(USE_CURL_NTLM_CORE) -#ifdef _WIN32 -#define Curl_getpid() ((unsigned int)GetCurrentProcessId()) -#else -#define Curl_getpid() ((unsigned int)getpid()) -#endif - #include "smb.h" #include "urldata.h" #include "sendf.h" @@ -548,7 +542,7 @@ static void smb_format_message(struct Curl_easy *data, struct smb_header *h, h->flags2 = smb_swap16(SMB_FLAGS2_IS_LONG_NAME | SMB_FLAGS2_KNOWS_LONG_NAME); h->uid = smb_swap16(smbc->uid); h->tid = smb_swap16(req->tid); - pid = Curl_getpid(); + pid = (unsigned int)Curl_getpid(); h->pid_high = smb_swap16((unsigned short)(pid >> 16)); h->pid = smb_swap16((unsigned short) pid); } diff --git a/src/tool_doswin.c b/src/tool_doswin.c index 70b263113e..301b2974e5 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -616,9 +616,10 @@ CURLcode FindWin32CACert(struct OperationConfig *config, */ struct curl_slist *GetLoadedModulePaths(void) { + struct curl_slist *slist = NULL; +#if !defined(CURL_WINDOWS_UWP) HANDLE hnd = INVALID_HANDLE_VALUE; MODULEENTRY32 mod = {0}; - struct curl_slist *slist = NULL; mod.dwSize = sizeof(MODULEENTRY32); @@ -661,6 +662,7 @@ error: cleanup: if(hnd != INVALID_HANDLE_VALUE) CloseHandle(hnd); +#endif return slist; } diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index b016803877..9cab12c5ac 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -1394,7 +1394,7 @@ server_cleanup: if(got_exit_signal) { logmsg("========> %s rtspd (port: %d pid: %ld) exits with signal (%d)", - ipv_inuse, (int)port, (long)getpid(), exit_signal); + ipv_inuse, (int)port, (long)Curl_getpid(), exit_signal); /* * To properly set the return status of the process we * must raise the same signal SIGINT or SIGTERM that we diff --git a/tests/server/sws.c b/tests/server/sws.c index cdc94fe19e..ef139bfc3c 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -2492,7 +2492,7 @@ sws_cleanup: if(got_exit_signal) { logmsg("========> %s sws (%s pid: %ld) exits with signal (%d)", - socket_type, location_str, (long)getpid(), exit_signal); + socket_type, location_str, (long)Curl_getpid(), exit_signal); /* * To properly set the return status of the process we * must raise the same signal SIGINT or SIGTERM that we diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index c6ac1505da..4edc2fd6dd 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -871,7 +871,7 @@ tftpd_cleanup: if(got_exit_signal) { logmsg("========> %s tftpd (port: %d pid: %ld) exits with signal (%d)", - ipv_inuse, (int)port, (long)getpid(), exit_signal); + ipv_inuse, (int)port, (long)Curl_getpid(), exit_signal); /* * To properly set the return status of the process we * must raise the same signal SIGINT or SIGTERM that we diff --git a/tests/server/util.c b/tests/server/util.c index a36dc0055d..287ca3000a 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -278,7 +278,7 @@ curl_off_t our_getpid(void) { curl_off_t pid; - pid = (curl_off_t)getpid(); + pid = (curl_off_t)Curl_getpid(); #if defined(_WIN32) /* store pid + 65536 to avoid conflict with Cygwin/msys PIDs, see also: * - https://cygwin.com/git/?p=newlib-cygwin.git;a=commit; ↵