From cb30c3fd0014f264709287fee43f24310dfde4aa Mon Sep 17 00:00:00 2001 From: Aybe Date: Fri, 17 Nov 2017 00:54:14 +0100 Subject: [PATCH 1/2] [libflac] patches for UWP builds --- ports/libflac/CONTROL | 2 +- ports/libflac/portfile.cmake | 16 ++++++++---- ports/libflac/uwp-consolewidth.patch | 16 ++++++++++++ ports/libflac/uwp-createfile.patch | 38 +++++++++++++++++++++++++++ ports/libflac/uwp-loadlibrary.patch | 13 ++++++++++ ports/libflac/uwp-writeconsole.patch | 39 ++++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 ports/libflac/uwp-consolewidth.patch create mode 100644 ports/libflac/uwp-createfile.patch create mode 100644 ports/libflac/uwp-loadlibrary.patch create mode 100644 ports/libflac/uwp-writeconsole.patch diff --git a/ports/libflac/CONTROL b/ports/libflac/CONTROL index 2a0572d2a0..ca2995d680 100644 --- a/ports/libflac/CONTROL +++ b/ports/libflac/CONTROL @@ -1,4 +1,4 @@ Source: libflac -Version: 1.3.2-3 +Version: 1.3.2-4 Description: Library for manipulating FLAC files Build-Depends: libogg diff --git a/ports/libflac/portfile.cmake b/ports/libflac/portfile.cmake index cbf7d6fd3f..7657e39276 100644 --- a/ports/libflac/portfile.cmake +++ b/ports/libflac/portfile.cmake @@ -1,8 +1,3 @@ - # libFLAC uses winapi functions not available in WindowsStore -if (VCPKG_CMAKE_SYSTEM_NAME STREQUAL WindowsStore) - message(FATAL_ERROR "Error: UWP builds are currently not supported.") -endif() - include(vcpkg_common_functions) set(SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/flac-1.3.2) vcpkg_download_distfile(ARCHIVE @@ -12,6 +7,17 @@ vcpkg_download_distfile(ARCHIVE vcpkg_extract_source_archive(${ARCHIVE}) +if (VCPKG_CMAKE_SYSTEM_NAME STREQUAL WindowsStore) + vcpkg_apply_patches( + SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/flac-1.3.2 + PATCHES + "${CMAKE_CURRENT_LIST_DIR}/uwp-consolewidth.patch" + "${CMAKE_CURRENT_LIST_DIR}/uwp-loadlibrary.patch" + "${CMAKE_CURRENT_LIST_DIR}/uwp-createfile.patch" + "${CMAKE_CURRENT_LIST_DIR}/uwp-writeconsole.patch" + ) +endif() + if(VCPKG_TARGET_ARCHITECTURE STREQUAL x86) vcpkg_find_acquire_program(NASM) get_filename_component(NASM_EXE_PATH ${NASM} DIRECTORY) diff --git a/ports/libflac/uwp-consolewidth.patch b/ports/libflac/uwp-consolewidth.patch new file mode 100644 index 0000000000..87a15f6630 --- /dev/null +++ b/ports/libflac/uwp-consolewidth.patch @@ -0,0 +1,16 @@ +diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c +index c61d27f..5b0e8f0 100644 +--- a/src/share/win_utf8_io/win_utf8_io.c ++++ b/src/share/win_utf8_io/win_utf8_io.c +@@ -164,11 +164,6 @@ size_t strlen_utf8(const char *str) + int win_get_console_width(void) + { + int width = 80; +- CONSOLE_SCREEN_BUFFER_INFO csbi; +- HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); +- if(hOut != INVALID_HANDLE_VALUE && hOut != NULL) +- if (GetConsoleScreenBufferInfo(hOut, &csbi) != 0) +- width = csbi.dwSize.X; + return width; + } + diff --git a/ports/libflac/uwp-createfile.patch b/ports/libflac/uwp-createfile.patch new file mode 100644 index 0000000000..348e66b0ad --- /dev/null +++ b/ports/libflac/uwp-createfile.patch @@ -0,0 +1,38 @@ +diff --git a/src/libFLAC/windows_unicode_filenames.c b/src/libFLAC/windows_unicode_filenames.c +index 2404e31..6d8bc74 100644 +--- a/src/libFLAC/windows_unicode_filenames.c ++++ b/src/libFLAC/windows_unicode_filenames.c +@@ -185,17 +185,23 @@ int flac_internal_rename_utf8(const char *oldname, const char *newname) + + HANDLE WINAPI flac_internal_CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) + { +- if (!utf8_filenames) { +- return CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); +- } else { +- wchar_t *wname; +- HANDLE handle = INVALID_HANDLE_VALUE; +- +- if ((wname = wchar_from_utf8(lpFileName)) != NULL) { +- handle = CreateFileW(wname, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); +- free(wname); +- } ++ HANDLE handle = INVALID_HANDLE_VALUE; + ++ if (!utf8_filenames) + return handle; ++ ++ wchar_t *wname; ++ ++ if ((wname = wchar_from_utf8(lpFileName)) != NULL) ++ { ++ CREATEFILE2_EXTENDED_PARAMETERS cfParams = {0}; ++ cfParams.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS); ++ cfParams.dwFileAttributes = dwFlagsAndAttributes & FILE_ATTRIBUTE_NORMAL; ++ cfParams.lpSecurityAttributes = lpSecurityAttributes; ++ cfParams.hTemplateFile = hTemplateFile; ++ handle = CreateFile2(wname, dwDesiredAccess, dwShareMode, dwCreationDisposition, &cfParams); ++ free(wname); + } ++ ++ return handle; + } diff --git a/ports/libflac/uwp-loadlibrary.patch b/ports/libflac/uwp-loadlibrary.patch new file mode 100644 index 0000000000..5d0b10df99 --- /dev/null +++ b/ports/libflac/uwp-loadlibrary.patch @@ -0,0 +1,13 @@ +diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c +index 5b0e8f0..15a76d4 100644 +--- a/src/share/win_utf8_io/win_utf8_io.c ++++ b/src/share/win_utf8_io/win_utf8_io.c +@@ -110,7 +110,7 @@ int get_utf8_argv(int *argc, char ***argv) + char **utf8argv; + int ret, i; + +- if ((handle = LoadLibrary("msvcrt.dll")) == NULL) return 1; ++ if ((handle = LoadPackagedLibrary("msvcrt.dll", 0)) == NULL) return 1; + if ((wgetmainargs = (wgetmainargs_t)GetProcAddress(handle, "__wgetmainargs")) == NULL) { + FreeLibrary(handle); + return 1; diff --git a/ports/libflac/uwp-writeconsole.patch b/ports/libflac/uwp-writeconsole.patch new file mode 100644 index 0000000000..feef963057 --- /dev/null +++ b/ports/libflac/uwp-writeconsole.patch @@ -0,0 +1,39 @@ +diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c +index 15a76d4..bfcc9db 100644 +--- a/src/share/win_utf8_io/win_utf8_io.c ++++ b/src/share/win_utf8_io/win_utf8_io.c +@@ -171,31 +171,13 @@ int win_get_console_width(void) + + static int wprint_console(FILE *stream, const wchar_t *text, size_t len) + { +- DWORD out; +- int ret; ++ // disabled for UWP (https://docs.microsoft.com/en-us/uwp/win32-and-com/alternatives-to-windows-apis-uwp) + +- do { +- if (stream == stdout) { +- HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); +- if (hOut == INVALID_HANDLE_VALUE || hOut == NULL || GetFileType(hOut) != FILE_TYPE_CHAR) +- break; +- if (WriteConsoleW(hOut, text, len, &out, NULL) == 0) +- return -1; +- return out; +- } +- if (stream == stderr) { +- HANDLE hErr = GetStdHandle(STD_ERROR_HANDLE); +- if (hErr == INVALID_HANDLE_VALUE || hErr == NULL || GetFileType(hErr) != FILE_TYPE_CHAR) +- break; +- if (WriteConsoleW(hErr, text, len, &out, NULL) == 0) +- return -1; +- return out; +- } +- } while(0); ++ int ret = fputws(text, stream); + +- ret = fputws(text, stream); + if (ret < 0) + return ret; ++ + return len; + } + From 38ae2f69b7f376614f6a4b9201a23fcaa228baf9 Mon Sep 17 00:00:00 2001 From: Aybe Date: Tue, 21 Nov 2017 05:46:58 +0100 Subject: [PATCH 2/2] [libflac] using #ifdef for patches instead --- ports/libflac/portfile.cmake | 16 +++--- ports/libflac/uwp-consolewidth.patch | 16 ------ ...createfile.patch => uwp-createfile2.patch} | 30 +++++------ ports/libflac/uwp-library-console.patch | 53 +++++++++++++++++++ ports/libflac/uwp-loadlibrary.patch | 13 ----- ports/libflac/uwp-writeconsole.patch | 39 -------------- 6 files changed, 74 insertions(+), 93 deletions(-) delete mode 100644 ports/libflac/uwp-consolewidth.patch rename ports/libflac/{uwp-createfile.patch => uwp-createfile2.patch} (68%) create mode 100644 ports/libflac/uwp-library-console.patch delete mode 100644 ports/libflac/uwp-loadlibrary.patch delete mode 100644 ports/libflac/uwp-writeconsole.patch diff --git a/ports/libflac/portfile.cmake b/ports/libflac/portfile.cmake index 7657e39276..236f51c8eb 100644 --- a/ports/libflac/portfile.cmake +++ b/ports/libflac/portfile.cmake @@ -7,16 +7,12 @@ vcpkg_download_distfile(ARCHIVE vcpkg_extract_source_archive(${ARCHIVE}) -if (VCPKG_CMAKE_SYSTEM_NAME STREQUAL WindowsStore) - vcpkg_apply_patches( - SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/flac-1.3.2 - PATCHES - "${CMAKE_CURRENT_LIST_DIR}/uwp-consolewidth.patch" - "${CMAKE_CURRENT_LIST_DIR}/uwp-loadlibrary.patch" - "${CMAKE_CURRENT_LIST_DIR}/uwp-createfile.patch" - "${CMAKE_CURRENT_LIST_DIR}/uwp-writeconsole.patch" - ) -endif() +vcpkg_apply_patches( + SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/flac-1.3.2 + PATCHES + "${CMAKE_CURRENT_LIST_DIR}/uwp-library-console.patch" + "${CMAKE_CURRENT_LIST_DIR}/uwp-createfile2.patch" +) if(VCPKG_TARGET_ARCHITECTURE STREQUAL x86) vcpkg_find_acquire_program(NASM) diff --git a/ports/libflac/uwp-consolewidth.patch b/ports/libflac/uwp-consolewidth.patch deleted file mode 100644 index 87a15f6630..0000000000 --- a/ports/libflac/uwp-consolewidth.patch +++ /dev/null @@ -1,16 +0,0 @@ -diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c -index c61d27f..5b0e8f0 100644 ---- a/src/share/win_utf8_io/win_utf8_io.c -+++ b/src/share/win_utf8_io/win_utf8_io.c -@@ -164,11 +164,6 @@ size_t strlen_utf8(const char *str) - int win_get_console_width(void) - { - int width = 80; -- CONSOLE_SCREEN_BUFFER_INFO csbi; -- HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); -- if(hOut != INVALID_HANDLE_VALUE && hOut != NULL) -- if (GetConsoleScreenBufferInfo(hOut, &csbi) != 0) -- width = csbi.dwSize.X; - return width; - } - diff --git a/ports/libflac/uwp-createfile.patch b/ports/libflac/uwp-createfile2.patch similarity index 68% rename from ports/libflac/uwp-createfile.patch rename to ports/libflac/uwp-createfile2.patch index 348e66b0ad..cfb3439905 100644 --- a/ports/libflac/uwp-createfile.patch +++ b/ports/libflac/uwp-createfile2.patch @@ -1,25 +1,16 @@ diff --git a/src/libFLAC/windows_unicode_filenames.c b/src/libFLAC/windows_unicode_filenames.c -index 2404e31..6d8bc74 100644 +index 2404e31..d320bf5 100644 --- a/src/libFLAC/windows_unicode_filenames.c +++ b/src/libFLAC/windows_unicode_filenames.c -@@ -185,17 +185,23 @@ int flac_internal_rename_utf8(const char *oldname, const char *newname) +@@ -185,6 +185,27 @@ int flac_internal_rename_utf8(const char *oldname, const char *newname) HANDLE WINAPI flac_internal_CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { -- if (!utf8_filenames) { -- return CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); -- } else { -- wchar_t *wname; -- HANDLE handle = INVALID_HANDLE_VALUE; -- -- if ((wname = wchar_from_utf8(lpFileName)) != NULL) { -- handle = CreateFileW(wname, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); -- free(wname); -- } ++#if defined (WINAPI_FAMILY_PARTITION) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) + HANDLE handle = INVALID_HANDLE_VALUE; - ++ + if (!utf8_filenames) - return handle; ++ return handle; + + wchar_t *wname; + @@ -32,7 +23,16 @@ index 2404e31..6d8bc74 100644 + cfParams.hTemplateFile = hTemplateFile; + handle = CreateFile2(wname, dwDesiredAccess, dwShareMode, dwCreationDisposition, &cfParams); + free(wname); - } ++ } + + return handle; ++#else + if (!utf8_filenames) { + return CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); + } else { +@@ -198,4 +219,5 @@ HANDLE WINAPI flac_internal_CreateFile_utf8(const char *lpFileName, DWORD dwDesi + + return handle; + } ++#endif } diff --git a/ports/libflac/uwp-library-console.patch b/ports/libflac/uwp-library-console.patch new file mode 100644 index 0000000000..bba2422c36 --- /dev/null +++ b/ports/libflac/uwp-library-console.patch @@ -0,0 +1,53 @@ +diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c +index c61d27f..0870054 100644 +--- a/src/share/win_utf8_io/win_utf8_io.c ++++ b/src/share/win_utf8_io/win_utf8_io.c +@@ -110,7 +110,11 @@ int get_utf8_argv(int *argc, char ***argv) + char **utf8argv; + int ret, i; + ++#if defined (WINAPI_FAMILY_PARTITION) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) ++ if ((handle = LoadPackagedLibrary("msvcrt.dll", 0)) == NULL) return 1; ++#else + if ((handle = LoadLibrary("msvcrt.dll")) == NULL) return 1; ++#endif + if ((wgetmainargs = (wgetmainargs_t)GetProcAddress(handle, "__wgetmainargs")) == NULL) { + FreeLibrary(handle); + return 1; +@@ -163,6 +167,9 @@ size_t strlen_utf8(const char *str) + /* get the console width in characters */ + int win_get_console_width(void) + { ++#if defined (WINAPI_FAMILY_PARTITION) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) ++ return 80; ++#else + int width = 80; + CONSOLE_SCREEN_BUFFER_INFO csbi; + HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); +@@ -170,6 +177,7 @@ int win_get_console_width(void) + if (GetConsoleScreenBufferInfo(hOut, &csbi) != 0) + width = csbi.dwSize.X; + return width; ++#endif + } + + /* print functions */ +@@ -179,6 +187,10 @@ static int wprint_console(FILE *stream, const wchar_t *text, size_t len) + DWORD out; + int ret; + ++#if defined (WINAPI_FAMILY_PARTITION) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) ++ // disabled for UWP as there's no alternative: ++ // https://docs.microsoft.com/en-us/uwp/win32-and-com/alternatives-to-windows-apis-uwp ++#else + do { + if (stream == stdout) { + HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); +@@ -197,6 +209,7 @@ static int wprint_console(FILE *stream, const wchar_t *text, size_t len) + return out; + } + } while(0); ++#endif + + ret = fputws(text, stream); + if (ret < 0) diff --git a/ports/libflac/uwp-loadlibrary.patch b/ports/libflac/uwp-loadlibrary.patch deleted file mode 100644 index 5d0b10df99..0000000000 --- a/ports/libflac/uwp-loadlibrary.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c -index 5b0e8f0..15a76d4 100644 ---- a/src/share/win_utf8_io/win_utf8_io.c -+++ b/src/share/win_utf8_io/win_utf8_io.c -@@ -110,7 +110,7 @@ int get_utf8_argv(int *argc, char ***argv) - char **utf8argv; - int ret, i; - -- if ((handle = LoadLibrary("msvcrt.dll")) == NULL) return 1; -+ if ((handle = LoadPackagedLibrary("msvcrt.dll", 0)) == NULL) return 1; - if ((wgetmainargs = (wgetmainargs_t)GetProcAddress(handle, "__wgetmainargs")) == NULL) { - FreeLibrary(handle); - return 1; diff --git a/ports/libflac/uwp-writeconsole.patch b/ports/libflac/uwp-writeconsole.patch deleted file mode 100644 index feef963057..0000000000 --- a/ports/libflac/uwp-writeconsole.patch +++ /dev/null @@ -1,39 +0,0 @@ -diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c -index 15a76d4..bfcc9db 100644 ---- a/src/share/win_utf8_io/win_utf8_io.c -+++ b/src/share/win_utf8_io/win_utf8_io.c -@@ -171,31 +171,13 @@ int win_get_console_width(void) - - static int wprint_console(FILE *stream, const wchar_t *text, size_t len) - { -- DWORD out; -- int ret; -+ // disabled for UWP (https://docs.microsoft.com/en-us/uwp/win32-and-com/alternatives-to-windows-apis-uwp) - -- do { -- if (stream == stdout) { -- HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); -- if (hOut == INVALID_HANDLE_VALUE || hOut == NULL || GetFileType(hOut) != FILE_TYPE_CHAR) -- break; -- if (WriteConsoleW(hOut, text, len, &out, NULL) == 0) -- return -1; -- return out; -- } -- if (stream == stderr) { -- HANDLE hErr = GetStdHandle(STD_ERROR_HANDLE); -- if (hErr == INVALID_HANDLE_VALUE || hErr == NULL || GetFileType(hErr) != FILE_TYPE_CHAR) -- break; -- if (WriteConsoleW(hErr, text, len, &out, NULL) == 0) -- return -1; -- return out; -- } -- } while(0); -+ int ret = fputws(text, stream); - -- ret = fputws(text, stream); - if (ret < 0) - return ret; -+ - return len; - } -